diff --git a/go.mod b/go.mod index 9cca9267..bf4ef945 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/imdario/mergo v0.3.7 // indirect github.com/jinzhu/copier v0.0.0-20180308034124-7e38e58719c3 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 - github.com/kr/pretty v0.1.0 + github.com/kr/pretty v0.1.0 // indirect github.com/kr/pty v1.1.4 // indirect github.com/mattn/go-colorable v0.0.9 // indirect github.com/mattn/go-isatty v0.0.3 // indirect diff --git a/go.sum b/go.sum index cfa3b479..84efd8b5 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,6 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZq github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE= github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ= -github.com/coryb/figtree v0.0.0-20180728224503-071d1ef303df h1:cS4Z9Nlv8J4UqFbLp9ltZypgenm2p3Jeg0yqLfpH2pc= -github.com/coryb/figtree v0.0.0-20180728224503-071d1ef303df/go.mod h1:uAkZUEGm6dROpxfy+8vXLs7JrLCI4O+gQyKAuISxI/g= github.com/coryb/figtree v1.0.1-0.20190907170512-58176d03ef0d h1:99xxg8FYj+5TYg88DxA4xL8ODuI6OvuSu35WQOVPDPg= github.com/coryb/figtree v1.0.1-0.20190907170512-58176d03ef0d/go.mod h1:uAkZUEGm6dROpxfy+8vXLs7JrLCI4O+gQyKAuISxI/g= github.com/coryb/kingpeon v0.0.0-20180107011214-9a669f143f2e h1:tGmk9Tuyz7fKuBq/d3nFJvVWRvc48MEBKQC4uYV3wb0= @@ -81,6 +79,7 @@ golang.org/x/net v0.0.0-20171102191033-01c190206fbd h1:CLQSRrSDQMOMkogMxky7XOkER golang.org/x/net v0.0.0-20171102191033-01c190206fbd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/sys v0.0.0-20180727230415-bd9dbc187b6e h1:3dQ4fR8k5KugjVKO0oqSd1odxuk2yaE2CIfxWP2WarQ= golang.org/x/sys v0.0.0-20180727230415-bd9dbc187b6e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/AlecAivazis/survey.v1 v1.6.1 h1:HyWkjKGBpzhNxrpaKRLDqoa4L1f4cMVBNU4bnVmU8Mw= gopkg.in/AlecAivazis/survey.v1 v1.6.1/go.mod h1:2Ehl7OqkBl3Xb8VmC4oFW2bItAhnUfzIjrOzwRxCrOU= diff --git a/jiracmd/create.go b/jiracmd/create.go index b5edea5c..17a43693 100644 --- a/jiracmd/create.go +++ b/jiracmd/create.go @@ -2,6 +2,7 @@ package jiracmd import ( "fmt" + "io/ioutil" "os" "strings" @@ -11,8 +12,8 @@ import ( "github.com/go-jira/jira" "github.com/go-jira/jira/jiracli" "github.com/go-jira/jira/jiradata" - kingpin "gopkg.in/alecthomas/kingpin.v2" - yaml "gopkg.in/coryb/yaml.v2" + "gopkg.in/alecthomas/kingpin.v2" + "gopkg.in/coryb/yaml.v2" ) type CreateOptions struct { @@ -22,6 +23,7 @@ type CreateOptions struct { IssueType string `yaml:"issuetype,omitempty" json:"issuetype,omitempty"` Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"` SaveFile string `yaml:"savefile,omitempty" json:"savefile,omitempty"` + FromFile string `yaml:"fromfile,omitempty" json:"fromfile,omitempty"` } func CmdCreateRegistry() *jiracli.CommandRegistryEntry { @@ -49,6 +51,7 @@ func CmdCreateUsage(cmd *kingpin.CmdClause, opts *CreateOptions) error { jiracli.EditorUsage(cmd, &opts.CommonOptions) jiracli.TemplateUsage(cmd, &opts.CommonOptions) cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing) + cmd.Flag("fromFile", "Use a file instead of the editor").StringVar(&opts.FromFile) cmd.Flag("project", "project to create issue in").Short('p').StringVar(&opts.Project) cmd.Flag("issuetype", "issuetype in to create").Short('i').StringVar(&opts.IssueType) cmd.Flag("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error { @@ -94,18 +97,41 @@ func CmdCreate(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CreateOptio input.Overrides["login"] = globals.Login.Value var issueResp *jiradata.IssueCreateResponse - err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error { - if globals.JiraDeploymentType.Value == jiracli.CloudDeploymentType { - err := fixGDPRUserFields(o, globals.Endpoint.Value, createMeta.Fields, issueUpdate.Fields) - if err != nil { - return err - } + + if opts.FromFile != "" { + // Loading from file + inputFile, err := os.Open(opts.FromFile) + if err != nil { + return err + } + + inputFileBytes, err := ioutil.ReadAll(inputFile) + if err != nil { + return err + } + + err = yaml.Unmarshal(inputFileBytes, &issueUpdate) + if err != nil { + return fmt.Errorf("invalid yaml provided: %v", err) } issueResp, err = jira.CreateIssue(o, globals.Endpoint.Value, &issueUpdate) - return err - }) - if err != nil { - return err + if err != nil { + return err + } + } else { + err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error { + if globals.JiraDeploymentType.Value == jiracli.CloudDeploymentType { + err := fixGDPRUserFields(o, globals.Endpoint.Value, createMeta.Fields, issueUpdate.Fields) + if err != nil { + return err + } + } + issueResp, err = jira.CreateIssue(o, globals.Endpoint.Value, &issueUpdate) + return err + }) + if err != nil { + return err + } } browseLink := jira.URLJoin(globals.Endpoint.Value, "browse", issueResp.Key)