Skip to content

Commit 3d69f7c

Browse files
iwanbkunknwon
authored andcommitted
issues comment API client (#26)
1 parent 2ffd470 commit 3d69f7c

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

issue_comment.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package gogs
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"fmt"
7+
"net/http"
8+
"time"
9+
)
10+
11+
// CommentType is type of a comment
12+
type CommentType int
13+
14+
// Comment represents a comment in commit and issue page.
15+
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"`
31+
}
32+
33+
// ListRepoIssueComments list comments on an issue
34+
func (c *Client) ListRepoIssueComments(owner, repo string, issueID int64) ([]*Comment, error) {
35+
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)
37+
}
38+
39+
// CreateIssueCommentOption is option when creating an issue comment
40+
type CreateIssueCommentOption struct {
41+
Content string `json:"content" binding:"required"`
42+
}
43+
44+
// CreateIssueComment create comment on an issue
45+
func (c *Client) CreateIssueComment(owner, repo string, issueID int64, opt CreateIssueCommentOption) (*Comment, error) {
46+
body, err := json.Marshal(&opt)
47+
if err != nil {
48+
return nil, err
49+
}
50+
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)
53+
}
54+
55+
// EditIssueCommentOption is option when editing an issue comment
56+
type EditIssueCommentOption struct {
57+
Content string `json:"content" binding:"required"`
58+
}
59+
60+
// EditIssueComment edits an issue comment
61+
func (c *Client) EditIssueComment(owner, repo string, issueID, commentID int64, opt EditIssueCommentOption) (*Comment, error) {
62+
body, err := json.Marshal(&opt)
63+
if err != nil {
64+
return nil, err
65+
}
66+
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)
69+
}

0 commit comments

Comments
 (0)