From 03d8633ba808f15bf9bf7699a48e1c0ece2d2d63 Mon Sep 17 00:00:00 2001 From: Cory Bennett Date: Wed, 10 May 2017 08:58:53 -0700 Subject: [PATCH] [#80] add `jira unassign` and `jira give ISSUE --default` commands --- commands.go | 16 +++++++++++++++- main/main.go | 16 +++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/commands.go b/commands.go index 030b5a03..65a9a541 100644 --- a/commands.go +++ b/commands.go @@ -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 @@ -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) diff --git a/main/main.go b/main/main.go index f56348d0..fcd7104e 100644 --- a/main/main.go +++ b/main/main.go @@ -82,7 +82,8 @@ Usage: jira comment ISSUE [--noedit] 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 @@ -194,6 +195,7 @@ Command Options: "rank": "rank", "worklog": "worklog", "addworklog": "addworklog", + "unassign": "unassign", } defaults := map[string]interface{}{ @@ -251,6 +253,7 @@ Command Options: "Q|quiet": setopt, "unixproxy": setopt, "down": setopt, + "default": setopt, }) if err := op.ProcessAll(os.Args[1:]); err != nil { @@ -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])