Skip to content

Commit c52f7ee

Browse files
committed
#26 code cleanup
1 parent 3d69f7c commit c52f7ee

File tree

2 files changed

+23
-35
lines changed

2 files changed

+23
-35
lines changed

gogs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func Version() string {
17-
return "0.12.2"
17+
return "0.12.3"
1818
}
1919

2020
// Client represents a Gogs API client.

issue_comment.go

+22-34
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,57 @@
1+
// Copyright 2016 The Gogs Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
15
package gogs
26

37
import (
48
"bytes"
59
"encoding/json"
610
"fmt"
7-
"net/http"
811
"time"
912
)
1013

11-
// CommentType is type of a comment
12-
type CommentType int
13-
1414
// Comment represents a comment in commit and issue page.
1515
type Comment struct {
16-
ID int64 `json:"id"`
17-
Type CommentType `json:"type"`
18-
Poster *User `json:"poster"`
19-
IssueID int64 `json:"issue_id"`
20-
CommitID int64 `json:"commit_id"`
21-
Line int64 `json:"line"`
22-
Content string `json:"content"`
23-
24-
Created time.Time `json:"created"`
25-
CreatedUnix int64 `json:"created_unix"`
26-
27-
// Reference issue in commit message
28-
CommitSHA string `json:"commit_sha"`
29-
30-
//Attachments []*Attachment `json:"attachments"`
16+
ID int64 `json:"id"`
17+
Poster *User `json:"user"`
18+
Body string `json:"body"`
19+
Created time.Time `json:"created_at"`
20+
Updated time.Time `json:"updated_at"`
3121
}
3222

33-
// ListRepoIssueComments list comments on an issue
34-
func (c *Client) ListRepoIssueComments(owner, repo string, issueID int64) ([]*Comment, error) {
23+
// ListIssueComments list comments on an issue.
24+
func (c *Client) ListIssueComments(owner, repo string, index int64) ([]*Comment, error) {
3525
comments := make([]*Comment, 0, 10)
36-
return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, issueID), nil, nil, &comments)
26+
return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), nil, nil, &comments)
3727
}
3828

39-
// CreateIssueCommentOption is option when creating an issue comment
29+
// CreateIssueCommentOption is option when creating an issue comment.
4030
type CreateIssueCommentOption struct {
41-
Content string `json:"content" binding:"required"`
31+
Body string `json:"body" binding:"Required"`
4232
}
4333

44-
// CreateIssueComment create comment on an issue
45-
func (c *Client) CreateIssueComment(owner, repo string, issueID int64, opt CreateIssueCommentOption) (*Comment, error) {
34+
// CreateIssueComment create comment on an issue.
35+
func (c *Client) CreateIssueComment(owner, repo string, index int64, opt CreateIssueCommentOption) (*Comment, error) {
4636
body, err := json.Marshal(&opt)
4737
if err != nil {
4838
return nil, err
4939
}
5040
comment := new(Comment)
51-
return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/:%s/:%s/issues/%d/comments", owner, repo, issueID),
52-
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), comment)
41+
return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/:%s/:%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment)
5342
}
5443

55-
// EditIssueCommentOption is option when editing an issue comment
44+
// EditIssueCommentOption is option when editing an issue comment.
5645
type EditIssueCommentOption struct {
57-
Content string `json:"content" binding:"required"`
46+
Body string `json:"body" binding:"Required"`
5847
}
5948

60-
// EditIssueComment edits an issue comment
61-
func (c *Client) EditIssueComment(owner, repo string, issueID, commentID int64, opt EditIssueCommentOption) (*Comment, error) {
49+
// EditIssueComment edits an issue comment.
50+
func (c *Client) EditIssueComment(owner, repo string, index, commentID int64, opt EditIssueCommentOption) (*Comment, error) {
6251
body, err := json.Marshal(&opt)
6352
if err != nil {
6453
return nil, err
6554
}
6655
comment := new(Comment)
67-
return comment, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/:%s/:%s/issues/%d/comments/%d", owner, repo, issueID, commentID),
68-
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), comment)
56+
return comment, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/:%s/:%s/issues/%d/comments/%d", owner, repo, index, commentID), jsonHeader, bytes.NewReader(body), comment)
6957
}

0 commit comments

Comments
 (0)