issue_milestone.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 gogs
  5. import (
  6. "bytes"
  7. "encoding/json"
  8. "fmt"
  9. "time"
  10. )
  11. type Milestone struct {
  12. ID int64 `json:"id"`
  13. Title string `json:"title"`
  14. Description string `json:"description"`
  15. State StateType `json:"state"`
  16. OpenIssues int `json:"open_issues"`
  17. ClosedIssues int `json:"closed_issues"`
  18. Closed *time.Time `json:"closed_at"`
  19. Deadline *time.Time `json:"due_on"`
  20. }
  21. func (c *Client) ListRepoMilestones(owner, repo string) ([]*Milestone, error) {
  22. milestones := make([]*Milestone, 0, 10)
  23. return milestones, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), nil, nil, &milestones)
  24. }
  25. func (c *Client) GetMilestone(owner, repo string, id int64) (*Milestone, error) {
  26. milestone := new(Milestone)
  27. return milestone, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil, milestone)
  28. }
  29. type CreateMilestoneOption struct {
  30. Title string `json:"title"`
  31. Description string `json:"description"`
  32. Deadline *time.Time `json:"due_on"`
  33. }
  34. func (c *Client) CreateMilestone(owner, repo string, opt CreateMilestoneOption) (*Milestone, error) {
  35. body, err := json.Marshal(&opt)
  36. if err != nil {
  37. return nil, err
  38. }
  39. milestone := new(Milestone)
  40. return milestone, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), jsonHeader, bytes.NewReader(body), milestone)
  41. }
  42. type EditMilestoneOption struct {
  43. Title string `json:"title"`
  44. Description *string `json:"description"`
  45. State *string `json:"state"`
  46. Deadline *time.Time `json:"due_on"`
  47. }
  48. func (c *Client) EditMilestone(owner, repo string, id int64, opt EditMilestoneOption) (*Milestone, error) {
  49. body, err := json.Marshal(&opt)
  50. if err != nil {
  51. return nil, err
  52. }
  53. milestone := new(Milestone)
  54. return milestone, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), milestone)
  55. }
  56. func (c *Client) DeleteMilestone(owner, repo string, id int64) error {
  57. _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil)
  58. return err
  59. }