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.go 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. type StateType string
  12. const (
  13. STATE_OPEN StateType = "open"
  14. STATE_CLOSED StateType = "closed"
  15. )
  16. type PullRequestMeta struct {
  17. HasMerged bool `json:"merged"`
  18. Merged *time.Time `json:"merged_at"`
  19. }
  20. type Issue struct {
  21. ID int64 `json:"id"`
  22. Index int64 `json:"number"`
  23. Poster *User `json:"user"`
  24. Title string `json:"title"`
  25. Body string `json:"body"`
  26. Labels []*Label `json:"labels"`
  27. Milestone *Milestone `json:"milestone"`
  28. Assignee *User `json:"assignee"`
  29. State StateType `json:"state"`
  30. Comments int `json:"comments"`
  31. Created time.Time `json:"created_at"`
  32. Updated time.Time `json:"updated_at"`
  33. PullRequest *PullRequestMeta `json:"pull_request"`
  34. }
  35. type ListIssueOption struct {
  36. Page int
  37. }
  38. func (c *Client) ListRepoIssues(owner, repo string, opt ListIssueOption) ([]*Issue, error) {
  39. issues := make([]*Issue, 0, 10)
  40. return issues, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues?page=%d", owner, repo, opt.Page), nil, nil, &issues)
  41. }
  42. func (c *Client) GetIssue(owner, repo string, index int64) (*Issue, error) {
  43. issue := new(Issue)
  44. return issue, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index), nil, nil, issue)
  45. }
  46. type CreateIssueOption struct {
  47. Title string `json:"title" binding:"Required"`
  48. Body string `json:"body"`
  49. Assignee string `json:"assignee"`
  50. Milestone int64 `json:"milestone"`
  51. Labels []int64 `json:"labels"`
  52. Closed bool `json:"closed"`
  53. }
  54. func (c *Client) CreateIssue(owner, repo string, opt CreateIssueOption) (*Issue, error) {
  55. body, err := json.Marshal(&opt)
  56. if err != nil {
  57. return nil, err
  58. }
  59. issue := new(Issue)
  60. return issue, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues", owner, repo),
  61. jsonHeader, bytes.NewReader(body), issue)
  62. }
  63. type EditIssueOption struct {
  64. Title string `json:"title"`
  65. Body *string `json:"body"`
  66. Assignee *string `json:"assignee"`
  67. Milestone *int64 `json:"milestone"`
  68. State *string `json:"state"`
  69. }
  70. func (c *Client) EditIssue(owner, repo string, index int64, opt EditIssueOption) (*Issue, error) {
  71. body, err := json.Marshal(&opt)
  72. if err != nil {
  73. return nil, err
  74. }
  75. issue := new(Issue)
  76. return issue, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index),
  77. jsonHeader, bytes.NewReader(body), issue)
  78. }