Skip to content

Commit

Permalink
feat: affects version (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
damianoneill authored Aug 23, 2023
1 parent 96b6219 commit 1783a0b
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 133 deletions.
55 changes: 30 additions & 25 deletions internal/cmd/epic/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,19 @@ func create(cmd *cobra.Command, _ []string) {
defer s.Stop()

cr := jira.CreateRequest{
Project: project,
IssueType: jira.IssueTypeEpic,
Summary: params.Summary,
Body: params.Body,
Reporter: params.Reporter,
Assignee: params.Assignee,
Priority: params.Priority,
Labels: params.Labels,
Components: params.Components,
FixVersions: params.FixVersions,
CustomFields: params.CustomFields,
EpicField: viper.GetString("epic.name"),
Project: project,
IssueType: jira.IssueTypeEpic,
Summary: params.Summary,
Body: params.Body,
Reporter: params.Reporter,
Assignee: params.Assignee,
Priority: params.Priority,
Labels: params.Labels,
Components: params.Components,
FixVersions: params.FixVersions,
AffectsVersions: params.AffectsVersions,
CustomFields: params.CustomFields,
EpicField: viper.GetString("epic.name"),
}
if projectType != jira.ProjectTypeNextGen {
cr.Name = params.Name
Expand Down Expand Up @@ -229,6 +230,9 @@ func parseFlags(flags query.FlagParser) *cmdcommon.CreateParams {
fixVersions, err := flags.GetStringArray("fix-version")
cmdutil.ExitIfError(err)

affectsVersions, err := flags.GetStringArray("affects-version")
cmdutil.ExitIfError(err)

custom, err := flags.GetStringToString("custom")
cmdutil.ExitIfError(err)

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

return &cmdcommon.CreateParams{
Name: name,
Summary: summary,
Body: body,
Priority: priority,
Reporter: reporter,
Assignee: assignee,
Labels: labels,
Components: components,
FixVersions: fixVersions,
CustomFields: custom,
Template: template,
NoInput: noInput,
Debug: debug,
Name: name,
Summary: summary,
Body: body,
Priority: priority,
Reporter: reporter,
Assignee: assignee,
Labels: labels,
Components: components,
FixVersions: fixVersions,
AffectsVersions: affectsVersions,
CustomFields: custom,
Template: template,
NoInput: noInput,
Debug: debug,
}
}
59 changes: 32 additions & 27 deletions internal/cmd/issue/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,20 @@ func create(cmd *cobra.Command, _ []string) {
defer s.Stop()

cr := jira.CreateRequest{
Project: project,
IssueType: params.IssueType,
ParentIssueKey: params.ParentIssueKey,
Summary: params.Summary,
Body: params.Body,
Reporter: params.Reporter,
Assignee: params.Assignee,
Priority: params.Priority,
Labels: params.Labels,
Components: params.Components,
FixVersions: params.FixVersions,
CustomFields: params.CustomFields,
EpicField: viper.GetString("epic.link"),
Project: project,
IssueType: params.IssueType,
ParentIssueKey: params.ParentIssueKey,
Summary: params.Summary,
Body: params.Body,
Reporter: params.Reporter,
Assignee: params.Assignee,
Priority: params.Priority,
Labels: params.Labels,
Components: params.Components,
FixVersions: params.FixVersions,
AffectsVersions: params.AffectsVersions,
CustomFields: params.CustomFields,
EpicField: viper.GetString("epic.link"),
}
cr.ForProjectType(projectType)
cr.ForInstallationType(installation)
Expand Down Expand Up @@ -343,6 +344,9 @@ func parseFlags(flags query.FlagParser) *cmdcommon.CreateParams {
fixVersions, err := flags.GetStringArray("fix-version")
cmdutil.ExitIfError(err)

affectsVersions, err := flags.GetStringArray("affects-version")
cmdutil.ExitIfError(err)

custom, err := flags.GetStringToString("custom")
cmdutil.ExitIfError(err)

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

return &cmdcommon.CreateParams{
IssueType: issueType,
ParentIssueKey: parentIssueKey,
Summary: summary,
Body: body,
Priority: priority,
Assignee: assignee,
Labels: labels,
Reporter: reporter,
Components: components,
FixVersions: fixVersions,
CustomFields: custom,
Template: template,
NoInput: noInput,
Debug: debug,
IssueType: issueType,
ParentIssueKey: parentIssueKey,
Summary: summary,
Body: body,
Priority: priority,
Assignee: assignee,
Labels: labels,
Reporter: reporter,
Components: components,
FixVersions: fixVersions,
AffectsVersions: affectsVersions,
CustomFields: custom,
Template: template,
NoInput: noInput,
Debug: debug,
}
}
99 changes: 65 additions & 34 deletions internal/cmd/issue/edit/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ func edit(cmd *cobra.Command, args []string) {
}
fixVersions = append(fixVersions, params.fixVersions...)

affectsVersions := make([]string, 0, len(issue.Fields.AffectsVersions)+len(params.affectsVersions))
for _, fv := range issue.Fields.AffectsVersions {
affectsVersions = append(affectsVersions, fv.Name)
}
affectsVersions = append(affectsVersions, params.affectsVersions...)

err = func() error {
s := cmdutil.Info("Updating an issue...")
defer s.Stop()
Expand All @@ -142,14 +148,15 @@ func edit(cmd *cobra.Command, args []string) {
}

edr := jira.EditRequest{
ParentIssueKey: parent,
Summary: params.summary,
Body: body,
Priority: params.priority,
Labels: labels,
Components: components,
FixVersions: fixVersions,
CustomFields: params.customFields,
ParentIssueKey: parent,
Summary: params.summary,
Body: body,
Priority: params.priority,
Labels: labels,
Components: components,
FixVersions: fixVersions,
AffectsVersions: affectsVersions,
CustomFields: params.customFields,
}
if configuredCustomFields, err := cmdcommon.GetConfiguredCustomFields(); err == nil {
cmdcommon.ValidateCustomFields(edr.CustomFields, configuredCustomFields)
Expand Down Expand Up @@ -187,10 +194,11 @@ func getAnswers(params *editParams, issue *jira.Issue) {
if len(ans.Metadata) > 0 {
qs := getMetadataQuestions(ans.Metadata, issue)
ans := struct {
Priority string
Labels string
Components string
FixVersions string
Priority string
Labels string
Components string
FixVersions string
AffectsVersions string
}{}
err := survey.Ask(qs, &ans)
cmdutil.ExitIfError(err)
Expand All @@ -207,6 +215,9 @@ func getAnswers(params *editParams, issue *jira.Issue) {
if len(ans.FixVersions) > 0 {
params.fixVersions = strings.Split(ans.FixVersions, ",")
}
if len(ans.AffectsVersions) > 0 {
params.affectsVersions = strings.Split(ans.AffectsVersions, ",")
}
}
}
}
Expand Down Expand Up @@ -289,17 +300,18 @@ func (ec *editCmd) askQuestions(issue *jira.Issue, originalBody string) error {
}

type editParams struct {
issueKey string
summary string
body string
priority string
assignee string
labels []string
components []string
fixVersions []string
customFields map[string]string
noInput bool
debug bool
issueKey string
summary string
body string
priority string
assignee string
labels []string
components []string
fixVersions []string
affectsVersions []string
customFields map[string]string
noInput bool
debug bool
}

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

affectsVersions, err := flags.GetStringArray("affects-version")
cmdutil.ExitIfError(err)

custom, err := flags.GetStringToString("custom")
cmdutil.ExitIfError(err)

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

return &editParams{
issueKey: cmdutil.GetJiraIssueKey(project, args[0]),
summary: summary,
body: body,
priority: priority,
assignee: assignee,
labels: labels,
components: components,
fixVersions: fixVersions,
customFields: custom,
noInput: noInput,
debug: debug,
issueKey: cmdutil.GetJiraIssueKey(project, args[0]),
summary: summary,
body: body,
priority: priority,
assignee: assignee,
labels: labels,
components: components,
fixVersions: fixVersions,
affectsVersions: affectsVersions,
customFields: custom,
noInput: noInput,
debug: debug,
}
}

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

affectsVersions := make([]string, 0, len(issue.Fields.AffectsVersions))
for _, fv := range issue.Fields.AffectsVersions {
affectsVersions = append(affectsVersions, fv.Name)
}

for _, m := range meta {
switch m {
case "Priority":
Expand Down Expand Up @@ -389,6 +410,15 @@ func getMetadataQuestions(meta []string, issue *jira.Issue) []*survey.Question {
Default: strings.Join(fixVersions, ","),
},
})
case "AffectsVersions":
qs = append(qs, &survey.Question{
Name: "affectsversions",
Prompt: &survey.Input{
Message: "Affects Versions",
Help: "Comma separated list of affectsVersions. For eg: v1.0-beta,v2.0",
Default: strings.Join(affectsVersions, ","),
},
})
}
}

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

0 comments on commit 1783a0b

Please sign in to comment.