mirror of
https://github.com/Threnklyn/jira.git
synced 2026-06-07 13:33:32 +02:00
Merge pull request #30 from mikepea/unwatch_support
Support for removing a given watcher
This commit is contained in:
@@ -474,6 +474,10 @@ func (c *Cli) FindIssues() (interface{}, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Cli) GetOptString(optName string, dflt string) string {
|
||||||
|
return c.getOptString(optName, dflt)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Cli) getOptString(optName string, dflt string) string {
|
func (c *Cli) getOptString(optName string, dflt string) string {
|
||||||
if val, ok := c.opts[optName].(string); ok {
|
if val, ok := c.opts[optName].(string); ok {
|
||||||
return val
|
return val
|
||||||
@@ -482,6 +486,10 @@ func (c *Cli) getOptString(optName string, dflt string) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Cli) GetOptBool(optName string, dflt bool) bool {
|
||||||
|
return c.getOptBool(optName, dflt)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Cli) getOptBool(optName string, dflt bool) bool {
|
func (c *Cli) getOptBool(optName string, dflt bool) bool {
|
||||||
if val, ok := c.opts[optName].(bool); ok {
|
if val, ok := c.opts[optName].(bool); ok {
|
||||||
return val
|
return val
|
||||||
|
|||||||
+22
-6
@@ -385,22 +385,34 @@ func (c *Cli) CmdDups(duplicate string, issue string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cli) CmdWatch(issue string) error {
|
func (c *Cli) CmdWatch(issue string, watcher string, remove bool) error {
|
||||||
watcher := c.getOptString("watcher", c.opts["user"].(string))
|
log.Debug("watch called: watcher: %q, remove: %n", watcher, remove)
|
||||||
log.Debug("watch called")
|
|
||||||
|
|
||||||
|
var uri string
|
||||||
json, err := jsonEncode(watcher)
|
json, err := jsonEncode(watcher)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/watchers", c.endpoint, issue)
|
|
||||||
if c.getOptBool("dryrun", false) {
|
if c.getOptBool("dryrun", false) {
|
||||||
|
if !remove {
|
||||||
log.Debug("POST: %s", json)
|
log.Debug("POST: %s", json)
|
||||||
log.Debug("Dryrun mode, skipping POST")
|
log.Debug("Dryrun mode, skipping POST")
|
||||||
|
} else {
|
||||||
|
log.Debug("DELETE: %s", watcher)
|
||||||
|
log.Debug("Dryrun mode, skipping POST")
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
resp, err := c.post(uri, json)
|
|
||||||
|
var resp *http.Response
|
||||||
|
if !remove {
|
||||||
|
uri = fmt.Sprintf("%s/rest/api/2/issue/%s/watchers", c.endpoint, issue)
|
||||||
|
resp, err = c.post(uri, json)
|
||||||
|
} else {
|
||||||
|
uri = fmt.Sprintf("%s/rest/api/2/issue/%s/watchers?username=%s", c.endpoint, issue, watcher)
|
||||||
|
resp, err = c.delete(uri)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -412,7 +424,11 @@ func (c *Cli) CmdWatch(issue string) error {
|
|||||||
} else {
|
} else {
|
||||||
logBuffer := bytes.NewBuffer(make([]byte, 0))
|
logBuffer := bytes.NewBuffer(make([]byte, 0))
|
||||||
resp.Write(logBuffer)
|
resp.Write(logBuffer)
|
||||||
err := fmt.Errorf("Unexpected Response From POST")
|
if !remove {
|
||||||
|
err = fmt.Errorf("Unexpected Response From POST")
|
||||||
|
} else {
|
||||||
|
err = fmt.Errorf("Unexpected Response From DELETE")
|
||||||
|
}
|
||||||
log.Error("%s:\n%s", err, logBuffer)
|
log.Error("%s:\n%s", err, logBuffer)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -56,8 +56,8 @@ Usage:
|
|||||||
jira create [--noedit] [-p PROJECT] <Create Options>
|
jira create [--noedit] [-p PROJECT] <Create Options>
|
||||||
jira DUPLICATE dups ISSUE
|
jira DUPLICATE dups ISSUE
|
||||||
jira BLOCKER blocks ISSUE
|
jira BLOCKER blocks ISSUE
|
||||||
jira watch ISSUE [-w WATCHER]
|
|
||||||
jira vote ISSUE [--down]
|
jira vote ISSUE [--down]
|
||||||
|
jira watch ISSUE [-w WATCHER] [--remove]
|
||||||
jira (trans|transition) TRANSITION ISSUE [--noedit] <Edit Options>
|
jira (trans|transition) TRANSITION ISSUE [--noedit] <Edit Options>
|
||||||
jira ack ISSUE [--edit] <Edit Options>
|
jira ack ISSUE [--edit] <Edit Options>
|
||||||
jira close ISSUE [--edit] <Edit Options>
|
jira close ISSUE [--edit] <Edit Options>
|
||||||
@@ -196,6 +196,7 @@ Command Options:
|
|||||||
"a|assignee=s": setopt,
|
"a|assignee=s": setopt,
|
||||||
"i|issuetype=s": setopt,
|
"i|issuetype=s": setopt,
|
||||||
"w|watcher=s": setopt,
|
"w|watcher=s": setopt,
|
||||||
|
"remove": setopt,
|
||||||
"r|reporter=s": setopt,
|
"r|reporter=s": setopt,
|
||||||
"f|queryfields=s": setopt,
|
"f|queryfields=s": setopt,
|
||||||
"s|sort=s": setopt,
|
"s|sort=s": setopt,
|
||||||
@@ -353,7 +354,9 @@ Command Options:
|
|||||||
}
|
}
|
||||||
case "watch":
|
case "watch":
|
||||||
requireArgs(1)
|
requireArgs(1)
|
||||||
err = c.CmdWatch(args[0])
|
watcher := c.GetOptString("watcher", opts["user"].(string))
|
||||||
|
remove := c.GetOptBool("remove", false)
|
||||||
|
err = c.CmdWatch(args[0], watcher, remove)
|
||||||
case "transition":
|
case "transition":
|
||||||
requireArgs(2)
|
requireArgs(2)
|
||||||
setEditing(true)
|
setEditing(true)
|
||||||
|
|||||||
Reference in New Issue
Block a user