Files
jira/jiracmd/worklogAdd.go
T
Mike Pountney 27f57b2bbe Switch over to using github.com/go-jira/jira, from gopkg.in
There should be no reason to use gopkg.in versioned imports now that
we're using go modules. I think, IANAE.

gopkg.in kind of gets in the way of modules, as it only pulls over
tagged releases from github.com -- this then means that you need to use
go modules 'replace' syntax in the go.mod to use a non-versioned commit
or branch. This is feasible, but kind of ugly.

go modules defaults to pulling the latest version, so the default
behavior is the same as when pulling go-jira.v1 from gopkg.in.
2019-09-14 21:31:11 -07:00

69 lines
2.3 KiB
Go

package jiracmd
import (
"fmt"
"github.com/coryb/figtree"
"github.com/coryb/oreo"
"github.com/go-jira/jira"
"github.com/go-jira/jira/jiracli"
"github.com/go-jira/jira/jiradata"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
type WorklogAddOptions struct {
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() *jiracli.CommandRegistryEntry {
opts := WorklogAddOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("worklog"),
},
}
return &jiracli.CommandRegistryEntry{
"Add a worklog to an issue",
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdWorklogAddUsage(cmd, &opts)
},
func(o *oreo.Client, globals *jiracli.GlobalOptions) error {
return CmdWorklogAdd(o, globals, &opts)
},
}
}
func CmdWorklogAddUsage(cmd *kingpin.CmdClause, opts *WorklogAddOptions) error {
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)
cmd.Flag("started", "Time you started work").Short('S').StringVar(&opts.Started)
cmd.Arg("ISSUE", "issue id to fetch worklogs").Required().StringVar(&opts.Issue)
return nil
}
// 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, 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 !globals.Quiet.Value {
fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
}
if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue)
}
return nil
}