mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-18 20:23:28 +02:00
fix edit with query loop, allow continuation when not submitting previous issue
This commit is contained in:
+16
-14
@@ -250,15 +250,17 @@ func (o *CommonOptions) editFile(fileName string) (changes bool, err error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
var EditLoopAbort = fmt.Errorf("Edit Loop aborted by request")
|
||||
|
||||
func EditLoop(opts *CommonOptions, input interface{}, output interface{}, submit func() error) error {
|
||||
tmpFile, err := tmpTemplate(opts.Template.Value, input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
confirm := func(msg string) (answer bool) {
|
||||
confirm := func(dflt bool, msg string) (answer bool) {
|
||||
survey.AskOne(
|
||||
&survey.Confirm{Message: msg, Default: true},
|
||||
&survey.Confirm{Message: msg, Default: dflt},
|
||||
&answer,
|
||||
nil,
|
||||
)
|
||||
@@ -279,14 +281,14 @@ func EditLoop(opts *CommonOptions, input interface{}, output interface{}, submit
|
||||
changes, err := opts.editFile(tmpFile)
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
if confirm("Editor reported an error, edit again?") {
|
||||
if confirm(true, "Editor reported an error, edit again?") {
|
||||
continue
|
||||
}
|
||||
panic(Exit{Code: 1})
|
||||
return EditLoopAbort
|
||||
}
|
||||
if !changes {
|
||||
if !confirm("No changes detected, submit anyway?") {
|
||||
panic(Exit{Code: 1})
|
||||
if !confirm(false, "No changes detected, submit anyway?") {
|
||||
return EditLoopAbort
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -319,35 +321,35 @@ func EditLoop(opts *CommonOptions, input interface{}, output interface{}, submit
|
||||
var raw interface{}
|
||||
if err := yaml.Unmarshal(data, &raw); err != nil {
|
||||
log.Error(err.Error())
|
||||
if confirm("Invalid YAML syntax, edit again?") {
|
||||
if confirm(true, "Invalid YAML syntax, edit again?") {
|
||||
continue
|
||||
}
|
||||
panic(Exit{Code: 1})
|
||||
return EditLoopAbort
|
||||
}
|
||||
yamlFixup(&raw)
|
||||
fixedYAML, err := yaml.Marshal(&raw)
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
if confirm("Invalid YAML syntax, edit again?") {
|
||||
if confirm(true, "Invalid YAML syntax, edit again?") {
|
||||
continue
|
||||
}
|
||||
panic(Exit{Code: 1})
|
||||
return EditLoopAbort
|
||||
}
|
||||
|
||||
if err := yaml.Unmarshal(fixedYAML, output); err != nil {
|
||||
log.Error(err.Error())
|
||||
if confirm("Invalid YAML syntax, edit again?") {
|
||||
if confirm(true, "Invalid YAML syntax, edit again?") {
|
||||
continue
|
||||
}
|
||||
panic(Exit{Code: 1})
|
||||
return EditLoopAbort
|
||||
}
|
||||
// submit template
|
||||
if err := submit(); err != nil {
|
||||
log.Error(err.Error())
|
||||
if confirm("Jira reported an error, edit again?") {
|
||||
if confirm(true, "Jira reported an error, edit again?") {
|
||||
continue
|
||||
}
|
||||
panic(Exit{Code: 1})
|
||||
return EditLoopAbort
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
+19
-2
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
"github.com/coryb/oreo"
|
||||
|
||||
"gopkg.in/AlecAivazis/survey.v1"
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1"
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
||||
@@ -106,7 +106,7 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, issueData := range results.Issues {
|
||||
for i, issueData := range results.Issues {
|
||||
editMeta, err := jira.GetIssueEditMeta(o, globals.Endpoint.Value, issueData.Key)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -121,6 +121,23 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions)
|
||||
err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
|
||||
return jira.EditIssue(o, globals.Endpoint.Value, issueData.Key, &issueUpdate)
|
||||
})
|
||||
if err == jiracli.EditLoopAbort {
|
||||
if len(results.Issues) > i+1 {
|
||||
var answer bool
|
||||
survey.AskOne(
|
||||
&survey.Confirm{
|
||||
Message: fmt.Sprintf("Continue to edit next issue %s?", results.Issues[i+1].Key),
|
||||
Default: true,
|
||||
},
|
||||
&answer,
|
||||
nil,
|
||||
)
|
||||
if answer {
|
||||
continue
|
||||
}
|
||||
panic(jiracli.Exit{1})
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user