add resolution to dup'd issues when necessary

This commit is contained in:
Cory Bennett
2017-09-03 00:38:37 -07:00
parent ad1a62a88d
commit 2638396606
2 changed files with 29 additions and 2 deletions
+14 -2
View File
@@ -72,19 +72,31 @@ func CmdDup(o *oreo.Client, globals *jiracli.GlobalOptions, opts *DupOptions) er
if err != nil {
return err
}
for _, trans := range []string{"close", "done", "start", "stop"} {
for _, trans := range []string{"close", "done", "cancel", "start", "stop"} {
transMeta := meta.Transitions.Find(trans)
if transMeta != nil {
issueUpdate := jiradata.IssueUpdate{
Transition: transMeta,
}
resolution := defaultResolution(transMeta)
if resolution != "" {
issueUpdate.Fields = map[string]interface{}{
"resolution": map[string]interface{}{
"name": resolution,
},
}
}
if err = jira.TransitionIssue(o, globals.Endpoint.Value, opts.InwardIssue.Key, &issueUpdate); err != nil {
return err
}
// if we just started the issue now we need to stop it
if trans != "start" {
break
}
// if we are here then we must be stopping, so need to reset the meta
meta, err = jira.GetIssueTransitions(o, globals.Endpoint.Value, opts.InwardIssue.Key)
if err != nil {
return err
}
}
}
+15
View File
@@ -66,6 +66,21 @@ func CmdTransitionUsage(cmd *kingpin.CmdClause, opts *TransitionOptions) error {
return nil
}
func defaultResolution(transMeta *jiradata.Transition) string {
if resField, ok := transMeta.Fields["resolution"]; ok {
for _, allowedValueRaw := range resField.AllowedValues {
if allowedValue, ok := allowedValueRaw.(map[string]interface{}); ok {
if allowedValue["name"] == "Fixed" {
return "Fixed"
} else if allowedValue["name"] == "Done" {
return "Done"
}
}
}
}
return ""
}
// CmdTransition will move state of the given issue to the given transtion
func CmdTransition(o *oreo.Client, globals *jiracli.GlobalOptions, opts *TransitionOptions) error {
issueData, err := jira.GetIssue(o, globals.Endpoint.Value, opts.Issue, nil)