Skip to content

Commit

Permalink
[#80] add jira unassign and jira give ISSUE --default commands
Browse files Browse the repository at this point in the history
  • Loading branch information
coryb committed May 10, 2017
1 parent 8f1e4e9 commit 03d8633
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
16 changes: 15 additions & 1 deletion commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1040,8 +1040,18 @@ func (c *Cli) CmdLabels(action string, issue string, labels []string) error {
func (c *Cli) CmdAssign(issue string, user string) error {
log.Debugf("assign called")

var userVal interface{} = user
// https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-assign
// If the name is "-1" automatic assignee is used. A null name will remove the assignee.
if user == "" {
userVal = nil
}
if c.GetOptBool("default", false) {
userVal = "-1"
}

json, err := jsonEncode(map[string]interface{}{
"name": user,
"name": userVal,
})
if err != nil {
return err
Expand Down Expand Up @@ -1072,6 +1082,10 @@ func (c *Cli) CmdAssign(issue string, user string) error {
return nil
}

func (c *Cli) CmdUnassign(issue string) error {
return c.CmdAssign(issue, "")
}

// CmdExportTemplates will export the default templates to the template directory.
func (c *Cli) CmdExportTemplates() error {
dir := c.opts["directory"].(string)
Expand Down
16 changes: 13 additions & 3 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ Usage:
jira comment ISSUE [--noedit] <Edit Options>
jira (set,add,remove) labels ISSUE [LABEL] ...
jira take ISSUE
jira (assign|give) ISSUE ASSIGNEE
jira (assign|give) ISSUE [ASSIGNEE|--default]
jira unassign ISSUE
jira fields
jira issuelinktypes
jira transmeta ISSUE
Expand Down Expand Up @@ -194,6 +195,7 @@ Command Options:
"rank": "rank",
"worklog": "worklog",
"addworklog": "addworklog",
"unassign": "unassign",
}

defaults := map[string]interface{}{
Expand Down Expand Up @@ -251,6 +253,7 @@ Command Options:
"Q|quiet": setopt,
"unixproxy": setopt,
"down": setopt,
"default": setopt,
})

if err := op.ProcessAll(os.Args[1:]); err != nil {
Expand Down Expand Up @@ -503,8 +506,15 @@ Command Options:
case "export-templates":
err = c.CmdExportTemplates()
case "assign":
requireArgs(2)
err = c.CmdAssign(args[0], args[1])
requireArgs(1)
assignee := ""
if len(args) > 1 {
assignee = args[1]
}
err = c.CmdAssign(args[0], assignee)
case "unassign":
requireArgs(1)
err = c.CmdUnassign(args[0])
case "view":
requireArgs(1)
err = c.CmdView(args[0])
Expand Down

0 comments on commit 03d8633

Please sign in to comment.