-
Notifications
You must be signed in to change notification settings - Fork 30
/
issueFieldConfiguration.go
245 lines (196 loc) · 8.86 KB
/
issueFieldConfiguration.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
package jira
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
)
type FieldConfigurationService struct{ client *Client }
type FieldConfigSearchScheme struct {
MaxResults int `json:"maxResults,omitempty"`
StartAt int `json:"startAt,omitempty"`
Total int `json:"total,omitempty"`
IsLast bool `json:"isLast,omitempty"`
Values []*FieldConfigScheme `json:"values,omitempty"`
}
type FieldConfigScheme struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
IsDefault bool `json:"isDefault,omitempty"`
}
// Returns a paginated list of all field configurations.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/issues/fields/configuration#get-all-field-configurations
func (f *FieldConfigurationService) Gets(ctx context.Context, IDs []int, isDefault bool, startAt, maxResults int) (result *FieldConfigSearchScheme, response *Response, err error) {
params := url.Values{}
params.Add("startAt", strconv.Itoa(startAt))
params.Add("maxResults", strconv.Itoa(maxResults))
if isDefault {
params.Add("isDefault", "true")
}
for _, id := range IDs {
params.Add("id", strconv.Itoa(id))
}
var endpoint = fmt.Sprintf("rest/api/3/fieldconfiguration?%v", params.Encode())
request, err := f.client.newRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return
}
request.Header.Set("Accept", "application/json")
response, err = f.client.Do(request)
if err != nil {
return
}
result = new(FieldConfigSearchScheme)
if err = json.Unmarshal(response.BodyAsBytes, &result); err != nil {
return nil, response, fmt.Errorf("unable to marshall the response body, error: %v", err.Error())
}
return
}
type FieldConfigurationItemPageScheme struct {
MaxResults int `json:"maxResults,omitempty"`
StartAt int `json:"startAt,omitempty"`
Total int `json:"total,omitempty"`
IsLast bool `json:"isLast,omitempty"`
Values []*FieldConfigurationItemScheme `json:"values,omitempty"`
}
type FieldConfigurationItemScheme struct {
ID string `json:"id,omitempty"`
IsHidden bool `json:"isHidden,omitempty"`
IsRequired bool `json:"isRequired,omitempty"`
Description string `json:"description,omitempty"`
}
// Returns a paginated list of all fields for a configuration.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/issues/fields/configuration#get-field-configuration-items
func (f *FieldConfigurationService) Items(ctx context.Context, fieldConfigurationID, startAt, maxResults int) (result *FieldConfigurationItemPageScheme, response *Response, err error) {
params := url.Values{}
params.Add("startAt", strconv.Itoa(startAt))
params.Add("maxResults", strconv.Itoa(maxResults))
var endpoint = fmt.Sprintf("rest/api/3/fieldconfiguration/%v/fields?%v", fieldConfigurationID, params.Encode())
request, err := f.client.newRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return
}
request.Header.Set("Accept", "application/json")
response, err = f.client.Do(request)
if err != nil {
return
}
result = new(FieldConfigurationItemPageScheme)
if err = json.Unmarshal(response.BodyAsBytes, &result); err != nil {
return nil, response, fmt.Errorf("unable to marshall the response body, error: %v", err.Error())
}
return
}
type FieldConfigurationSchemePageScheme struct {
MaxResults int `json:"maxResults,omitempty"`
StartAt int `json:"startAt,omitempty"`
Total int `json:"total,omitempty"`
IsLast bool `json:"isLast,omitempty"`
Values []*FieldConfigurationSchemeScheme `json:"values,omitempty"`
}
type FieldConfigurationSchemeScheme struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
}
// Returns a paginated list of field configuration schemes.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/issues/fields/configuration#get-all-field-configuration-schemes
func (f *FieldConfigurationService) Schemes(ctx context.Context, IDs []int, startAt, maxResults int) (result *FieldConfigurationSchemePageScheme, response *Response, err error) {
params := url.Values{}
params.Add("startAt", strconv.Itoa(startAt))
params.Add("maxResults", strconv.Itoa(maxResults))
for _, id := range IDs {
params.Add("id", strconv.Itoa(id))
}
var endpoint = fmt.Sprintf("rest/api/3/fieldconfigurationscheme?%v", params.Encode())
request, err := f.client.newRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return
}
request.Header.Set("Accept", "application/json")
response, err = f.client.Do(request)
if err != nil {
return
}
result = new(FieldConfigurationSchemePageScheme)
if err = json.Unmarshal(response.BodyAsBytes, &result); err != nil {
return nil, response, fmt.Errorf("unable to marshall the response body, error: %v", err.Error())
}
return
}
type FieldConfigurationIssueTypeItemPageScheme struct {
MaxResults int `json:"maxResults,omitempty"`
StartAt int `json:"startAt,omitempty"`
Total int `json:"total,omitempty"`
IsLast bool `json:"isLast,omitempty"`
Values []*FieldConfigurationIssueTypeItemScheme `json:"values,omitempty"`
}
type FieldConfigurationIssueTypeItemScheme struct {
FieldConfigurationSchemeID string `json:"fieldConfigurationSchemeId,omitempty"`
IssueTypeID string `json:"issueTypeId,omitempty"`
FieldConfigurationID string `json:"fieldConfigurationId,omitempty"`
}
// Returns a paginated list of field configuration issue type items.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/issues/fields/configuration#get-field-configuration-issue-type-items
func (f *FieldConfigurationService) IssueTypeItems(ctx context.Context, fieldConfigIDs []int, startAt, maxResults int) (result *FieldConfigurationIssueTypeItemPageScheme, response *Response, err error) {
params := url.Values{}
params.Add("startAt", strconv.Itoa(startAt))
params.Add("maxResults", strconv.Itoa(maxResults))
for _, id := range fieldConfigIDs {
params.Add("fieldConfigurationSchemeId", strconv.Itoa(id))
}
var endpoint = fmt.Sprintf("rest/api/3/fieldconfigurationscheme/mapping?%v", params.Encode())
request, err := f.client.newRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return
}
request.Header.Set("Accept", "application/json")
response, err = f.client.Do(request)
if err != nil {
return
}
result = new(FieldConfigurationIssueTypeItemPageScheme)
if err = json.Unmarshal(response.BodyAsBytes, &result); err != nil {
return nil, response, fmt.Errorf("unable to marshall the response body, error: %v", err.Error())
}
return
}
type FieldConfigurationSchemeProjectPageScheme struct {
MaxResults int `json:"maxResults,omitempty"`
StartAt int `json:"startAt,omitempty"`
Total int `json:"total,omitempty"`
IsLast bool `json:"isLast,omitempty"`
Values []*FieldConfigurationSchemeProjectScheme `json:"values,omitempty"`
}
type FieldConfigurationSchemeProjectScheme struct {
ProjectIds []string `json:"projectIds,omitempty"`
FieldConfigurationScheme *FieldConfigurationSchemeScheme `json:"fieldConfigurationScheme,omitempty"`
}
// Returns a paginated list of field configuration schemes and, for each scheme, a list of the projects that use it.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/issues/fields/configuration#get-field-configuration-schemes-for-projects
func (f *FieldConfigurationService) SchemesByProject(ctx context.Context, projectIDs []int, startAt, maxResults int) (result *FieldConfigurationSchemeProjectPageScheme, response *Response, err error) {
params := url.Values{}
params.Add("startAt", strconv.Itoa(startAt))
params.Add("maxResults", strconv.Itoa(maxResults))
for _, projectID := range projectIDs {
params.Add("projectId", strconv.Itoa(projectID))
}
var endpoint = fmt.Sprintf("rest/api/3/fieldconfigurationscheme/project?%v", params.Encode())
request, err := f.client.newRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return
}
request.Header.Set("Accept", "application/json")
response, err = f.client.Do(request)
if err != nil {
return
}
result = new(FieldConfigurationSchemeProjectPageScheme)
if err = json.Unmarshal(response.BodyAsBytes, &result); err != nil {
return nil, response, fmt.Errorf("unable to marshall the response body, error: %v", err.Error())
}
return
}