You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

issue_comment.go 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. package gitea
  5. import (
  6. "bytes"
  7. "encoding/json"
  8. "fmt"
  9. "time"
  10. )
  11. // Comment represents a comment in commit and issue page.
  12. type Comment struct {
  13. ID int64 `json:"id"`
  14. Poster *User `json:"user"`
  15. Body string `json:"body"`
  16. Created time.Time `json:"created_at"`
  17. Updated time.Time `json:"updated_at"`
  18. }
  19. // ListIssueComments list comments on an issue.
  20. func (c *Client) ListIssueComments(owner, repo string, index int64) ([]*Comment, error) {
  21. comments := make([]*Comment, 0, 10)
  22. return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), nil, nil, &comments)
  23. }
  24. // CreateIssueCommentOption is option when creating an issue comment.
  25. type CreateIssueCommentOption struct {
  26. Body string `json:"body" binding:"Required"`
  27. }
  28. // CreateIssueComment create comment on an issue.
  29. func (c *Client) CreateIssueComment(owner, repo string, index int64, opt CreateIssueCommentOption) (*Comment, error) {
  30. body, err := json.Marshal(&opt)
  31. if err != nil {
  32. return nil, err
  33. }
  34. comment := new(Comment)
  35. return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/:%s/:%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment)
  36. }
  37. // EditIssueCommentOption is option when editing an issue comment.
  38. type EditIssueCommentOption struct {
  39. Body string `json:"body" binding:"Required"`
  40. }
  41. // EditIssueComment edits an issue comment.
  42. func (c *Client) EditIssueComment(owner, repo string, index, commentID int64, opt EditIssueCommentOption) (*Comment, error) {
  43. body, err := json.Marshal(&opt)
  44. if err != nil {
  45. return nil, err
  46. }
  47. comment := new(Comment)
  48. return comment, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/:%s/:%s/issues/%d/comments/%d", owner, repo, index, commentID), jsonHeader, bytes.NewReader(body), comment)
  49. }