1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 "time"
12 )
13
14
15 type Milestone struct {
16 URL *string `json:"url,omitempty"`
17 HTMLURL *string `json:"html_url,omitempty"`
18 LabelsURL *string `json:"labels_url,omitempty"`
19 ID *int64 `json:"id,omitempty"`
20 Number *int `json:"number,omitempty"`
21 State *string `json:"state,omitempty"`
22 Title *string `json:"title,omitempty"`
23 Description *string `json:"description,omitempty"`
24 Creator *User `json:"creator,omitempty"`
25 OpenIssues *int `json:"open_issues,omitempty"`
26 ClosedIssues *int `json:"closed_issues,omitempty"`
27 CreatedAt *time.Time `json:"created_at,omitempty"`
28 UpdatedAt *time.Time `json:"updated_at,omitempty"`
29 ClosedAt *time.Time `json:"closed_at,omitempty"`
30 DueOn *time.Time `json:"due_on,omitempty"`
31 NodeID *string `json:"node_id,omitempty"`
32 }
33
34 func (m Milestone) String() string {
35 return Stringify(m)
36 }
37
38
39
40 type MilestoneListOptions struct {
41
42
43 State string `url:"state,omitempty"`
44
45
46
47 Sort string `url:"sort,omitempty"`
48
49
50
51 Direction string `url:"direction,omitempty"`
52
53 ListOptions
54 }
55
56
57
58
59 func (s *IssuesService) ListMilestones(ctx context.Context, owner string, repo string, opts *MilestoneListOptions) ([]*Milestone, *Response, error) {
60 u := fmt.Sprintf("repos/%v/%v/milestones", owner, repo)
61 u, err := addOptions(u, opts)
62 if err != nil {
63 return nil, nil, err
64 }
65
66 req, err := s.client.NewRequest("GET", u, nil)
67 if err != nil {
68 return nil, nil, err
69 }
70
71 var milestones []*Milestone
72 resp, err := s.client.Do(ctx, req, &milestones)
73 if err != nil {
74 return nil, resp, err
75 }
76
77 return milestones, resp, nil
78 }
79
80
81
82
83 func (s *IssuesService) GetMilestone(ctx context.Context, owner string, repo string, number int) (*Milestone, *Response, error) {
84 u := fmt.Sprintf("repos/%v/%v/milestones/%d", owner, repo, number)
85 req, err := s.client.NewRequest("GET", u, nil)
86 if err != nil {
87 return nil, nil, err
88 }
89
90 milestone := new(Milestone)
91 resp, err := s.client.Do(ctx, req, milestone)
92 if err != nil {
93 return nil, resp, err
94 }
95
96 return milestone, resp, nil
97 }
98
99
100
101
102 func (s *IssuesService) CreateMilestone(ctx context.Context, owner string, repo string, milestone *Milestone) (*Milestone, *Response, error) {
103 u := fmt.Sprintf("repos/%v/%v/milestones", owner, repo)
104 req, err := s.client.NewRequest("POST", u, milestone)
105 if err != nil {
106 return nil, nil, err
107 }
108
109 m := new(Milestone)
110 resp, err := s.client.Do(ctx, req, m)
111 if err != nil {
112 return nil, resp, err
113 }
114
115 return m, resp, nil
116 }
117
118
119
120
121 func (s *IssuesService) EditMilestone(ctx context.Context, owner string, repo string, number int, milestone *Milestone) (*Milestone, *Response, error) {
122 u := fmt.Sprintf("repos/%v/%v/milestones/%d", owner, repo, number)
123 req, err := s.client.NewRequest("PATCH", u, milestone)
124 if err != nil {
125 return nil, nil, err
126 }
127
128 m := new(Milestone)
129 resp, err := s.client.Do(ctx, req, m)
130 if err != nil {
131 return nil, resp, err
132 }
133
134 return m, resp, nil
135 }
136
137
138
139
140 func (s *IssuesService) DeleteMilestone(ctx context.Context, owner string, repo string, number int) (*Response, error) {
141 u := fmt.Sprintf("repos/%v/%v/milestones/%d", owner, repo, number)
142 req, err := s.client.NewRequest("DELETE", u, nil)
143 if err != nil {
144 return nil, err
145 }
146
147 return s.client.Do(ctx, req, nil)
148 }
149
View as plain text