This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
issue.go
150 lines (124 loc) · 3.78 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
// 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 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
}