4
4
5
5
package gogs
6
6
7
- import "time"
7
+ import (
8
+ "bytes"
9
+ "encoding/json"
10
+ "fmt"
11
+ "time"
12
+ )
8
13
9
14
type Milestone struct {
10
15
ID int64 `json:"id"`
@@ -16,3 +21,84 @@ type Milestone struct {
16
21
Closed * time.Time `json:"closed_at"`
17
22
Deadline * time.Time `json:"due_on"`
18
23
}
24
+
25
+ type CreateMilestoneOption struct {
26
+ Title string `json:"title"`
27
+ Description string `json:"description"`
28
+ Deadline * time.Time `json:"due_on"`
29
+ }
30
+
31
+ type EditMilestoneOption struct {
32
+ Title string `json:"title"`
33
+ Description string `json:"description"`
34
+ Deadline * time.Time `json:"due_on"`
35
+ }
36
+
37
+ type SetIssueMilestoneOption struct {
38
+ ID int64 `json:"id"`
39
+ }
40
+
41
+ func (c * Client ) ListRepoMilestones (owner , repo string ) ([]* Milestone , error ) {
42
+ milestones := make ([]* Milestone , 0 , 10 )
43
+ return milestones , c .getParsedResponse ("GET" , fmt .Sprintf ("/repos/%s/%s/milestones" , owner , repo ), nil , nil , & milestones )
44
+ }
45
+
46
+ func (c * Client ) GetRepoMilestone (owner , repo string , id int64 ) (* Milestone , error ) {
47
+ milestone := new (Milestone )
48
+ return milestone , c .getParsedResponse ("GET" , fmt .Sprintf ("/repos/%s/%s/milestones/%d" , owner , repo , id ), nil , nil , milestone )
49
+ }
50
+
51
+ func (c * Client ) CreateMilestone (owner , repo string , opt CreateMilestoneOption ) (* Milestone , error ) {
52
+ body , err := json .Marshal (& opt )
53
+ if err != nil {
54
+ return nil , err
55
+ }
56
+ milestone := new (Milestone )
57
+ return milestone , c .getParsedResponse ("POST" , fmt .Sprintf ("/repos/%s/%s/milestones" , owner , repo ),
58
+ jsonHeader , bytes .NewReader (body ), milestone )
59
+ }
60
+
61
+ func (c * Client ) EditMilestone (owner , repo string , id int64 , opt EditMilestoneOption ) (* Milestone , error ) {
62
+ body , err := json .Marshal (& opt )
63
+ if err != nil {
64
+ return nil , err
65
+ }
66
+ milestone := new (Milestone )
67
+ return milestone , c .getParsedResponse ("PATCH" , fmt .Sprintf ("/repos/%s/%s/milestones/%d" , owner , repo , id ), jsonHeader , bytes .NewReader (body ), milestone )
68
+ }
69
+
70
+ func (c * Client ) DeleteMilestone (owner , repo string , id int64 ) error {
71
+ _ , err := c .getResponse ("DELETE" , fmt .Sprintf ("/repos/%s/%s/milestones/%d" , owner , repo , id ), nil , nil )
72
+ return err
73
+ }
74
+
75
+ func (c * Client ) ChangeMilestoneStatus (owner , repo string , id int64 , open bool ) (* Milestone , error ) {
76
+ var action string
77
+ if open {
78
+ action = "open"
79
+ } else {
80
+ action = "close"
81
+ }
82
+
83
+ milestone := new (Milestone )
84
+ return milestone , c .getParsedResponse ("POST" , fmt .Sprintf ("/repos/%s/%s/milestones/%d/%s" , owner , repo , id , action ), nil , nil , milestone )
85
+ }
86
+
87
+ func (c * Client ) GetIssueMilestone (owner , repo string , index int64 ) (* Milestone , error ) {
88
+ milestone := new (Milestone )
89
+ return milestone , c .getParsedResponse ("GET" , fmt .Sprintf ("/repos/%s/%s/issues/%d/milestone" , owner , repo , index ), nil , nil , & milestone )
90
+ }
91
+
92
+ func (c * Client ) SetIssueMilestone (owner , repo string , index int64 , opt SetIssueMilestoneOption ) (* Milestone , error ) {
93
+ body , err := json .Marshal (& opt )
94
+ if err != nil {
95
+ return nil , err
96
+ }
97
+ milestone := new (Milestone )
98
+ return milestone , c .getParsedResponse ("POST" , fmt .Sprintf ("/repos/%s/%s/issues/%d/milestone" , owner , repo , index ), jsonHeader , bytes .NewReader (body ), & milestone )
99
+ }
100
+
101
+ func (c * Client ) DeleteIssueMilestone (owner , repo string , index int64 ) error {
102
+ _ , err := c .getResponse ("DELETE" , fmt .Sprintf ("/repos/%s/%s/issues/%d/milestone" , owner , repo , index ), nil , nil )
103
+ return err
104
+ }
0 commit comments