refactor for GlobalOptions and CommonOptions

This commit is contained in:
Cory Bennett
2017-09-02 14:05:27 -07:00
parent 65891e7b3b
commit 979da1f3a5
37 changed files with 544 additions and 647 deletions
+13 -17
View File
@@ -5,38 +5,34 @@ import (
"github.com/coryb/figtree"
"github.com/coryb/oreo"
"gopkg.in/Netflix-Skunkworks/go-jira.v1"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
type AssignOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Assignee string `yaml:"assignee,omitempty" json:"assignee,omitempty"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Assignee string `yaml:"assignee,omitempty" json:"assignee,omitempty"`
}
func CmdAssignRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdAssignRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := AssignOptions{}
return &jiracli.CommandRegistryEntry{
"Assign user to issue",
func() error {
return CmdAssign(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdAssignUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdAssign(o, globals, &opts)
},
}
}
func CmdAssignUsage(cmd *kingpin.CmdClause, opts *AssignOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
cmd.Flag("default", "use default user for assignee").PreAction(func(ctx *kingpin.ParseContext) error {
if jiracli.FlagValue(ctx, "default") == "true" {
opts.Assignee = "-1"
@@ -49,16 +45,16 @@ func CmdAssignUsage(cmd *kingpin.CmdClause, opts *AssignOptions) error {
}
// CmdAssign will assign an issue to a user
func CmdAssign(o *oreo.Client, opts *AssignOptions) error {
err := jira.IssueAssign(o, opts.Endpoint.Value, opts.Issue, opts.Assignee)
func CmdAssign(o *oreo.Client, globals *jiracli.GlobalOptions, opts *AssignOptions) error {
err := jira.IssueAssign(o, globals.Endpoint.Value, opts.Issue, opts.Assignee)
if err != nil {
return err
}
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, opts.Endpoint.Value, opts.Issue)
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
return CmdBrowse(globals, opts.Issue)
}
return nil
+16 -19
View File
@@ -13,13 +13,13 @@ import (
)
type BlockOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.LinkIssueRequest `yaml:",inline" json:",inline" figtree:",inline"`
}
func CmdBlockRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdBlockRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := BlockOptions{
GlobalOptions: jiracli.GlobalOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("edit"),
},
LinkIssueRequest: jiradata.LinkIssueRequest{
@@ -33,23 +33,20 @@ func CmdBlockRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegi
return &jiracli.CommandRegistryEntry{
"Mark issues as blocker",
func() error {
return CmdBlock(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdBlockUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdBlock(o, globals, &opts)
},
}
}
func CmdBlockUsage(cmd *kingpin.CmdClause, opts *BlockOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
jiracli.EditorUsage(cmd, &opts.CommonOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
cmd.Flag("comment", "Comment message when marking issue as blocker").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
opts.Comment = &jiradata.Comment{
Body: jiracli.FlagValue(ctx, "comment"),
@@ -63,17 +60,17 @@ func CmdBlockUsage(cmd *kingpin.CmdClause, opts *BlockOptions) error {
// CmdBlock will update the given issue as being a duplicate by the given dup issue
// and will attempt to resolve the dup issue
func CmdBlock(o *oreo.Client, opts *BlockOptions) error {
if err := jira.LinkIssues(o, opts.Endpoint.Value, &opts.LinkIssueRequest); err != nil {
func CmdBlock(o *oreo.Client, globals *jiracli.GlobalOptions, opts *BlockOptions) error {
if err := jira.LinkIssues(o, globals.Endpoint.Value, &opts.LinkIssueRequest); err != nil {
return err
}
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, opts.Endpoint.Value, opts.InwardIssue.Key)
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, opts.Endpoint.Value, opts.OutwardIssue.Key)
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, globals.Endpoint.Value, opts.InwardIssue.Key)
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, globals.Endpoint.Value, opts.OutwardIssue.Key)
if opts.Browse.Value {
if err := CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.InwardIssue.Key}); err != nil {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.OutwardIssue.Key})
if err := CmdBrowse(globals, opts.InwardIssue.Key); err != nil {
return CmdBrowse(globals, opts.OutwardIssue.Key)
}
}
+9 -23
View File
@@ -9,36 +9,22 @@ import (
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
type BrowseOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
}
func CmdBrowseRegistry(fig *figtree.FigTree) *jiracli.CommandRegistryEntry {
opts := BrowseOptions{}
func CmdBrowseRegistry() *jiracli.CommandRegistryEntry {
issue := ""
return &jiracli.CommandRegistryEntry{
"Open issue in browser",
func() error {
return CmdBrowse(&opts)
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
cmd.Arg("ISSUE", "Issue to browse to").Required().StringVar(&issue)
return nil
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdBrowseUsage(cmd, &opts)
func(globals *jiracli.GlobalOptions) error {
return CmdBrowse(globals, issue)
},
}
}
func CmdBrowseUsage(cmd *kingpin.CmdClause, opts *BrowseOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
cmd.Arg("ISSUE", "Issue to browse to").Required().StringVar(&opts.Issue)
return nil
}
// CmdBrowse open the default system browser to the provided issue
func CmdBrowse(opts *BrowseOptions) error {
return browser.OpenURL(fmt.Sprintf("%s/browse/%s", opts.Endpoint.Value, opts.Issue))
func CmdBrowse(globals *jiracli.GlobalOptions, issue string) error {
return browser.OpenURL(fmt.Sprintf("%s/browse/%s", globals.Endpoint.Value, issue))
}
+17 -20
View File
@@ -13,14 +13,14 @@ import (
)
type CommentOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
}
func CmdCommentRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdCommentRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := CommentOptions{
GlobalOptions: jiracli.GlobalOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("comment"),
},
Overrides: map[string]string{},
@@ -28,23 +28,20 @@ func CmdCommentRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRe
return &jiracli.CommandRegistryEntry{
"Add comment to issue",
func() error {
return CmdComment(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdCommentUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdComment(o, globals, &opts)
},
}
}
func CmdCommentUsage(cmd *kingpin.CmdClause, opts *CommentOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
jiracli.EditorUsage(cmd, &opts.CommonOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
cmd.Flag("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
opts.Overrides["comment"] = jiracli.FlagValue(ctx, "comment")
return nil
@@ -54,25 +51,25 @@ func CmdCommentUsage(cmd *kingpin.CmdClause, opts *CommentOptions) error {
}
// CmdComment will update issue with comment
func CmdComment(o *oreo.Client, opts *CommentOptions) error {
func CmdComment(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CommentOptions) error {
comment := jiradata.Comment{}
input := struct {
Overrides map[string]string
}{
opts.Overrides,
}
err := jiracli.EditLoop(&opts.GlobalOptions, &input, &comment, func() error {
_, err := jira.IssueAddComment(o, opts.Endpoint.Value, opts.Issue, &comment)
err := jiracli.EditLoop(&opts.CommonOptions, &input, &comment, func() error {
_, err := jira.IssueAddComment(o, globals.Endpoint.Value, opts.Issue, &comment)
return err
})
if err != nil {
return err
}
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, opts.Endpoint.Value, opts.Issue)
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
return CmdBrowse(globals, opts.Issue)
}
return nil
+13 -16
View File
@@ -13,35 +13,32 @@ import (
)
type ComponentAddOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.Component `yaml:",inline" json:",inline" figtree:",inline"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.Component `yaml:",inline" json:",inline" figtree:",inline"`
}
func CmdComponentAddRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdComponentAddRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := ComponentAddOptions{
GlobalOptions: jiracli.GlobalOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("component-add"),
},
}
return &jiracli.CommandRegistryEntry{
"Add component",
func() error {
return CmdComponentAdd(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdComponentAddUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdComponentAdd(o, globals, &opts)
},
}
}
func CmdComponentAddUsage(cmd *kingpin.CmdClause, opts *ComponentAddOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.CommonOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing)
cmd.Flag("project", "project to create component in").Short('p').StringVar(&opts.Project)
cmd.Flag("name", "name of component").Short('n').StringVar(&opts.Name)
@@ -52,12 +49,12 @@ func CmdComponentAddUsage(cmd *kingpin.CmdClause, opts *ComponentAddOptions) err
// CmdComponentAdd sends the provided overrides to the "component-add" template for editing, then
// will parse the edited document as YAML and submit the document to jira.
func CmdComponentAdd(o *oreo.Client, opts *ComponentAddOptions) error {
func CmdComponentAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *ComponentAddOptions) error {
var err error
component := &jiradata.Component{}
var resp *jiradata.Component
err = jiracli.EditLoop(&opts.GlobalOptions, &opts.Component, component, func() error {
resp, err = jira.CreateComponent(o, opts.Endpoint.Value, component)
err = jiracli.EditLoop(&opts.CommonOptions, &opts.Component, component, func() error {
resp, err = jira.CreateComponent(o, globals.Endpoint.Value, component)
return err
})
if err != nil {
+11 -14
View File
@@ -12,45 +12,42 @@ import (
)
type ComponentsOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Project string `yaml:"project,omitempty" json:"project,omitempty"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Project string `yaml:"project,omitempty" json:"project,omitempty"`
}
func CmdComponentsRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdComponentsRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := ComponentsOptions{
GlobalOptions: jiracli.GlobalOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("components"),
},
}
return &jiracli.CommandRegistryEntry{
"Show components for a project",
func() error {
return CmdComponents(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdComponentsUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdComponents(o, globals, &opts)
},
}
}
func CmdComponentsUsage(cmd *kingpin.CmdClause, opts *ComponentsOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
cmd.Flag("project", "project to list components").Short('p').StringVar(&opts.Project)
return nil
}
// CmdComponents will get available components for project and send to the "components" template
func CmdComponents(o *oreo.Client, opts *ComponentsOptions) error {
func CmdComponents(o *oreo.Client, globals *jiracli.GlobalOptions, opts *ComponentsOptions) error {
if opts.Project == "" {
return fmt.Errorf("Project Required.")
}
data, err := jira.GetProjectComponents(o, opts.Endpoint.Value, opts.Project)
data, err := jira.GetProjectComponents(o, globals.Endpoint.Value, opts.Project)
if err != nil {
return err
}
+24 -27
View File
@@ -15,17 +15,17 @@ import (
)
type CreateOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.IssueUpdate `yaml:",inline" json:",inline" figtree:",inline"`
Project string `yaml:"project,omitempty" json:"project,omitempty"`
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"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.IssueUpdate `yaml:",inline" json:",inline" figtree:",inline"`
Project string `yaml:"project,omitempty" json:"project,omitempty"`
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"`
}
func CmdCreateRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdCreateRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := CreateOptions{
GlobalOptions: jiracli.GlobalOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("create"),
},
Overrides: map[string]string{},
@@ -33,23 +33,20 @@ func CmdCreateRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandReg
return &jiracli.CommandRegistryEntry{
"Create issue",
func() error {
return CmdCreate(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdCreateUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdCreate(o, globals, &opts)
},
}
}
func CmdCreateUsage(cmd *kingpin.CmdClause, opts *CreateOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
jiracli.EditorUsage(cmd, &opts.CommonOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing)
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)
@@ -64,16 +61,16 @@ func CmdCreateUsage(cmd *kingpin.CmdClause, opts *CreateOptions) error {
// CmdCreate sends the create-metadata to the "create" template for editing, then
// will parse the edited document as YAML and submit the document to jira.
func CmdCreate(o *oreo.Client, opts *CreateOptions) error {
func CmdCreate(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CreateOptions) error {
type templateInput struct {
Meta *jiradata.IssueType `yaml:"meta" json:"meta"`
Overrides map[string]string `yaml:"overrides" json:"overrides"`
}
if err := defaultIssueType(o, opts.Endpoint.Value, &opts.Project, &opts.IssueType); err != nil {
if err := defaultIssueType(o, globals.Endpoint.Value, &opts.Project, &opts.IssueType); err != nil {
return err
}
createMeta, err := jira.GetIssueCreateMetaIssueType(o, opts.Endpoint.Value, opts.Project, opts.IssueType)
createMeta, err := jira.GetIssueCreateMetaIssueType(o, globals.Endpoint.Value, opts.Project, opts.IssueType)
if err != nil {
return err
}
@@ -85,18 +82,18 @@ func CmdCreate(o *oreo.Client, opts *CreateOptions) error {
}
input.Overrides["project"] = opts.Project
input.Overrides["issuetype"] = opts.IssueType
input.Overrides["user"] = opts.User.Value
input.Overrides["user"] = globals.User.Value
var issueResp *jiradata.IssueCreateResponse
err = jiracli.EditLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error {
issueResp, err = jira.CreateIssue(o, opts.Endpoint.Value, &issueUpdate)
err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
issueResp, err = jira.CreateIssue(o, globals.Endpoint.Value, &issueUpdate)
return err
})
if err != nil {
return err
}
fmt.Printf("OK %s %s/browse/%s\n", issueResp.Key, opts.Endpoint.Value, issueResp.Key)
fmt.Printf("OK %s %s/browse/%s\n", issueResp.Key, globals.Endpoint.Value, issueResp.Key)
if opts.SaveFile != "" {
fh, err := os.Create(opts.SaveFile)
@@ -106,7 +103,7 @@ func CmdCreate(o *oreo.Client, opts *CreateOptions) error {
defer fh.Close()
out, err := yaml.Marshal(map[string]string{
"issue": issueResp.Key,
"link": fmt.Sprintf("%s/browse/%s", opts.Endpoint.Value, issueResp.Key),
"link": fmt.Sprintf("%s/browse/%s", globals.Endpoint.Value, issueResp.Key),
})
if err != nil {
return err
@@ -115,7 +112,7 @@ func CmdCreate(o *oreo.Client, opts *CreateOptions) error {
}
if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, issueResp.Key})
return CmdBrowse(globals, issueResp.Key)
}
return nil
}
+13 -16
View File
@@ -9,46 +9,43 @@ import (
)
type CreateMetaOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Project string `yaml:"project,omitempty" json:"project,omitempty"`
IssueType string `yaml:"issuetype,omitempty" json:"issuetype,omitempty"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Project string `yaml:"project,omitempty" json:"project,omitempty"`
IssueType string `yaml:"issuetype,omitempty" json:"issuetype,omitempty"`
}
func CmdCreateMetaRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdCreateMetaRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := CreateMetaOptions{
GlobalOptions: jiracli.GlobalOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("createmeta"),
},
}
return &jiracli.CommandRegistryEntry{
"View 'create' metadata",
func() error {
return CmdCreateMeta(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdCreateMetaUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdCreateMeta(o, globals, &opts)
},
}
}
func CmdCreateMetaUsage(cmd *kingpin.CmdClause, opts *CreateMetaOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
cmd.Flag("project", "project to fetch create metadata").Short('p').StringVar(&opts.Project)
cmd.Flag("issuetype", "issuetype in project to fetch create metadata").Short('i').StringVar(&opts.IssueType)
return nil
}
// Create will get issue create metadata and send to "createmeta" template
func CmdCreateMeta(o *oreo.Client, opts *CreateMetaOptions) error {
if err := defaultIssueType(o, opts.Endpoint.Value, &opts.Project, &opts.IssueType); err != nil {
func CmdCreateMeta(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CreateMetaOptions) error {
if err := defaultIssueType(o, globals.Endpoint.Value, &opts.Project, &opts.IssueType); err != nil {
return err
}
createMeta, err := jira.GetIssueCreateMetaIssueType(o, opts.Endpoint.Value, opts.Project, opts.IssueType)
createMeta, err := jira.GetIssueCreateMetaIssueType(o, globals.Endpoint.Value, opts.Project, opts.IssueType)
if err != nil {
return err
}
+18 -21
View File
@@ -13,15 +13,15 @@ import (
)
type DupOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.LinkIssueRequest `yaml:",inline" json:",inline" figtree:",inline"`
Duplicate string `yaml:"duplicate,omitempty" json:"duplicate,omitempty"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
}
func CmdDupRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdDupRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := DupOptions{
GlobalOptions: jiracli.GlobalOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("edit"),
},
LinkIssueRequest: jiradata.LinkIssueRequest{
@@ -35,23 +35,20 @@ func CmdDupRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegist
return &jiracli.CommandRegistryEntry{
"Mark issues as duplicate",
func() error {
return CmdDup(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdDupUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdDup(o, globals, &opts)
},
}
}
func CmdDupUsage(cmd *kingpin.CmdClause, opts *DupOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
jiracli.EditorUsage(cmd, &opts.CommonOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
cmd.Flag("comment", "Comment message when marking issue as duplicate").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
opts.Comment = &jiradata.Comment{
Body: jiracli.FlagValue(ctx, "comment"),
@@ -65,13 +62,13 @@ func CmdDupUsage(cmd *kingpin.CmdClause, opts *DupOptions) error {
// CmdDups will update the given issue as being a duplicate by the given dup issue
// and will attempt to resolve the dup issue
func CmdDup(o *oreo.Client, opts *DupOptions) error {
if err := jira.LinkIssues(o, opts.Endpoint.Value, &opts.LinkIssueRequest); err != nil {
func CmdDup(o *oreo.Client, globals *jiracli.GlobalOptions, opts *DupOptions) error {
if err := jira.LinkIssues(o, globals.Endpoint.Value, &opts.LinkIssueRequest); err != nil {
return err
}
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, opts.Endpoint.Value, opts.OutwardIssue.Key)
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, globals.Endpoint.Value, opts.OutwardIssue.Key)
meta, err := jira.GetIssueTransitions(o, opts.Endpoint.Value, opts.InwardIssue.Key)
meta, err := jira.GetIssueTransitions(o, globals.Endpoint.Value, opts.InwardIssue.Key)
if err != nil {
return err
}
@@ -81,7 +78,7 @@ func CmdDup(o *oreo.Client, opts *DupOptions) error {
issueUpdate := jiradata.IssueUpdate{
Transition: transMeta,
}
if err = jira.TransitionIssue(o, opts.Endpoint.Value, opts.InwardIssue.Key, &issueUpdate); err != nil {
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
@@ -91,11 +88,11 @@ func CmdDup(o *oreo.Client, opts *DupOptions) error {
}
}
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, opts.Endpoint.Value, opts.InwardIssue.Key)
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, globals.Endpoint.Value, opts.InwardIssue.Key)
if opts.Browse.Value {
if err := CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.OutwardIssue.Key}); err != nil {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.InwardIssue.Key})
if err := CmdBrowse(globals, opts.OutwardIssue.Key); err != nil {
return CmdBrowse(globals, opts.InwardIssue.Key)
}
}
+27 -30
View File
@@ -13,16 +13,16 @@ import (
)
type EditOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.IssueUpdate `yaml:",inline" json:",inline" figtree:",inline"`
jira.SearchOptions `yaml:",inline" json:",inline" figtree:",inline"`
Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.IssueUpdate `yaml:",inline" json:",inline" figtree:",inline"`
jira.SearchOptions `yaml:",inline" json:",inline" figtree:",inline"`
Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
}
func CmdEditRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdEditRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := EditOptions{
GlobalOptions: jiracli.GlobalOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("edit"),
},
Overrides: map[string]string{},
@@ -30,23 +30,20 @@ func CmdEditRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegis
return &jiracli.CommandRegistryEntry{
"Edit issue details",
func() error {
return CmdEdit(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdEditUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdEdit(o, globals, &opts)
},
}
}
func CmdEditUsage(cmd *kingpin.CmdClause, opts *EditOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
jiracli.EditorUsage(cmd, &opts.CommonOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing)
cmd.Flag("query", "Jira Query Language (JQL) expression for the search to edit multiple issues").Short('q').StringVar(&opts.Query)
cmd.Flag("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
@@ -59,18 +56,18 @@ func CmdEditUsage(cmd *kingpin.CmdClause, opts *EditOptions) error {
}
// Edit will get issue data and send to "edit" template
func CmdEdit(o *oreo.Client, opts *EditOptions) error {
func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions) error {
type templateInput struct {
*jiradata.Issue `yaml:",inline"`
Meta *jiradata.EditMeta `yaml:"meta" json:"meta"`
Overrides map[string]string `yaml:"overrides" json:"overrides"`
}
if opts.Issue != "" {
issueData, err := jira.GetIssue(o, opts.Endpoint.Value, opts.Issue, nil)
issueData, err := jira.GetIssue(o, globals.Endpoint.Value, opts.Issue, nil)
if err != nil {
return err
}
editMeta, err := jira.GetIssueEditMeta(o, opts.Endpoint.Value, opts.Issue)
editMeta, err := jira.GetIssueEditMeta(o, globals.Endpoint.Value, opts.Issue)
if err != nil {
return err
}
@@ -81,24 +78,24 @@ func CmdEdit(o *oreo.Client, opts *EditOptions) error {
Meta: editMeta,
Overrides: opts.Overrides,
}
err = jiracli.EditLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error {
return jira.EditIssue(o, opts.Endpoint.Value, opts.Issue, &issueUpdate)
err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
return jira.EditIssue(o, globals.Endpoint.Value, opts.Issue, &issueUpdate)
})
if err != nil {
return err
}
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, opts.Endpoint.Value, opts.Issue)
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
return CmdBrowse(globals, opts.Issue)
}
}
results, err := jira.Search(o, opts.Endpoint.Value, opts)
results, err := jira.Search(o, globals.Endpoint.Value, opts)
if err != nil {
return err
}
for _, issueData := range results.Issues {
editMeta, err := jira.GetIssueEditMeta(o, opts.Endpoint.Value, issueData.Key)
editMeta, err := jira.GetIssueEditMeta(o, globals.Endpoint.Value, issueData.Key)
if err != nil {
return err
}
@@ -108,16 +105,16 @@ func CmdEdit(o *oreo.Client, opts *EditOptions) error {
Issue: issueData,
Meta: editMeta,
}
err = jiracli.EditLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error {
return jira.EditIssue(o, opts.Endpoint.Value, issueData.Key, &issueUpdate)
err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
return jira.EditIssue(o, globals.Endpoint.Value, issueData.Key, &issueUpdate)
})
if err != nil {
return err
}
fmt.Printf("OK %s %s/browse/%s\n", issueData.Key, opts.Endpoint.Value, issueData.Key)
fmt.Printf("OK %s %s/browse/%s\n", issueData.Key, globals.Endpoint.Value, issueData.Key)
if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, issueData.Key})
return CmdBrowse(globals, issueData.Key)
}
}
return nil
+13 -16
View File
@@ -9,43 +9,40 @@ import (
)
type EditMetaOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
}
func CmdEditMetaRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdEditMetaRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := EditMetaOptions{
GlobalOptions: jiracli.GlobalOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("editmeta"),
},
}
return &jiracli.CommandRegistryEntry{
"View 'edit' metadata",
func() error {
return CmdEditMeta(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdEditMetaUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdEditMeta(o, globals, &opts)
},
}
}
func CmdEditMetaUsage(cmd *kingpin.CmdClause, opts *EditMetaOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
cmd.Arg("ISSUE", "edit metadata for issue id").Required().StringVar(&opts.Issue)
return nil
}
// EditMeta will get issue edit metadata and send to "editmeta" template
func CmdEditMeta(o *oreo.Client, opts *EditMetaOptions) error {
editMeta, err := jira.GetIssueEditMeta(o, opts.Endpoint.Value, opts.Issue)
func CmdEditMeta(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditMetaOptions) error {
editMeta, err := jira.GetIssueEditMeta(o, globals.Endpoint.Value, opts.Issue)
if err != nil {
return err
}
@@ -53,7 +50,7 @@ func CmdEditMeta(o *oreo.Client, opts *EditMetaOptions) error {
return err
}
if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
return CmdBrowse(globals, opts.Issue)
}
return nil
}
+5 -5
View File
@@ -15,21 +15,21 @@ type ExportTemplatesOptions struct {
Dir string `yaml:"dir,omitempty" json:"dir,omitempty"`
}
func CmdExportTemplatesRegistry(fig *figtree.FigTree) *jiracli.CommandRegistryEntry {
func CmdExportTemplatesRegistry() *jiracli.CommandRegistryEntry {
opts := ExportTemplatesOptions{}
return &jiracli.CommandRegistryEntry{
"Export templates for customizations",
func() error {
return CmdExportTemplates(&opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
if opts.Dir == "" {
opts.Dir = fmt.Sprintf("%s/.jira.d/templates", jiracli.Homedir())
}
return CmdExportTemplatesUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdExportTemplates(&opts)
},
}
}
+9 -10
View File
@@ -8,27 +8,26 @@ import (
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
func CmdFieldsRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := jiracli.GlobalOptions{
func CmdFieldsRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := jiracli.CommonOptions{
Template: figtree.NewStringOption("fields"),
}
return &jiracli.CommandRegistryEntry{
"Prints all fields, both System and Custom",
func() error {
return CmdFields(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
err := jiracli.GlobalUsage(cmd, &opts)
jiracli.TemplateUsage(cmd, &opts)
return err
return nil
},
func(globals *jiracli.GlobalOptions) error {
return CmdFields(o, globals, &opts)
},
}
}
// Fields will send data from /rest/api/2/field API to "fields" template
func CmdFields(o *oreo.Client, opts *jiracli.GlobalOptions) error {
data, err := jira.GetFields(o, opts.Endpoint.Value)
func CmdFields(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.CommonOptions) error {
data, err := jira.GetFields(o, globals.Endpoint.Value)
if err != nil {
return err
}
+15 -18
View File
@@ -13,12 +13,12 @@ import (
)
type IssueLinkOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.LinkIssueRequest `yaml:",inline" json:",inline" figtree:",inline"`
LinkType string `yaml:"linktype,omitempty" json:"linktype,omitempty"`
}
func CmdIssueLinkRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdIssueLinkRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := IssueLinkOptions{
LinkIssueRequest: jiradata.LinkIssueRequest{
Type: &jiradata.IssueLinkType{},
@@ -28,23 +28,20 @@ func CmdIssueLinkRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.Command
}
return &jiracli.CommandRegistryEntry{
"Link two issues",
func() error {
return CmdIssueLink(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdIssueLinkUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdIssueLink(o, globals, &opts)
},
}
}
func CmdIssueLinkUsage(cmd *kingpin.CmdClause, opts *IssueLinkOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
jiracli.EditorUsage(cmd, &opts.CommonOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
cmd.Flag("comment", "Comment message when linking issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
opts.Comment = &jiradata.Comment{
Body: jiracli.FlagValue(ctx, "comment"),
@@ -59,17 +56,17 @@ func CmdIssueLinkUsage(cmd *kingpin.CmdClause, opts *IssueLinkOptions) error {
// CmdBlock will update the given issue as being a duplicate by the given dup issue
// and will attempt to resolve the dup issue
func CmdIssueLink(o *oreo.Client, opts *IssueLinkOptions) error {
if err := jira.LinkIssues(o, opts.Endpoint.Value, &opts.LinkIssueRequest); err != nil {
func CmdIssueLink(o *oreo.Client, globals *jiracli.GlobalOptions, opts *IssueLinkOptions) error {
if err := jira.LinkIssues(o, globals.Endpoint.Value, &opts.LinkIssueRequest); err != nil {
return err
}
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, opts.Endpoint.Value, opts.InwardIssue.Key)
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, opts.Endpoint.Value, opts.OutwardIssue.Key)
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, globals.Endpoint.Value, opts.InwardIssue.Key)
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, globals.Endpoint.Value, opts.OutwardIssue.Key)
if opts.Browse.Value {
if err := CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.OutwardIssue.Key}); err != nil {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.InwardIssue.Key})
if err := CmdBrowse(globals, opts.OutwardIssue.Key); err != nil {
return CmdBrowse(globals, opts.InwardIssue.Key)
}
}
+9 -12
View File
@@ -8,34 +8,31 @@ import (
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
func CmdIssueLinkTypesRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := jiracli.GlobalOptions{
func CmdIssueLinkTypesRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := jiracli.CommonOptions{
Template: figtree.NewStringOption("issuelinktypes"),
}
return &jiracli.CommandRegistryEntry{
"Show the issue link types",
func() error {
return CmdIssueLinkTypes(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdIssueLinkTypesUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdIssueLinkTypes(o, globals, &opts)
},
}
}
func CmdIssueLinkTypesUsage(cmd *kingpin.CmdClause, opts *jiracli.GlobalOptions) error {
if err := jiracli.GlobalUsage(cmd, opts); err != nil {
return err
}
func CmdIssueLinkTypesUsage(cmd *kingpin.CmdClause, opts *jiracli.CommonOptions) error {
jiracli.TemplateUsage(cmd, opts)
return nil
}
// CmdIssueLinkTypes will get issue link type data and send to "issuelinktypes" template
func CmdIssueLinkTypes(o *oreo.Client, opts *jiracli.GlobalOptions) error {
data, err := jira.GetIssueLinkTypes(o, opts.Endpoint.Value)
func CmdIssueLinkTypes(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.CommonOptions) error {
data, err := jira.GetIssueLinkTypes(o, globals.Endpoint.Value)
if err != nil {
return err
}
+11 -14
View File
@@ -12,45 +12,42 @@ import (
)
type IssueTypesOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Project string `yaml:"project,omitempty" json:"project,omitempty"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Project string `yaml:"project,omitempty" json:"project,omitempty"`
}
func CmdIssueTypesRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdIssueTypesRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := IssueTypesOptions{
GlobalOptions: jiracli.GlobalOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("issuetypes"),
},
}
return &jiracli.CommandRegistryEntry{
"Show issue types for a project",
func() error {
return CmdIssueTypes(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdIssueTypesUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdIssueTypes(o, globals, &opts)
},
}
}
func CmdIssueTypesUsage(cmd *kingpin.CmdClause, opts *IssueTypesOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
cmd.Flag("project", "project to list issueTypes").Short('p').StringVar(&opts.Project)
return nil
}
// CmdIssueTypes will get available issueTypes for project and send to the "issueTypes" template
func CmdIssueTypes(o *oreo.Client, opts *IssueTypesOptions) error {
func CmdIssueTypes(o *oreo.Client, globals *jiracli.GlobalOptions, opts *IssueTypesOptions) error {
if opts.Project == "" {
return fmt.Errorf("Project Required.")
}
data, err := jira.GetIssueCreateMetaProject(o, opts.Endpoint.Value, opts.Project)
data, err := jira.GetIssueCreateMetaProject(o, globals.Endpoint.Value, opts.Project)
if err != nil {
return err
}
+13 -16
View File
@@ -13,37 +13,34 @@ import (
)
type LabelsAddOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Labels []string `yaml:"labels,omitempty" json:"labels,omitempty"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Labels []string `yaml:"labels,omitempty" json:"labels,omitempty"`
}
func CmdLabelsAddRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdLabelsAddRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := LabelsAddOptions{}
return &jiracli.CommandRegistryEntry{
"Add labels to an issue",
func() error {
return CmdLabelsAdd(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdLabelsAddUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdLabelsAdd(o, globals, &opts)
},
}
}
func CmdLabelsAddUsage(cmd *kingpin.CmdClause, opts *LabelsAddOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
cmd.Arg("ISSUE", "issue id to modify labels").Required().StringVar(&opts.Issue)
cmd.Arg("LABEL", "label to add to issue").Required().StringsVar(&opts.Labels)
return nil
}
// CmdLabels will add labels on a given issue
func CmdLabelsAdd(o *oreo.Client, opts *LabelsAddOptions) error {
func CmdLabelsAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *LabelsAddOptions) error {
ops := jiradata.FieldOperations{}
for _, label := range opts.Labels {
ops = append(ops, jiradata.FieldOperation{
@@ -56,12 +53,12 @@ func CmdLabelsAdd(o *oreo.Client, opts *LabelsAddOptions) error {
},
}
if err := jira.EditIssue(o, opts.Endpoint.Value, opts.Issue, &issueUpdate); err != nil {
if err := jira.EditIssue(o, globals.Endpoint.Value, opts.Issue, &issueUpdate); err != nil {
return err
}
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, opts.Endpoint.Value, opts.Issue)
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
return CmdBrowse(globals, opts.Issue)
}
return nil
}
+13 -16
View File
@@ -13,37 +13,34 @@ import (
)
type LabelsRemoveOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Labels []string `yaml:"labels,omitempty" json:"labels,omitempty"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Labels []string `yaml:"labels,omitempty" json:"labels,omitempty"`
}
func CmdLabelsRemoveRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdLabelsRemoveRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := LabelsRemoveOptions{}
return &jiracli.CommandRegistryEntry{
"Remove labels from an issue",
func() error {
return CmdLabelsRemove(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdLabelsRemoveUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdLabelsRemove(o, globals, &opts)
},
}
}
func CmdLabelsRemoveUsage(cmd *kingpin.CmdClause, opts *LabelsRemoveOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
cmd.Arg("ISSUE", "issue id to modify labels").Required().StringVar(&opts.Issue)
cmd.Arg("LABEL", "label to remove from issue").Required().StringsVar(&opts.Labels)
return nil
}
// CmdLabels will remove labels on a given issue
func CmdLabelsRemove(o *oreo.Client, opts *LabelsRemoveOptions) error {
func CmdLabelsRemove(o *oreo.Client, globals *jiracli.GlobalOptions, opts *LabelsRemoveOptions) error {
ops := jiradata.FieldOperations{}
for _, label := range opts.Labels {
ops = append(ops, jiradata.FieldOperation{
@@ -56,13 +53,13 @@ func CmdLabelsRemove(o *oreo.Client, opts *LabelsRemoveOptions) error {
},
}
err := jira.EditIssue(o, opts.Endpoint.Value, opts.Issue, &issueUpdate)
err := jira.EditIssue(o, globals.Endpoint.Value, opts.Issue, &issueUpdate)
if err != nil {
return err
}
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, opts.Endpoint.Value, opts.Issue)
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
return CmdBrowse(globals, opts.Issue)
}
return nil
}
+13 -16
View File
@@ -13,37 +13,34 @@ import (
)
type LabelsSetOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Labels []string `yaml:"labels,omitempty" json:"labels,omitempty"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Labels []string `yaml:"labels,omitempty" json:"labels,omitempty"`
}
func CmdLabelsSetRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdLabelsSetRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := LabelsSetOptions{}
return &jiracli.CommandRegistryEntry{
"Set labels on an issue",
func() error {
return CmdLabelsSet(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdLabelsSetUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdLabelsSet(o, globals, &opts)
},
}
}
func CmdLabelsSetUsage(cmd *kingpin.CmdClause, opts *LabelsSetOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
cmd.Arg("ISSUE", "issue id to modify labels").Required().StringVar(&opts.Issue)
cmd.Arg("LABEL", "label to set on issue").Required().StringsVar(&opts.Labels)
return nil
}
// CmdLabels will set labels on a given issue
func CmdLabelsSet(o *oreo.Client, opts *LabelsSetOptions) error {
func CmdLabelsSet(o *oreo.Client, globals *jiracli.GlobalOptions, opts *LabelsSetOptions) error {
issueUpdate := jiradata.IssueUpdate{
Update: jiradata.FieldOperationsMap{
"labels": jiradata.FieldOperations{
@@ -54,12 +51,12 @@ func CmdLabelsSet(o *oreo.Client, opts *LabelsSetOptions) error {
},
}
if err := jira.EditIssue(o, opts.Endpoint.Value, opts.Issue, &issueUpdate); err != nil {
if err := jira.EditIssue(o, globals.Endpoint.Value, opts.Issue, &issueUpdate); err != nil {
return err
}
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, opts.Endpoint.Value, opts.Issue)
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
return CmdBrowse(globals, opts.Issue)
}
return nil
}
+11 -14
View File
@@ -9,23 +9,20 @@ import (
)
type ListOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
jira.SearchOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jira.SearchOptions `yaml:",inline" json:",inline" figtree:",inline"`
}
func CmdListRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdListRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := ListOptions{
GlobalOptions: jiracli.GlobalOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("list"),
},
}
return &jiracli.CommandRegistryEntry{
"Prints list of issues for given search criteria",
func() error {
return CmdList(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
if opts.MaxResults == 0 {
opts.MaxResults = 500
@@ -38,14 +35,14 @@ func CmdListRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegis
}
return CmdListUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdList(o, globals, &opts)
},
}
}
func CmdListUsage(cmd *kingpin.CmdClause, opts *ListOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
cmd.Flag("assignee", "User assigned the issue").Short('a').StringVar(&opts.Assignee)
cmd.Flag("component", "Component to search for").Short('c').StringVar(&opts.Component)
cmd.Flag("issuetype", "Issue type to search for").Short('i').StringVar(&opts.IssueType)
@@ -60,8 +57,8 @@ func CmdListUsage(cmd *kingpin.CmdClause, opts *ListOptions) error {
}
// List will query jira and send data to "list" template
func CmdList(o *oreo.Client, opts *ListOptions) error {
data, err := jira.Search(o, opts.Endpoint.Value, opts)
func CmdList(o *oreo.Client, globals *jiracli.GlobalOptions, opts *ListOptions) error {
data, err := jira.Search(o, globals.Endpoint.Value, opts)
if err != nil {
return err
}
+12 -12
View File
@@ -12,16 +12,16 @@ import (
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
func CmdLoginRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := jiracli.GlobalOptions{}
func CmdLoginRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := jiracli.CommonOptions{}
return &jiracli.CommandRegistryEntry{
"Attempt to login into jira server",
func() error {
return CmdLogin(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return jiracli.GlobalUsage(cmd, &opts)
return nil
},
func(globals *jiracli.GlobalOptions) error {
return CmdLogin(o, globals, &opts)
},
}
}
@@ -45,19 +45,19 @@ func authCallback(req *http.Request, resp *http.Response) (*http.Response, error
}
// CmdLogin will attempt to login into jira server
func CmdLogin(o *oreo.Client, opts *jiracli.GlobalOptions) error {
func CmdLogin(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.CommonOptions) error {
ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks().WithPostCallback(authCallback)
for {
if session, err := jira.GetSession(o, opts.Endpoint.Value); err != nil {
if session, err := jira.GetSession(o, globals.Endpoint.Value); err != nil {
// No active session so try to create a new one
_, err := jira.NewSession(ua, opts.Endpoint.Value, opts)
_, err := jira.NewSession(ua, globals.Endpoint.Value, globals)
if err != nil {
// reset password on failed session
opts.SetPass("")
globals.SetPass("")
log.Errorf("%s", err)
continue
}
fmt.Println(ansi.Color("OK", "green"), "New session for", opts.User)
fmt.Println(ansi.Color("OK", "green"), "New session for", globals.User)
break
} else {
fmt.Println(ansi.Color("OK", "green"), "Found session for", session.Name)
+11 -11
View File
@@ -11,28 +11,28 @@ import (
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
func CmdLogoutRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := jiracli.GlobalOptions{}
func CmdLogoutRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := jiracli.CommonOptions{}
return &jiracli.CommandRegistryEntry{
"Deactivate sesssion with Jira server",
func() error {
return CmdLogout(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return jiracli.GlobalUsage(cmd, &opts)
return nil
},
func(globals *jiracli.GlobalOptions) error {
return CmdLogout(o, globals, &opts)
},
}
}
// CmdLogout will attempt to terminate an active Jira session
func CmdLogout(o *oreo.Client, opts *jiracli.GlobalOptions) error {
func CmdLogout(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.CommonOptions) error {
ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks()
err := jira.DeleteSession(ua, opts.Endpoint.Value)
err := jira.DeleteSession(ua, globals.Endpoint.Value)
if err == nil {
fmt.Println(ansi.Color("OK", "green"), "Terminated session for", opts.User)
fmt.Println(ansi.Color("OK", "green"), "Terminated session for", globals.User)
} else {
fmt.Printf("%s Failed to terminate session for %s: %s", ansi.Color("ERROR", "red"), opts.User, err)
fmt.Printf("%s Failed to terminate session for %s: %s", ansi.Color("ERROR", "red"), globals.User, err)
}
return nil
}
+16 -19
View File
@@ -13,32 +13,29 @@ import (
)
type RankOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
First string `yaml:"first,omitempty" json:"first,omitempty"`
Second string `yaml:"second,omitempty" json:"second,omitempty"`
Order string `yaml:"order,omitempty" json:"order,omitempty"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
First string `yaml:"first,omitempty" json:"first,omitempty"`
Second string `yaml:"second,omitempty" json:"second,omitempty"`
Order string `yaml:"order,omitempty" json:"order,omitempty"`
}
func CmdRankRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdRankRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := RankOptions{}
return &jiracli.CommandRegistryEntry{
"Mark issues as blocker",
func() error {
return CmdRank(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdRankUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdRank(o, globals, &opts)
},
}
}
func CmdRankUsage(cmd *kingpin.CmdClause, opts *RankOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
cmd.Arg("FIRST-ISSUE", "first issue").Required().StringVar(&opts.First)
cmd.Arg("after|before", "rank ordering").Required().HintOptions("after", "before").EnumVar(&opts.Order, "after", "before")
cmd.Arg("SECOND-ISSUE", "second issue").Required().StringVar(&opts.Second)
@@ -46,7 +43,7 @@ func CmdRankUsage(cmd *kingpin.CmdClause, opts *RankOptions) error {
}
// CmdRank order two issue
func CmdRank(o *oreo.Client, opts *RankOptions) error {
func CmdRank(o *oreo.Client, globals *jiracli.GlobalOptions, opts *RankOptions) error {
req := &jiradata.RankRequest{
Issues: []string{opts.First},
}
@@ -57,16 +54,16 @@ func CmdRank(o *oreo.Client, opts *RankOptions) error {
req.RankBeforeIssue = opts.Second
}
if err := jira.RankIssues(o, opts.Endpoint.Value, req); err != nil {
if err := jira.RankIssues(o, globals.Endpoint.Value, req); err != nil {
return err
}
fmt.Printf("OK %s %s/browse/%s\n", opts.First, opts.Endpoint.Value, opts.First)
fmt.Printf("OK %s %s/browse/%s\n", opts.Second, opts.Endpoint.Value, opts.Second)
fmt.Printf("OK %s %s/browse/%s\n", opts.First, globals.Endpoint.Value, opts.First)
fmt.Printf("OK %s %s/browse/%s\n", opts.Second, globals.Endpoint.Value, opts.Second)
if opts.Browse.Value {
if err := CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.First}); err != nil {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Second})
if err := CmdBrowse(globals, opts.First); err != nil {
return CmdBrowse(globals, opts.Second)
}
}
+9 -12
View File
@@ -15,38 +15,35 @@ import (
)
type RequestOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Method string `yaml:"method,omitempty" json:"method,omitempty"`
URI string `yaml:"uri,omitempty" json:"uri,omitempty"`
Data string `yaml:"data,omitempty" json:"data,omitempty"`
}
func CmdRequestRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdRequestRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := RequestOptions{
GlobalOptions: jiracli.GlobalOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("request"),
},
}
return &jiracli.CommandRegistryEntry{
"Open issue in requestr",
func() error {
return CmdRequest(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
if opts.Method == "" {
opts.Method = "GET"
}
return CmdRequestUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdRequest(o, globals, &opts)
},
}
}
func CmdRequestUsage(cmd *kingpin.CmdClause, opts *RequestOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
cmd.Flag("method", "HTTP request method to use").Short('m').EnumVar(&opts.Method, "GET", "PUT", "POST", "DELETE")
cmd.Arg("API", "Path to Jira API (ie: /rest/api/2/issue)").Required().StringVar(&opts.URI)
cmd.Arg("JSON", "JSON Content to send to API").Required().StringVar(&opts.Data)
@@ -55,10 +52,10 @@ func CmdRequestUsage(cmd *kingpin.CmdClause, opts *RequestOptions) error {
}
// CmdRequest open the default system requestr to the provided issue
func CmdRequest(o *oreo.Client, opts *RequestOptions) error {
func CmdRequest(o *oreo.Client, globals *jiracli.GlobalOptions, opts *RequestOptions) error {
uri := opts.URI
if !strings.HasPrefix(uri, "http") {
uri = opts.Endpoint.Value + uri
uri = globals.Endpoint.Value + uri
}
parsedURI, err := url.Parse(uri)
+23 -26
View File
@@ -13,17 +13,17 @@ import (
)
type SubtaskOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.IssueUpdate `yaml:",inline" json:",inline" figtree:",inline"`
Project string `yaml:"project,omitempty" json:"project,omitempty"`
IssueType string `yaml:"issuetype,omitempty" json:"issuetype,omitempty"`
Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.IssueUpdate `yaml:",inline" json:",inline" figtree:",inline"`
Project string `yaml:"project,omitempty" json:"project,omitempty"`
IssueType string `yaml:"issuetype,omitempty" json:"issuetype,omitempty"`
Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
}
func CmdSubtaskRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdSubtaskRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := SubtaskOptions{
GlobalOptions: jiracli.GlobalOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("subtask"),
},
Overrides: map[string]string{},
@@ -31,26 +31,23 @@ func CmdSubtaskRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRe
return &jiracli.CommandRegistryEntry{
"Subtask issue",
func() error {
return CmdSubtask(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
if opts.IssueType == "" {
opts.IssueType = "Sub-task"
}
return CmdSubtaskUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdSubtask(o, globals, &opts)
},
}
}
func CmdSubtaskUsage(cmd *kingpin.CmdClause, opts *SubtaskOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
jiracli.EditorUsage(cmd, &opts.CommonOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing)
cmd.Flag("project", "project to subtask issue in").Short('p').StringVar(&opts.Project)
cmd.Flag("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
@@ -64,14 +61,14 @@ func CmdSubtaskUsage(cmd *kingpin.CmdClause, opts *SubtaskOptions) error {
// CmdSubtask sends the subtask-metadata to the "subtask" template for editing, then
// will parse the edited document as YAML and submit the document to jira.
func CmdSubtask(o *oreo.Client, opts *SubtaskOptions) error {
func CmdSubtask(o *oreo.Client, globals *jiracli.GlobalOptions, opts *SubtaskOptions) error {
type templateInput struct {
Meta *jiradata.IssueType `yaml:"meta" json:"meta"`
Overrides map[string]string `yaml:"overrides" json:"overrides"`
Parent *jiradata.Issue `yaml:"parent" json:"parent"`
}
parent, err := jira.GetIssue(o, opts.Endpoint.Value, opts.Issue, nil)
parent, err := jira.GetIssue(o, globals.Endpoint.Value, opts.Issue, nil)
if err != nil {
return err
}
@@ -86,7 +83,7 @@ func CmdSubtask(o *oreo.Client, opts *SubtaskOptions) error {
return fmt.Errorf("Failed to find Project field in parent issue")
}
createMeta, err := jira.GetIssueCreateMetaIssueType(o, opts.Endpoint.Value, opts.Project, opts.IssueType)
createMeta, err := jira.GetIssueCreateMetaIssueType(o, globals.Endpoint.Value, opts.Project, opts.IssueType)
if err != nil {
return err
}
@@ -99,21 +96,21 @@ func CmdSubtask(o *oreo.Client, opts *SubtaskOptions) error {
}
input.Overrides["project"] = opts.Project
input.Overrides["issuetype"] = opts.IssueType
input.Overrides["user"] = opts.User.Value
input.Overrides["user"] = globals.User.Value
var issueResp *jiradata.IssueCreateResponse
err = jiracli.EditLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error {
issueResp, err = jira.CreateIssue(o, opts.Endpoint.Value, &issueUpdate)
err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
issueResp, err = jira.CreateIssue(o, globals.Endpoint.Value, &issueUpdate)
return err
})
if err != nil {
return err
}
fmt.Printf("OK %s %s/browse/%s\n", issueResp.Key, opts.Endpoint.Value, issueResp.Key)
fmt.Printf("OK %s %s/browse/%s\n", issueResp.Key, globals.Endpoint.Value, issueResp.Key)
if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, issueResp.Key})
return CmdBrowse(globals, issueResp.Key)
}
return nil
}
+7 -10
View File
@@ -7,27 +7,24 @@ import (
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
func CmdTakeRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdTakeRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := AssignOptions{}
return &jiracli.CommandRegistryEntry{
"Assign issue to yourself",
func() error {
opts.Assignee = opts.User.Value
return CmdAssign(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdAssignUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
opts.Assignee = globals.User.Value
return CmdAssign(o, globals, &opts)
},
}
}
func CmdTakeUsage(cmd *kingpin.CmdClause, opts *AssignOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
cmd.Arg("ISSUE", "issue to assign").Required().StringVar(&opts.Issue)
return nil
}
+20 -23
View File
@@ -14,16 +14,16 @@ import (
)
type TransitionOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"`
Transition string `yaml:"transition,omitempty" json:"transition,omitempty"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Resolution string `yaml:"resolution,omitempty" json:"resolution,omitempty"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"`
Transition string `yaml:"transition,omitempty" json:"transition,omitempty"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Resolution string `yaml:"resolution,omitempty" json:"resolution,omitempty"`
}
func CmdTransitionRegistry(fig *figtree.FigTree, o *oreo.Client, transition string) *jiracli.CommandRegistryEntry {
func CmdTransitionRegistry(o *oreo.Client, transition string) *jiracli.CommandRegistryEntry {
opts := TransitionOptions{
GlobalOptions: jiracli.GlobalOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("transition"),
},
Overrides: map[string]string{},
@@ -37,25 +37,22 @@ func CmdTransitionRegistry(fig *figtree.FigTree, o *oreo.Client, transition stri
return &jiracli.CommandRegistryEntry{
help,
func() error {
return CmdTransition(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
if opts.Transition == "" {
opts.Transition = transition
}
return CmdTransitionUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdTransition(o, globals, &opts)
},
}
}
func CmdTransitionUsage(cmd *kingpin.CmdClause, opts *TransitionOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing)
cmd.Flag("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
opts.Overrides["comment"] = jiracli.FlagValue(ctx, "comment")
@@ -70,13 +67,13 @@ func CmdTransitionUsage(cmd *kingpin.CmdClause, opts *TransitionOptions) error {
}
// CmdTransition will move state of the given issue to the given transtion
func CmdTransition(o *oreo.Client, opts *TransitionOptions) error {
issueData, err := jira.GetIssue(o, opts.Endpoint.Value, opts.Issue, nil)
func CmdTransition(o *oreo.Client, globals *jiracli.GlobalOptions, opts *TransitionOptions) error {
issueData, err := jira.GetIssue(o, globals.Endpoint.Value, opts.Issue, nil)
if err != nil {
return jiracli.CliError(err)
}
meta, err := jira.GetIssueTransitions(o, opts.Endpoint.Value, opts.Issue)
meta, err := jira.GetIssueTransitions(o, globals.Endpoint.Value, opts.Issue)
if err != nil {
return jiracli.CliError(err)
}
@@ -128,16 +125,16 @@ func CmdTransition(o *oreo.Client, opts *TransitionOptions) error {
Transition: transMeta,
Overrides: opts.Overrides,
}
err = jiracli.EditLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error {
return jira.TransitionIssue(o, opts.Endpoint.Value, opts.Issue, &issueUpdate)
err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
return jira.TransitionIssue(o, globals.Endpoint.Value, opts.Issue, &issueUpdate)
})
if err != nil {
return jiracli.CliError(err)
}
fmt.Printf("OK %s %s/browse/%s\n", issueData.Key, opts.Endpoint.Value, issueData.Key)
fmt.Printf("OK %s %s/browse/%s\n", issueData.Key, globals.Endpoint.Value, issueData.Key)
if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
return CmdBrowse(globals, opts.Issue)
}
return nil
}
+13 -16
View File
@@ -9,42 +9,39 @@ import (
)
type TransitionsOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
}
func CmdTransitionsRegistry(fig *figtree.FigTree, o *oreo.Client, defaultTemplate string) *jiracli.CommandRegistryEntry {
func CmdTransitionsRegistry(o *oreo.Client, defaultTemplate string) *jiracli.CommandRegistryEntry {
opts := TransitionsOptions{
GlobalOptions: jiracli.GlobalOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption(defaultTemplate),
},
}
return &jiracli.CommandRegistryEntry{
"List valid issue transitions",
func() error {
return CmdTransitions(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdTransitionsUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdTransitions(o, globals, &opts)
},
}
}
func CmdTransitionsUsage(cmd *kingpin.CmdClause, opts *TransitionsOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
cmd.Arg("ISSUE", "issue to list valid transitions").Required().StringVar(&opts.Issue)
return nil
}
// Transitions will get issue edit metadata and send to "editmeta" template
func CmdTransitions(o *oreo.Client, opts *TransitionsOptions) error {
editMeta, err := jira.GetIssueTransitions(o, opts.Endpoint.Value, opts.Issue)
func CmdTransitions(o *oreo.Client, globals *jiracli.GlobalOptions, opts *TransitionsOptions) error {
editMeta, err := jira.GetIssueTransitions(o, globals.Endpoint.Value, opts.Issue)
if err != nil {
return err
}
@@ -52,7 +49,7 @@ func CmdTransitions(o *oreo.Client, opts *TransitionsOptions) error {
return err
}
if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
return CmdBrowse(globals, opts.Issue)
}
return nil
}
+6 -9
View File
@@ -7,26 +7,23 @@ import (
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
func CmdUnassignRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdUnassignRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := AssignOptions{}
return &jiracli.CommandRegistryEntry{
"Unassign an issue",
func() error {
return CmdAssign(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdAssignUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdAssign(o, globals, &opts)
},
}
}
func CmdUnassignUsage(cmd *kingpin.CmdClause, opts *AssignOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
cmd.Arg("ISSUE", "issue to unassign").Required().StringVar(&opts.Issue)
return nil
}
+5 -5
View File
@@ -12,15 +12,12 @@ import (
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
func CmdUnexportTemplatesRegistry(fig *figtree.FigTree) *jiracli.CommandRegistryEntry {
func CmdUnexportTemplatesRegistry() *jiracli.CommandRegistryEntry {
opts := ExportTemplatesOptions{}
return &jiracli.CommandRegistryEntry{
"Remove unmodified exported templates",
func() error {
return CmdUnexportTemplates(&opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
if opts.Dir != "" {
opts.Dir = fmt.Sprintf("%s/.jira.d/templates", jiracli.Homedir())
@@ -28,6 +25,9 @@ func CmdUnexportTemplatesRegistry(fig *figtree.FigTree) *jiracli.CommandRegistry
return CmdExportTemplatesUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdUnexportTemplates(&opts)
},
}
}
+14 -17
View File
@@ -9,36 +9,33 @@ import (
)
type ViewOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
jira.IssueOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jira.IssueOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
}
func CmdViewRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdViewRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := ViewOptions{
GlobalOptions: jiracli.GlobalOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("view"),
},
}
return &jiracli.CommandRegistryEntry{
"Prints issue details",
func() error {
return CmdView(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdViewUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdView(o, globals, &opts)
},
}
}
func CmdViewUsage(cmd *kingpin.CmdClause, opts *ViewOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
cmd.Flag("expand", "field to expand for the issue").StringsVar(&opts.Expand)
cmd.Flag("field", "field to return for the issue").StringsVar(&opts.Fields)
cmd.Flag("property", "property to return for issue").StringsVar(&opts.Properties)
@@ -47,8 +44,8 @@ func CmdViewUsage(cmd *kingpin.CmdClause, opts *ViewOptions) error {
}
// View will get issue data and send to "view" template
func CmdView(o *oreo.Client, opts *ViewOptions) error {
data, err := jira.GetIssue(o, opts.Endpoint.Value, opts.Issue, opts)
func CmdView(o *oreo.Client, globals *jiracli.GlobalOptions, opts *ViewOptions) error {
data, err := jira.GetIssue(o, globals.Endpoint.Value, opts.Issue, opts)
if err != nil {
return err
}
@@ -56,7 +53,7 @@ func CmdView(o *oreo.Client, opts *ViewOptions) error {
return err
}
if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
return CmdBrowse(globals, opts.Issue)
}
return nil
}
+15 -18
View File
@@ -19,34 +19,31 @@ const (
)
type VoteOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Action VoteAction `yaml:"-" json:"-"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Action VoteAction `yaml:"-" json:"-"`
}
func CmdVoteRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdVoteRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := VoteOptions{
GlobalOptions: jiracli.GlobalOptions{},
CommonOptions: jiracli.CommonOptions{},
Action: VoteUP,
}
return &jiracli.CommandRegistryEntry{
"Vote up/down an issue",
func() error {
return CmdVote(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdVoteUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdVote(o, globals, &opts)
},
}
}
func CmdVoteUsage(cmd *kingpin.CmdClause, opts *VoteOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
cmd.Flag("down", "downvote the issue").Short('d').PreAction(func(ctx *kingpin.ParseContext) error {
opts.Action = VoteDown
return nil
@@ -56,20 +53,20 @@ func CmdVoteUsage(cmd *kingpin.CmdClause, opts *VoteOptions) error {
}
// Vote will up/down vote an issue
func CmdVote(o *oreo.Client, opts *VoteOptions) error {
func CmdVote(o *oreo.Client, globals *jiracli.GlobalOptions, opts *VoteOptions) error {
if opts.Action == VoteUP {
if err := jira.IssueAddVote(o, opts.Endpoint.Value, opts.Issue); err != nil {
if err := jira.IssueAddVote(o, globals.Endpoint.Value, opts.Issue); err != nil {
return err
}
} else {
if err := jira.IssueRemoveVote(o, opts.Endpoint.Value, opts.Issue); err != nil {
if err := jira.IssueRemoveVote(o, globals.Endpoint.Value, opts.Issue); err != nil {
return err
}
}
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, opts.Endpoint.Value, opts.Issue)
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
return CmdBrowse(globals, opts.Issue)
}
return nil
}
+17 -20
View File
@@ -19,35 +19,32 @@ const (
)
type WatchOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Watcher string `yaml:"watcher,omitempty" json:"watcher,omitempty"`
Action WatchAction `yaml:"-" json:"-"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Watcher string `yaml:"watcher,omitempty" json:"watcher,omitempty"`
Action WatchAction `yaml:"-" json:"-"`
}
func CmdWatchRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdWatchRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := WatchOptions{
GlobalOptions: jiracli.GlobalOptions{},
CommonOptions: jiracli.CommonOptions{},
Action: WatcherAdd,
}
return &jiracli.CommandRegistryEntry{
"Add/Remove watcher to issue",
func() error {
return CmdWatch(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdWatchUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdWatch(o, globals, &opts)
},
}
}
func CmdWatchUsage(cmd *kingpin.CmdClause, opts *WatchOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
cmd.Flag("remove", "remove watcher from issue").Short('r').PreAction(func(ctx *kingpin.ParseContext) error {
opts.Action = WatcherRemove
return nil
@@ -59,24 +56,24 @@ func CmdWatchUsage(cmd *kingpin.CmdClause, opts *WatchOptions) error {
// CmdWatch will add the given watcher to the issue (or remove the watcher
// with the 'remove' flag)
func CmdWatch(o *oreo.Client, opts *WatchOptions) error {
func CmdWatch(o *oreo.Client, globals *jiracli.GlobalOptions, opts *WatchOptions) error {
if opts.Watcher == "" {
opts.Watcher = opts.User.Value
opts.Watcher = globals.User.Value
}
if opts.Action == WatcherAdd {
if err := jira.IssueAddWatcher(o, opts.Endpoint.Value, opts.Issue, opts.Watcher); err != nil {
if err := jira.IssueAddWatcher(o, globals.Endpoint.Value, opts.Issue, opts.Watcher); err != nil {
return err
}
} else {
if err := jira.IssueRemoveWatcher(o, opts.Endpoint.Value, opts.Issue, opts.Watcher); err != nil {
if err := jira.IssueRemoveWatcher(o, globals.Endpoint.Value, opts.Issue, opts.Watcher); err != nil {
return err
}
}
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, opts.Endpoint.Value, opts.Issue)
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
return CmdBrowse(globals, opts.Issue)
}
return nil
+16 -19
View File
@@ -10,36 +10,33 @@ import (
)
type WorklogAddOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.Worklog `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.Worklog `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
}
func CmdWorklogAddRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdWorklogAddRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := WorklogAddOptions{
GlobalOptions: jiracli.GlobalOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("worklog"),
},
}
return &jiracli.CommandRegistryEntry{
"Add a worklog to an issue",
func() error {
return CmdWorklogAdd(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdWorklogAddUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdWorklogAdd(o, globals, &opts)
},
}
}
func CmdWorklogAddUsage(cmd *kingpin.CmdClause, opts *WorklogAddOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
jiracli.EditorUsage(cmd, &opts.CommonOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing)
cmd.Flag("comment", "Comment message for worklog").Short('m').StringVar(&opts.Comment)
cmd.Flag("time-spent", "Time spent working on issue").Short('T').StringVar(&opts.TimeSpent)
@@ -50,16 +47,16 @@ func CmdWorklogAddUsage(cmd *kingpin.CmdClause, opts *WorklogAddOptions) error {
// CmdWorklogAdd will attempt to add (action=add) a worklog to the given issue.
// It will spawn the editor (unless --noedit isused) and post edited YAML
// content as JSON to the worklog endpoint
func CmdWorklogAdd(o *oreo.Client, opts *WorklogAddOptions) error {
err := jiracli.EditLoop(&opts.GlobalOptions, &opts.Worklog, &opts.Worklog, func() error {
_, err := jira.AddIssueWorklog(o, opts.Endpoint.Value, opts.Issue, opts)
func CmdWorklogAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *WorklogAddOptions) error {
err := jiracli.EditLoop(&opts.CommonOptions, &opts.Worklog, &opts.Worklog, func() error {
_, err := jira.AddIssueWorklog(o, globals.Endpoint.Value, opts.Issue, opts)
return err
})
if err != nil {
return err
}
if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
return CmdBrowse(globals, opts.Issue)
}
return nil
}
+13 -16
View File
@@ -9,41 +9,38 @@ import (
)
type WorklogListOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
}
func CmdWorklogListRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
func CmdWorklogListRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := WorklogListOptions{
GlobalOptions: jiracli.GlobalOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("worklogs"),
},
}
return &jiracli.CommandRegistryEntry{
"Prints the worklog data for given issue",
func() error {
return CmdWorklogList(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdWorklogListUsage(cmd, &opts)
},
func(globals *jiracli.GlobalOptions) error {
return CmdWorklogList(o, globals, &opts)
},
}
}
func CmdWorklogListUsage(cmd *kingpin.CmdClause, opts *WorklogListOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
cmd.Arg("ISSUE", "issue id to fetch worklogs").Required().StringVar(&opts.Issue)
return nil
}
// // CmdWorklogList will get worklog data for given issue and sent to the "worklogs" template
func CmdWorklogList(o *oreo.Client, opts *WorklogListOptions) error {
data, err := jira.GetIssueWorklog(o, opts.Endpoint.Value, opts.Issue)
func CmdWorklogList(o *oreo.Client, globals *jiracli.GlobalOptions, opts *WorklogListOptions) error {
data, err := jira.GetIssueWorklog(o, globals.Endpoint.Value, opts.Issue)
if err != nil {
return err
}
@@ -51,7 +48,7 @@ func CmdWorklogList(o *oreo.Client, opts *WorklogListOptions) error {
return err
}
if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
return CmdBrowse(globals, opts.Issue)
}
return nil
}