Skip to content

Commit 1783a0b

Browse files
authored
feat: affects version (#642)
1 parent 96b6219 commit 1783a0b

File tree

8 files changed

+256
-133
lines changed

8 files changed

+256
-133
lines changed

internal/cmd/epic/create/create.go

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,19 @@ func create(cmd *cobra.Command, _ []string) {
9898
defer s.Stop()
9999

100100
cr := jira.CreateRequest{
101-
Project: project,
102-
IssueType: jira.IssueTypeEpic,
103-
Summary: params.Summary,
104-
Body: params.Body,
105-
Reporter: params.Reporter,
106-
Assignee: params.Assignee,
107-
Priority: params.Priority,
108-
Labels: params.Labels,
109-
Components: params.Components,
110-
FixVersions: params.FixVersions,
111-
CustomFields: params.CustomFields,
112-
EpicField: viper.GetString("epic.name"),
101+
Project: project,
102+
IssueType: jira.IssueTypeEpic,
103+
Summary: params.Summary,
104+
Body: params.Body,
105+
Reporter: params.Reporter,
106+
Assignee: params.Assignee,
107+
Priority: params.Priority,
108+
Labels: params.Labels,
109+
Components: params.Components,
110+
FixVersions: params.FixVersions,
111+
AffectsVersions: params.AffectsVersions,
112+
CustomFields: params.CustomFields,
113+
EpicField: viper.GetString("epic.name"),
113114
}
114115
if projectType != jira.ProjectTypeNextGen {
115116
cr.Name = params.Name
@@ -229,6 +230,9 @@ func parseFlags(flags query.FlagParser) *cmdcommon.CreateParams {
229230
fixVersions, err := flags.GetStringArray("fix-version")
230231
cmdutil.ExitIfError(err)
231232

233+
affectsVersions, err := flags.GetStringArray("affects-version")
234+
cmdutil.ExitIfError(err)
235+
232236
custom, err := flags.GetStringToString("custom")
233237
cmdutil.ExitIfError(err)
234238

@@ -242,18 +246,19 @@ func parseFlags(flags query.FlagParser) *cmdcommon.CreateParams {
242246
cmdutil.ExitIfError(err)
243247

244248
return &cmdcommon.CreateParams{
245-
Name: name,
246-
Summary: summary,
247-
Body: body,
248-
Priority: priority,
249-
Reporter: reporter,
250-
Assignee: assignee,
251-
Labels: labels,
252-
Components: components,
253-
FixVersions: fixVersions,
254-
CustomFields: custom,
255-
Template: template,
256-
NoInput: noInput,
257-
Debug: debug,
249+
Name: name,
250+
Summary: summary,
251+
Body: body,
252+
Priority: priority,
253+
Reporter: reporter,
254+
Assignee: assignee,
255+
Labels: labels,
256+
Components: components,
257+
FixVersions: fixVersions,
258+
AffectsVersions: affectsVersions,
259+
CustomFields: custom,
260+
Template: template,
261+
NoInput: noInput,
262+
Debug: debug,
258263
}
259264
}

internal/cmd/issue/create/create.go

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,20 @@ func create(cmd *cobra.Command, _ []string) {
9999
defer s.Stop()
100100

101101
cr := jira.CreateRequest{
102-
Project: project,
103-
IssueType: params.IssueType,
104-
ParentIssueKey: params.ParentIssueKey,
105-
Summary: params.Summary,
106-
Body: params.Body,
107-
Reporter: params.Reporter,
108-
Assignee: params.Assignee,
109-
Priority: params.Priority,
110-
Labels: params.Labels,
111-
Components: params.Components,
112-
FixVersions: params.FixVersions,
113-
CustomFields: params.CustomFields,
114-
EpicField: viper.GetString("epic.link"),
102+
Project: project,
103+
IssueType: params.IssueType,
104+
ParentIssueKey: params.ParentIssueKey,
105+
Summary: params.Summary,
106+
Body: params.Body,
107+
Reporter: params.Reporter,
108+
Assignee: params.Assignee,
109+
Priority: params.Priority,
110+
Labels: params.Labels,
111+
Components: params.Components,
112+
FixVersions: params.FixVersions,
113+
AffectsVersions: params.AffectsVersions,
114+
CustomFields: params.CustomFields,
115+
EpicField: viper.GetString("epic.link"),
115116
}
116117
cr.ForProjectType(projectType)
117118
cr.ForInstallationType(installation)
@@ -343,6 +344,9 @@ func parseFlags(flags query.FlagParser) *cmdcommon.CreateParams {
343344
fixVersions, err := flags.GetStringArray("fix-version")
344345
cmdutil.ExitIfError(err)
345346

347+
affectsVersions, err := flags.GetStringArray("affects-version")
348+
cmdutil.ExitIfError(err)
349+
346350
custom, err := flags.GetStringToString("custom")
347351
cmdutil.ExitIfError(err)
348352

@@ -356,19 +360,20 @@ func parseFlags(flags query.FlagParser) *cmdcommon.CreateParams {
356360
cmdutil.ExitIfError(err)
357361

358362
return &cmdcommon.CreateParams{
359-
IssueType: issueType,
360-
ParentIssueKey: parentIssueKey,
361-
Summary: summary,
362-
Body: body,
363-
Priority: priority,
364-
Assignee: assignee,
365-
Labels: labels,
366-
Reporter: reporter,
367-
Components: components,
368-
FixVersions: fixVersions,
369-
CustomFields: custom,
370-
Template: template,
371-
NoInput: noInput,
372-
Debug: debug,
363+
IssueType: issueType,
364+
ParentIssueKey: parentIssueKey,
365+
Summary: summary,
366+
Body: body,
367+
Priority: priority,
368+
Assignee: assignee,
369+
Labels: labels,
370+
Reporter: reporter,
371+
Components: components,
372+
FixVersions: fixVersions,
373+
AffectsVersions: affectsVersions,
374+
CustomFields: custom,
375+
Template: template,
376+
NoInput: noInput,
377+
Debug: debug,
373378
}
374379
}

internal/cmd/issue/edit/edit.go

Lines changed: 65 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ func edit(cmd *cobra.Command, args []string) {
127127
}
128128
fixVersions = append(fixVersions, params.fixVersions...)
129129

130+
affectsVersions := make([]string, 0, len(issue.Fields.AffectsVersions)+len(params.affectsVersions))
131+
for _, fv := range issue.Fields.AffectsVersions {
132+
affectsVersions = append(affectsVersions, fv.Name)
133+
}
134+
affectsVersions = append(affectsVersions, params.affectsVersions...)
135+
130136
err = func() error {
131137
s := cmdutil.Info("Updating an issue...")
132138
defer s.Stop()
@@ -142,14 +148,15 @@ func edit(cmd *cobra.Command, args []string) {
142148
}
143149

144150
edr := jira.EditRequest{
145-
ParentIssueKey: parent,
146-
Summary: params.summary,
147-
Body: body,
148-
Priority: params.priority,
149-
Labels: labels,
150-
Components: components,
151-
FixVersions: fixVersions,
152-
CustomFields: params.customFields,
151+
ParentIssueKey: parent,
152+
Summary: params.summary,
153+
Body: body,
154+
Priority: params.priority,
155+
Labels: labels,
156+
Components: components,
157+
FixVersions: fixVersions,
158+
AffectsVersions: affectsVersions,
159+
CustomFields: params.customFields,
153160
}
154161
if configuredCustomFields, err := cmdcommon.GetConfiguredCustomFields(); err == nil {
155162
cmdcommon.ValidateCustomFields(edr.CustomFields, configuredCustomFields)
@@ -187,10 +194,11 @@ func getAnswers(params *editParams, issue *jira.Issue) {
187194
if len(ans.Metadata) > 0 {
188195
qs := getMetadataQuestions(ans.Metadata, issue)
189196
ans := struct {
190-
Priority string
191-
Labels string
192-
Components string
193-
FixVersions string
197+
Priority string
198+
Labels string
199+
Components string
200+
FixVersions string
201+
AffectsVersions string
194202
}{}
195203
err := survey.Ask(qs, &ans)
196204
cmdutil.ExitIfError(err)
@@ -207,6 +215,9 @@ func getAnswers(params *editParams, issue *jira.Issue) {
207215
if len(ans.FixVersions) > 0 {
208216
params.fixVersions = strings.Split(ans.FixVersions, ",")
209217
}
218+
if len(ans.AffectsVersions) > 0 {
219+
params.affectsVersions = strings.Split(ans.AffectsVersions, ",")
220+
}
210221
}
211222
}
212223
}
@@ -289,17 +300,18 @@ func (ec *editCmd) askQuestions(issue *jira.Issue, originalBody string) error {
289300
}
290301

291302
type editParams struct {
292-
issueKey string
293-
summary string
294-
body string
295-
priority string
296-
assignee string
297-
labels []string
298-
components []string
299-
fixVersions []string
300-
customFields map[string]string
301-
noInput bool
302-
debug bool
303+
issueKey string
304+
summary string
305+
body string
306+
priority string
307+
assignee string
308+
labels []string
309+
components []string
310+
fixVersions []string
311+
affectsVersions []string
312+
customFields map[string]string
313+
noInput bool
314+
debug bool
303315
}
304316

305317
func parseArgsAndFlags(flags query.FlagParser, args []string, project string) *editParams {
@@ -324,6 +336,9 @@ func parseArgsAndFlags(flags query.FlagParser, args []string, project string) *e
324336
fixVersions, err := flags.GetStringArray("fix-version")
325337
cmdutil.ExitIfError(err)
326338

339+
affectsVersions, err := flags.GetStringArray("affects-version")
340+
cmdutil.ExitIfError(err)
341+
327342
custom, err := flags.GetStringToString("custom")
328343
cmdutil.ExitIfError(err)
329344

@@ -334,17 +349,18 @@ func parseArgsAndFlags(flags query.FlagParser, args []string, project string) *e
334349
cmdutil.ExitIfError(err)
335350

336351
return &editParams{
337-
issueKey: cmdutil.GetJiraIssueKey(project, args[0]),
338-
summary: summary,
339-
body: body,
340-
priority: priority,
341-
assignee: assignee,
342-
labels: labels,
343-
components: components,
344-
fixVersions: fixVersions,
345-
customFields: custom,
346-
noInput: noInput,
347-
debug: debug,
352+
issueKey: cmdutil.GetJiraIssueKey(project, args[0]),
353+
summary: summary,
354+
body: body,
355+
priority: priority,
356+
assignee: assignee,
357+
labels: labels,
358+
components: components,
359+
fixVersions: fixVersions,
360+
affectsVersions: affectsVersions,
361+
customFields: custom,
362+
noInput: noInput,
363+
debug: debug,
348364
}
349365
}
350366

@@ -356,6 +372,11 @@ func getMetadataQuestions(meta []string, issue *jira.Issue) []*survey.Question {
356372
fixVersions = append(fixVersions, fv.Name)
357373
}
358374

375+
affectsVersions := make([]string, 0, len(issue.Fields.AffectsVersions))
376+
for _, fv := range issue.Fields.AffectsVersions {
377+
affectsVersions = append(affectsVersions, fv.Name)
378+
}
379+
359380
for _, m := range meta {
360381
switch m {
361382
case "Priority":
@@ -389,6 +410,15 @@ func getMetadataQuestions(meta []string, issue *jira.Issue) []*survey.Question {
389410
Default: strings.Join(fixVersions, ","),
390411
},
391412
})
413+
case "AffectsVersions":
414+
qs = append(qs, &survey.Question{
415+
Name: "affectsversions",
416+
Prompt: &survey.Input{
417+
Message: "Affects Versions",
418+
Help: "Comma separated list of affectsVersions. For eg: v1.0-beta,v2.0",
419+
Default: strings.Join(affectsVersions, ","),
420+
},
421+
})
392422
}
393423
}
394424

@@ -407,6 +437,7 @@ func setFlags(cmd *cobra.Command) {
407437
cmd.Flags().StringArrayP("label", "l", []string{}, "Append labels")
408438
cmd.Flags().StringArrayP("component", "C", []string{}, "Replace components")
409439
cmd.Flags().StringArray("fix-version", []string{}, "Add/Append release info (fixVersions)")
440+
cmd.Flags().StringArray("affects-version", []string{}, "Add/Append release info (affectsVersions)")
410441
cmd.Flags().StringToString("custom", custom, "Edit custom fields")
411442
cmd.Flags().Bool("web", false, "Open in web browser after successful update")
412443
cmd.Flags().Bool("no-input", false, "Disable prompt for non-required fields")

0 commit comments

Comments
 (0)