|
| 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 | + |
1 | 5 | package gogs
|
2 | 6 |
|
3 | 7 | import (
|
4 | 8 | "bytes"
|
5 | 9 | "encoding/json"
|
6 | 10 | "fmt"
|
7 | | - "net/http" |
8 | 11 | "time"
|
9 | 12 | )
|
10 | 13 |
|
11 | | -// CommentType is type of a comment |
12 | | -type CommentType int |
13 | | - |
14 | 14 | // Comment represents a comment in commit and issue page.
|
15 | 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"` |
| 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"` |
31 | 21 | }
|
32 | 22 |
|
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) { |
35 | 25 | 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) |
37 | 27 | }
|
38 | 28 |
|
39 | | -// CreateIssueCommentOption is option when creating an issue comment |
| 29 | +// CreateIssueCommentOption is option when creating an issue comment. |
40 | 30 | type CreateIssueCommentOption struct {
|
41 | | - Content string `json:"content" binding:"required"` |
| 31 | + Body string `json:"body" binding:"Required"` |
42 | 32 | }
|
43 | 33 |
|
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) { |
46 | 36 | body, err := json.Marshal(&opt)
|
47 | 37 | if err != nil {
|
48 | 38 | return nil, err
|
49 | 39 | }
|
50 | 40 | 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) |
53 | 42 | }
|
54 | 43 |
|
55 | | -// EditIssueCommentOption is option when editing an issue comment |
| 44 | +// EditIssueCommentOption is option when editing an issue comment. |
56 | 45 | type EditIssueCommentOption struct {
|
57 | | - Content string `json:"content" binding:"required"` |
| 46 | + Body string `json:"body" binding:"Required"` |
58 | 47 | }
|
59 | 48 |
|
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) { |
62 | 51 | body, err := json.Marshal(&opt)
|
63 | 52 | if err != nil {
|
64 | 53 | return nil, err
|
65 | 54 | }
|
66 | 55 | 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) |
69 | 57 | }
|
0 commit comments