forked from profclems/glab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissue.go
220 lines (185 loc) · 5.82 KB
/
issue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// This is a silly wrapper for go-gitlab but helps maintain consistency
package api
import (
"errors"
"github.com/xanzy/go-gitlab"
)
var ListIssueNotes = func(client *gitlab.Client, projectID interface{}, issueID int, opts *gitlab.ListIssueNotesOptions) ([]*gitlab.Note, error) {
if client == nil {
client = apiClient.Lab()
}
if opts.PerPage == 0 {
opts.PerPage = DefaultListLimit
}
notes, _, err := client.Notes.ListIssueNotes(projectID, issueID, opts)
if err != nil {
return nil, err
}
return notes, nil
}
var UpdateIssue = func(client *gitlab.Client, projectID interface{}, issueID int, opts *gitlab.UpdateIssueOptions) (*gitlab.Issue, error) {
if client == nil {
client = apiClient.Lab()
}
issue, _, err := client.Issues.UpdateIssue(projectID, issueID, opts)
if err != nil {
return nil, err
}
return issue, nil
}
var GetIssue = func(client *gitlab.Client, projectID interface{}, issueID int) (*gitlab.Issue, error) {
if client == nil {
client = apiClient.Lab()
}
issue, _, err := client.Issues.GetIssue(projectID, issueID)
if err != nil {
return nil, err
}
return issue, nil
}
var ProjectListIssueOptionsToGroup = func(l *gitlab.ListProjectIssuesOptions) *gitlab.ListGroupIssuesOptions {
return &gitlab.ListGroupIssuesOptions{
ListOptions: l.ListOptions,
State: l.State,
Labels: l.Labels,
NotLabels: l.NotLabels,
WithLabelDetails: l.WithLabelDetails,
IIDs: l.IIDs,
Milestone: l.Milestone,
Scope: l.Scope,
AuthorID: l.AuthorID,
NotAuthorID: l.NotAuthorID,
AssigneeID: l.AssigneeID,
NotAssigneeID: l.NotAssigneeID,
AssigneeUsername: l.AssigneeUsername,
MyReactionEmoji: l.MyReactionEmoji,
NotMyReactionEmoji: l.NotMyReactionEmoji,
OrderBy: l.OrderBy,
Sort: l.Sort,
Search: l.Search,
In: l.In,
CreatedAfter: l.CreatedAfter,
CreatedBefore: l.CreatedBefore,
UpdatedAfter: l.UpdatedAfter,
UpdatedBefore: l.UpdatedBefore,
IssueType: l.IssueType,
}
}
var ListGroupIssues = func(client *gitlab.Client, groupID interface{}, opts *gitlab.ListGroupIssuesOptions) ([]*gitlab.Issue, error) {
if client == nil {
client = apiClient.Lab()
}
if opts.PerPage == 0 {
opts.PerPage = DefaultListLimit
}
issues, _, err := client.Issues.ListGroupIssues(groupID, opts)
if err != nil {
return nil, err
}
return issues, nil
}
var ListIssues = func(client *gitlab.Client, projectID interface{}, opts *gitlab.ListProjectIssuesOptions) ([]*gitlab.Issue, error) {
if client == nil {
client = apiClient.Lab()
}
if opts.PerPage == 0 {
opts.PerPage = DefaultListLimit
}
issues, _, err := client.Issues.ListProjectIssues(projectID, opts)
if err != nil {
return nil, err
}
return issues, nil
}
var CreateIssue = func(client *gitlab.Client, projectID interface{}, opts *gitlab.CreateIssueOptions) (*gitlab.Issue, error) {
if client == nil {
client = apiClient.Lab()
}
issue, _, err := client.Issues.CreateIssue(projectID, opts)
if err != nil {
return nil, err
}
return issue, nil
}
var DeleteIssue = func(client *gitlab.Client, projectID interface{}, issueID int) error {
if client == nil {
client = apiClient.Lab()
}
_, err := client.Issues.DeleteIssue(projectID, issueID)
if err != nil {
return err
}
return nil
}
var CreateIssueNote = func(client *gitlab.Client, projectID interface{}, mrID int, opts *gitlab.CreateIssueNoteOptions) (*gitlab.Note, error) {
if client == nil {
client = apiClient.Lab()
}
note, _, err := client.Notes.CreateIssueNote(projectID, mrID, opts)
if err != nil {
return note, err
}
return note, nil
}
var SubscribeToIssue = func(client *gitlab.Client, projectID interface{}, issueID int, opts gitlab.RequestOptionFunc) (*gitlab.Issue, error) {
if client == nil {
client = apiClient.Lab()
}
issue, resp, err := client.Issues.SubscribeToIssue(projectID, issueID, opts)
if err != nil {
if resp != nil {
// If the user is already subscribed to the issue, the status code 304 is returned.
if resp.StatusCode == 304 {
return nil, errors.New("you are already subscribed to this issue")
}
}
return issue, err
}
return issue, nil
}
var UnsubscribeFromIssue = func(client *gitlab.Client, projectID interface{}, issueID int, opts gitlab.RequestOptionFunc) (*gitlab.Issue, error) {
if client == nil {
client = apiClient.Lab()
}
issue, resp, err := client.Issues.UnsubscribeFromIssue(projectID, issueID, opts)
if err != nil {
if resp != nil {
// If the user is not subscribed to the issue, the status code 304 is returned.
if resp.StatusCode == 304 {
return nil, errors.New("you are not subscribed to this issue")
}
}
return issue, err
}
return issue, nil
}
var LinkIssues = func(client *gitlab.Client, projectID interface{}, issueIDD int, opts *gitlab.CreateIssueLinkOptions) (*gitlab.Issue, *gitlab.Issue, error) {
if client == nil {
client = apiClient.Lab()
}
issueLink, _, err := client.IssueLinks.CreateIssueLink(projectID, issueIDD, opts)
if err != nil {
return nil, nil, err
}
return issueLink.SourceIssue, issueLink.TargetIssue, nil
}
var SetIssueTimeEstimate = func(client *gitlab.Client, projectID interface{}, issueIDD int, opts *gitlab.SetTimeEstimateOptions) (*gitlab.TimeStats, error) {
if client == nil {
client = apiClient.Lab()
}
timeStats, _, err := client.Issues.SetTimeEstimate(projectID, issueIDD, opts)
if err != nil {
return nil, err
}
return timeStats, nil
}
var AddIssueTimeSpent = func(client *gitlab.Client, projectID interface{}, issueIDD int, opts *gitlab.AddSpentTimeOptions) (*gitlab.TimeStats, error) {
if client == nil {
client = apiClient.Lab()
}
timeStats, _, err := client.Issues.AddSpentTime(projectID, issueIDD, opts)
if err != nil {
return nil, err
}
return timeStats, nil
}