Skip to content

Commit 7c4bee0

Browse files
authored
Merge pull request #1 from prpht9/jira_9_createmeta_api_url_bug
fix createmeta issue on jira 9.x
2 parents 4263bd2 + 3c01795 commit 7c4bee0

File tree

8 files changed

+463
-45
lines changed

8 files changed

+463
-45
lines changed

TODO.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# TODO
2+
3+
* https://confluence.atlassian.com/jiracore/createmeta-rest-endpoint-to-be-removed-975040986.html
4+
* Jira 9.0 moved the parameters on api/2/issue/createmeta into path values
5+
Need to allow both versions to function
6+
Need a configuration item to indicate which url/method to call
7+
Need to write the new method to conform to the new api method format
8+
Need new jiradata type because the api endpoint changed the output json schema
9+
* slipstream to create jiradata types
10+
slipscheme -stdout schema/IssueTypes.json > jiradata/IssueTypes.go
11+
12+
* Old API Doc: https://docs.atlassian.com/software/jira/docs/api/REST/7.2.7/#api/2/issue-getCreateIssueMeta
13+
* New API Doc: https://docs.atlassian.com/software/jira/docs/api/REST/9.0.0/#issue-getCreateIssueMetaProjectIssueTypes

issue.go

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -247,43 +247,38 @@ func CreateIssue(ua HttpClient, endpoint string, iup IssueUpdateProvider) (*jira
247247
}
248248

249249
// https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-getCreateIssueMeta
250-
func (j *Jira) GetIssueCreateMetaProject(projectKey string) (*jiradata.CreateMetaProject, error) {
250+
func (j *Jira) GetIssueCreateMetaProject(projectKey string) (jiradata.Values, error) {
251251
return GetIssueCreateMetaProject(j.UA, j.Endpoint, projectKey)
252252
}
253253

254-
func GetIssueCreateMetaProject(ua HttpClient, endpoint string, projectKey string) (*jiradata.CreateMetaProject, error) {
254+
func GetIssueCreateMetaProject(ua HttpClient, endpoint string, projectKey string) (jiradata.Values, error) {
255255
uri := URLJoin(endpoint, "rest/api/2/issue/createmeta")
256-
uri += fmt.Sprintf("?projectKeys=%s&expand=projects.issuetypes.fields", projectKey)
256+
uri += fmt.Sprintf("/%s/issuetypes", projectKey)
257257
resp, err := ua.GetJSON(uri)
258258
if err != nil {
259259
return nil, err
260260
}
261261
defer resp.Body.Close()
262262

263263
if resp.StatusCode == 200 {
264-
results := &jiradata.CreateMeta{}
264+
results := &jiradata.PageOfCreateMetaIssueType{}
265265
err = json.NewDecoder(resp.Body).Decode(results)
266266
if err != nil {
267267
return nil, err
268268
}
269-
for _, project := range results.Projects {
270-
if project.Key == projectKey {
271-
return project, nil
272-
}
273-
}
274-
return nil, fmt.Errorf("project %s not found", projectKey)
269+
return results.Values, nil
275270
}
276271
return nil, responseError(resp)
277272
}
278273

279274
// https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-getCreateIssueMeta
280-
func (j *Jira) GetIssueCreateMetaIssueType(projectKey, issueTypeName string) (*jiradata.IssueType, error) {
275+
func (j *Jira) GetIssueCreateMetaIssueType(projectKey, issueTypeName string) (*jiradata.CreateMetaIssueType, error) {
281276
return GetIssueCreateMetaIssueType(j.UA, j.Endpoint, projectKey, issueTypeName)
282277
}
283278

284-
func GetIssueCreateMetaIssueType(ua HttpClient, endpoint string, projectKey, issueTypeName string) (*jiradata.IssueType, error) {
279+
func GetIssueCreateMetaIssueType(ua HttpClient, endpoint string, projectKey, issueTypeName string) (*jiradata.CreateMetaIssueType, error) {
285280
uri := URLJoin(endpoint, "rest/api/2/issue/createmeta")
286-
uri += fmt.Sprintf("?projectKeys=%s&issuetypeNames=%s&expand=projects.issuetypes.fields", projectKey, url.QueryEscape(issueTypeName))
281+
uri += fmt.Sprintf("/%s/issuetypes", projectKey)
287282
resp, err := ua.GetJSON(uri)
288283
if err != nil {
289284
return nil, err
@@ -293,18 +288,13 @@ func GetIssueCreateMetaIssueType(ua HttpClient, endpoint string, projectKey, iss
293288
if resp.StatusCode != 200 {
294289
return nil, responseError(resp)
295290
}
296-
results := &jiradata.CreateMeta{}
291+
results := &jiradata.PageOfCreateMetaIssueType{}
297292
if err := json.NewDecoder(resp.Body).Decode(results); err != nil {
298293
return nil, err
299294
}
300-
for _, project := range results.Projects {
301-
if project.Key != projectKey {
302-
continue
303-
}
304-
for _, issueType := range project.IssueTypes {
305-
if issueType.Name == issueTypeName {
306-
return issueType, nil
307-
}
295+
for _, issueType := range results.Values {
296+
if issueType.Name == issueTypeName {
297+
return issueType, nil
308298
}
309299
}
310300
return nil, fmt.Errorf("project %s and IssueType %s not found", projectKey, issueTypeName)

jiracmd/create.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ func CmdCreate(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CreateOptio
7575
}
7676

7777
type templateInput struct {
78-
Meta *jiradata.IssueType `yaml:"meta" json:"meta"`
79-
Overrides map[string]string `yaml:"overrides" json:"overrides"`
78+
Meta *jiradata.CreateMetaIssueType `yaml:"meta" json:"meta"`
79+
Overrides map[string]string `yaml:"overrides" json:"overrides"`
8080
}
8181

8282
if err := defaultIssueType(o, globals.Endpoint.Value, &opts.Project, &opts.IssueType); err != nil {
@@ -157,26 +157,25 @@ func defaultIssueType(o *oreo.Client, endpoint string, project, issuetype *strin
157157
if issuetype != nil && *issuetype != "" {
158158
return nil
159159
}
160-
projectMeta, err := jira.GetIssueCreateMetaProject(o, endpoint, *project)
160+
issueTypes, err := jira.GetIssueCreateMetaProject(o, endpoint, *project)
161161
if err != nil {
162162
return err
163163
}
164164

165-
issueTypes := map[string]bool{}
166-
167-
for _, issuetype := range projectMeta.IssueTypes {
168-
issueTypes[issuetype.Name] = true
169-
}
170-
171165
// prefer "Bug" type
172-
if _, ok := issueTypes["Bug"]; ok {
173-
*issuetype = "Bug"
174-
return nil
166+
for _, issueType := range issueTypes {
167+
if issueType.Name == "Bug" {
168+
*issuetype = "Bug"
169+
return nil
170+
}
175171
}
172+
176173
// next best default it "Task"
177-
if _, ok := issueTypes["Task"]; ok {
178-
*issuetype = "Task"
179-
return nil
174+
for _, issueType := range issueTypes {
175+
if issueType.Name == "Task" {
176+
*issuetype = "Task"
177+
return nil
178+
}
180179
}
181180

182181
return fmt.Errorf("Unable to find default issueType of Bug or Task, please set --issuetype argument or set the `issuetype` config property")

jiracmd/subtask.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ func CmdSubtask(o *oreo.Client, globals *jiracli.GlobalOptions, opts *SubtaskOpt
7373
}
7474

7575
type templateInput struct {
76-
Meta *jiradata.IssueType `yaml:"meta" json:"meta"`
77-
Overrides map[string]string `yaml:"overrides" json:"overrides"`
78-
Parent *jiradata.Issue `yaml:"parent" json:"parent"`
76+
Meta *jiradata.CreateMetaIssueType `yaml:"meta" json:"meta"`
77+
Overrides map[string]string `yaml:"overrides" json:"overrides"`
78+
Parent *jiradata.Issue `yaml:"parent" json:"parent"`
7979
}
8080

8181
parent, err := jira.GetIssue(o, globals.Endpoint.Value, opts.Issue, nil)

jiradata/AllowedValues.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ package jiradata
1111
/////////////////////////////////////////////////////////////////////////
1212

1313
// AllowedValues defined from schema:
14-
// {
15-
// "title": "allowedValues",
16-
// "type": "array",
17-
// "items": {}
18-
// }
14+
//
15+
// {
16+
// "title": "allowedValues",
17+
// "type": "array",
18+
// "items": {}
19+
// }
1920
type AllowedValues []interface{}

jiradata/PageOfCreateMetaIssueType.go

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
package jiradata
2+
3+
/////////////////////////////////////////////////////////////////////////
4+
// This Code is Generated by SlipScheme Project:
5+
// https://github.com/coryb/slipscheme
6+
//
7+
// Generated with command:
8+
// slipscheme -dir jiradata schema/IssueTypes.json
9+
/////////////////////////////////////////////////////////////////////////
10+
// DO NOT EDIT //
11+
/////////////////////////////////////////////////////////////////////////
12+
13+
// PageOfCreateMetaIssueType defined from schema:
14+
//
15+
// {
16+
// "title": "Page of Create Meta Issue Type",
17+
// "id": "https://docs.atlassian.com/jira/REST/schema/page-of-create-meta-issue-type#",
18+
// "type": "object",
19+
// "properties": {
20+
// "last": {
21+
// "title": "last",
22+
// "type": "boolean"
23+
// },
24+
// "size": {
25+
// "title": "size",
26+
// "type": "integer"
27+
// },
28+
// "start": {
29+
// "title": "start",
30+
// "type": "integer"
31+
// },
32+
// "total": {
33+
// "title": "total",
34+
// "type": "integer"
35+
// },
36+
// "values": {
37+
// "title": "values",
38+
// "type": "array",
39+
// "items": {
40+
// "title": "Create Meta Issue Type",
41+
// "type": "object",
42+
// "properties": {
43+
// "avatarId": {
44+
// "title": "avatarId",
45+
// "type": "integer"
46+
// },
47+
// "description": {
48+
// "title": "description",
49+
// "type": "string"
50+
// },
51+
// "expand": {
52+
// "title": "expand",
53+
// "type": "string"
54+
// },
55+
// "fields": {
56+
// "title": "fields",
57+
// "type": "object",
58+
// "patternProperties": {
59+
// ".+": {
60+
// "title": "Field Meta",
61+
// "type": "object",
62+
// "properties": {
63+
// "allowedValues": {
64+
// "title": "allowedValues",
65+
// "type": "array",
66+
// "items": {}
67+
// },
68+
// "autoCompleteUrl": {
69+
// "title": "autoCompleteUrl",
70+
// "type": "string"
71+
// },
72+
// "defaultValue": {
73+
// "title": "defaultValue"
74+
// },
75+
// "fieldId": {
76+
// "title": "fieldId",
77+
// "type": "string"
78+
// },
79+
// "hasDefaultValue": {
80+
// "title": "hasDefaultValue",
81+
// "type": "boolean"
82+
// },
83+
// "name": {
84+
// "title": "name",
85+
// "type": "string"
86+
// },
87+
// "operations": {
88+
// "title": "operations",
89+
// "type": "array",
90+
// "items": {
91+
// "type": "string"
92+
// }
93+
// },
94+
// "required": {
95+
// "title": "required",
96+
// "type": "boolean"
97+
// },
98+
// "schema": {
99+
// "title": "Json Type",
100+
// "type": "object",
101+
// "properties": {
102+
// "custom": {
103+
// "title": "custom",
104+
// "type": "string"
105+
// },
106+
// "customId": {
107+
// "title": "customId",
108+
// "type": "integer"
109+
// },
110+
// "items": {
111+
// "title": "items",
112+
// "type": "string"
113+
// },
114+
// "system": {
115+
// "title": "system",
116+
// "type": "string"
117+
// },
118+
// "type": {
119+
// "title": "type",
120+
// "type": "string"
121+
// }
122+
// }
123+
// }
124+
// }
125+
// }
126+
// }
127+
// },
128+
// "iconUrl": {
129+
// "title": "iconUrl",
130+
// "type": "string"
131+
// },
132+
// "id": {
133+
// "title": "id",
134+
// "type": "string"
135+
// },
136+
// "name": {
137+
// "title": "name",
138+
// "type": "string"
139+
// },
140+
// "self": {
141+
// "title": "self",
142+
// "type": "string"
143+
// },
144+
// "subtask": {
145+
// "title": "subtask",
146+
// "type": "boolean"
147+
// }
148+
// }
149+
// }
150+
// }
151+
// }
152+
// }
153+
type PageOfCreateMetaIssueType struct {
154+
Last bool `json:"last,omitempty" yaml:"last,omitempty"`
155+
Size int `json:"size,omitempty" yaml:"size,omitempty"`
156+
Start int `json:"start,omitempty" yaml:"start,omitempty"`
157+
Total int `json:"total,omitempty" yaml:"total,omitempty"`
158+
Values Values `json:"values,omitempty" yaml:"values,omitempty"`
159+
}

0 commit comments

Comments
 (0)