mirror of
https://github.com/Threnklyn/jira.git
synced 2026-06-07 05:23:33 +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
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var EditLoopAbort = fmt.Errorf("Edit Loop aborted by request")
|
||||||
|
|
||||||
func EditLoop(opts *CommonOptions, input interface{}, output interface{}, submit func() error) error {
|
func EditLoop(opts *CommonOptions, input interface{}, output interface{}, submit func() error) error {
|
||||||
tmpFile, err := tmpTemplate(opts.Template.Value, input)
|
tmpFile, err := tmpTemplate(opts.Template.Value, input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
confirm := func(msg string) (answer bool) {
|
confirm := func(dflt bool, msg string) (answer bool) {
|
||||||
survey.AskOne(
|
survey.AskOne(
|
||||||
&survey.Confirm{Message: msg, Default: true},
|
&survey.Confirm{Message: msg, Default: dflt},
|
||||||
&answer,
|
&answer,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
@@ -279,14 +281,14 @@ func EditLoop(opts *CommonOptions, input interface{}, output interface{}, submit
|
|||||||
changes, err := opts.editFile(tmpFile)
|
changes, err := opts.editFile(tmpFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
if confirm("Editor reported an error, edit again?") {
|
if confirm(true, "Editor reported an error, edit again?") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
panic(Exit{Code: 1})
|
return EditLoopAbort
|
||||||
}
|
}
|
||||||
if !changes {
|
if !changes {
|
||||||
if !confirm("No changes detected, submit anyway?") {
|
if !confirm(false, "No changes detected, submit anyway?") {
|
||||||
panic(Exit{Code: 1})
|
return EditLoopAbort
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -319,35 +321,35 @@ func EditLoop(opts *CommonOptions, input interface{}, output interface{}, submit
|
|||||||
var raw interface{}
|
var raw interface{}
|
||||||
if err := yaml.Unmarshal(data, &raw); err != nil {
|
if err := yaml.Unmarshal(data, &raw); err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
if confirm("Invalid YAML syntax, edit again?") {
|
if confirm(true, "Invalid YAML syntax, edit again?") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
panic(Exit{Code: 1})
|
return EditLoopAbort
|
||||||
}
|
}
|
||||||
yamlFixup(&raw)
|
yamlFixup(&raw)
|
||||||
fixedYAML, err := yaml.Marshal(&raw)
|
fixedYAML, err := yaml.Marshal(&raw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
if confirm("Invalid YAML syntax, edit again?") {
|
if confirm(true, "Invalid YAML syntax, edit again?") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
panic(Exit{Code: 1})
|
return EditLoopAbort
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := yaml.Unmarshal(fixedYAML, output); err != nil {
|
if err := yaml.Unmarshal(fixedYAML, output); err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
if confirm("Invalid YAML syntax, edit again?") {
|
if confirm(true, "Invalid YAML syntax, edit again?") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
panic(Exit{Code: 1})
|
return EditLoopAbort
|
||||||
}
|
}
|
||||||
// submit template
|
// submit template
|
||||||
if err := submit(); err != nil {
|
if err := submit(); err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
if confirm("Jira reported an error, edit again?") {
|
if confirm(true, "Jira reported an error, edit again?") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
panic(Exit{Code: 1})
|
return EditLoopAbort
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-2
@@ -5,7 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/coryb/figtree"
|
"github.com/coryb/figtree"
|
||||||
"github.com/coryb/oreo"
|
"github.com/coryb/oreo"
|
||||||
|
"gopkg.in/AlecAivazis/survey.v1"
|
||||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1"
|
"gopkg.in/Netflix-Skunkworks/go-jira.v1"
|
||||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
|
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
|
||||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
"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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, issueData := range results.Issues {
|
for i, issueData := range results.Issues {
|
||||||
editMeta, err := jira.GetIssueEditMeta(o, globals.Endpoint.Value, issueData.Key)
|
editMeta, err := jira.GetIssueEditMeta(o, globals.Endpoint.Value, issueData.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
|
||||||
return jira.EditIssue(o, globals.Endpoint.Value, issueData.Key, &issueUpdate)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user