#26 code cleanup

This commit is contained in:
Unknwon 2016-08-24 20:58:09 -07:00
parent 3d69f7ccdc
commit c52f7ee0cc
2 changed files with 23 additions and 35 deletions

View file

@ -14,7 +14,7 @@ import (
) )
func Version() string { func Version() string {
return "0.12.2" return "0.12.3"
} }
// Client represents a Gogs API client. // Client represents a Gogs API client.

View file

@ -1,69 +1,57 @@
// Copyright 2016 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package gogs package gogs
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http"
"time" "time"
) )
// CommentType is type of a comment
type CommentType int
// Comment represents a comment in commit and issue page. // Comment represents a comment in commit and issue page.
type Comment struct { type Comment struct {
ID int64 `json:"id"` ID int64 `json:"id"`
Type CommentType `json:"type"` Poster *User `json:"user"`
Poster *User `json:"poster"` Body string `json:"body"`
IssueID int64 `json:"issue_id"` Created time.Time `json:"created_at"`
CommitID int64 `json:"commit_id"` Updated time.Time `json:"updated_at"`
Line int64 `json:"line"`
Content string `json:"content"`
Created time.Time `json:"created"`
CreatedUnix int64 `json:"created_unix"`
// Reference issue in commit message
CommitSHA string `json:"commit_sha"`
//Attachments []*Attachment `json:"attachments"`
} }
// ListRepoIssueComments list comments on an issue // ListIssueComments list comments on an issue.
func (c *Client) ListRepoIssueComments(owner, repo string, issueID int64) ([]*Comment, error) { func (c *Client) ListIssueComments(owner, repo string, index int64) ([]*Comment, error) {
comments := make([]*Comment, 0, 10) comments := make([]*Comment, 0, 10)
return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, issueID), nil, nil, &comments) return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), nil, nil, &comments)
} }
// CreateIssueCommentOption is option when creating an issue comment // CreateIssueCommentOption is option when creating an issue comment.
type CreateIssueCommentOption struct { type CreateIssueCommentOption struct {
Content string `json:"content" binding:"required"` Body string `json:"body" binding:"Required"`
} }
// CreateIssueComment create comment on an issue // CreateIssueComment create comment on an issue.
func (c *Client) CreateIssueComment(owner, repo string, issueID int64, opt CreateIssueCommentOption) (*Comment, error) { func (c *Client) CreateIssueComment(owner, repo string, index int64, opt CreateIssueCommentOption) (*Comment, error) {
body, err := json.Marshal(&opt) body, err := json.Marshal(&opt)
if err != nil { if err != nil {
return nil, err return nil, err
} }
comment := new(Comment) comment := new(Comment)
return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/:%s/:%s/issues/%d/comments", owner, repo, issueID), return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/:%s/:%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment)
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), comment)
} }
// EditIssueCommentOption is option when editing an issue comment // EditIssueCommentOption is option when editing an issue comment.
type EditIssueCommentOption struct { type EditIssueCommentOption struct {
Content string `json:"content" binding:"required"` Body string `json:"body" binding:"Required"`
} }
// EditIssueComment edits an issue comment // EditIssueComment edits an issue comment.
func (c *Client) EditIssueComment(owner, repo string, issueID, commentID int64, opt EditIssueCommentOption) (*Comment, error) { func (c *Client) EditIssueComment(owner, repo string, index, commentID int64, opt EditIssueCommentOption) (*Comment, error) {
body, err := json.Marshal(&opt) body, err := json.Marshal(&opt)
if err != nil { if err != nil {
return nil, err return nil, err
} }
comment := new(Comment) comment := new(Comment)
return comment, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/:%s/:%s/issues/%d/comments/%d", owner, repo, issueID, commentID), return comment, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/:%s/:%s/issues/%d/comments/%d", owner, repo, index, commentID), jsonHeader, bytes.NewReader(body), comment)
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), comment)
} }