mirror of
https://github.com/Threnklyn/jira.git
synced 2026-06-06 21:20:48 +02:00
adding "comment" command
This commit is contained in:
+12
-10
@@ -248,17 +248,19 @@ func (c *Cli) editTemplate(template string, tmpFilePrefix string, templateData m
|
|||||||
} else {
|
} else {
|
||||||
edited = fixed.(map[string]interface{})
|
edited = fixed.(map[string]interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
mf := templateData["meta"].(map[string]interface{})["fields"]
|
if _, ok := templateData["meta"]; ok {
|
||||||
f := edited["fields"].(map[string]interface{})
|
mf := templateData["meta"].(map[string]interface{})["fields"]
|
||||||
for k, _ := range f {
|
f := edited["fields"].(map[string]interface{})
|
||||||
if _, ok := mf.(map[string]interface{})[k]; !ok {
|
for k, _ := range f {
|
||||||
err := fmt.Errorf("Field %s is not editable", k)
|
if _, ok := mf.(map[string]interface{})[k]; !ok {
|
||||||
log.Error("%s", err)
|
err := fmt.Errorf("Field %s is not editable", k)
|
||||||
if promptYN("edit again?", true) {
|
log.Error("%s", err)
|
||||||
continue
|
if promptYN("edit again?", true) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+43
-2
@@ -312,7 +312,7 @@ func (c *Cli) CmdDups(duplicate string, issue string) error {
|
|||||||
|
|
||||||
|
|
||||||
func (c *Cli) CmdWatch(issue string, watcher string) error {
|
func (c *Cli) CmdWatch(issue string, watcher string) error {
|
||||||
log.Debug("dups called")
|
log.Debug("watch called")
|
||||||
|
|
||||||
json, err := jsonEncode(watcher); if err != nil {
|
json, err := jsonEncode(watcher); if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -335,6 +335,7 @@ func (c *Cli) CmdWatch(issue string, watcher string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cli) CmdTransition(issue string, trans string) error {
|
func (c *Cli) CmdTransition(issue string, trans string) error {
|
||||||
|
log.Debug("transition called")
|
||||||
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/transitions", c.endpoint, issue)
|
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/transitions", c.endpoint, issue)
|
||||||
data, err := responseToJson(c.get(uri)); if err != nil {
|
data, err := responseToJson(c.get(uri)); if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -342,7 +343,7 @@ func (c *Cli) CmdTransition(issue string, trans string) error {
|
|||||||
|
|
||||||
transitions := data.(map[string]interface{})["transitions"].([]interface{})
|
transitions := data.(map[string]interface{})["transitions"].([]interface{})
|
||||||
var transId string
|
var transId string
|
||||||
found := make([]string, len(transitions))
|
found := make([]string, 0, len(transitions))
|
||||||
for _, transition := range transitions {
|
for _, transition := range transitions {
|
||||||
name := transition.(map[string]interface{})["name"].(string)
|
name := transition.(map[string]interface{})["name"].(string)
|
||||||
id := transition.(map[string]interface{})["id"].(string)
|
id := transition.(map[string]interface{})["id"].(string)
|
||||||
@@ -395,3 +396,43 @@ func (c *Cli) CmdTransition(issue string, trans string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Cli) CmdComment(issue string) error {
|
||||||
|
log.Debug("comment called")
|
||||||
|
|
||||||
|
handlePost := func(json string) error {
|
||||||
|
log.Debug("JSON: %s", json)
|
||||||
|
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/comment", c.endpoint, issue)
|
||||||
|
resp, err := c.post(uri, json); if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode == 201 {
|
||||||
|
fmt.Printf("OK %s %s/browse/%s\n", issue, c.endpoint, issue)
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
logBuffer := bytes.NewBuffer(make([]byte,0))
|
||||||
|
resp.Write(logBuffer)
|
||||||
|
err := fmt.Errorf("Unexpected Response From PUT")
|
||||||
|
log.Error("%s:\n%s", err, logBuffer)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if comment, ok := c.opts["comment"]; ok {
|
||||||
|
json, err := jsonEncode(map[string]interface{}{
|
||||||
|
"body": comment,
|
||||||
|
}); if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return handlePost(json)
|
||||||
|
} else {
|
||||||
|
return c.editTemplate(
|
||||||
|
c.getTemplate(".jira.d/templates/comment", default_comment_template),
|
||||||
|
fmt.Sprintf("%s-create-", issue),
|
||||||
|
map[string]interface{}{},
|
||||||
|
handlePost,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -71,3 +71,7 @@ const default_create_template = `fields:
|
|||||||
customfield_10110:
|
customfield_10110:
|
||||||
- name:
|
- name:
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const default_comment_template = `body: |
|
||||||
|
|
||||||
|
`
|
||||||
|
|||||||
+3
-2
@@ -41,9 +41,8 @@ Usage:
|
|||||||
jira [-v ...] [-u USER] [-e URI] reopen ISSUE [-m COMMENT]
|
jira [-v ...] [-u USER] [-e URI] reopen ISSUE [-m COMMENT]
|
||||||
jira [-v ...] [-u USER] [-e URI] start ISSUE [-m COMMENT]
|
jira [-v ...] [-u USER] [-e URI] start ISSUE [-m COMMENT]
|
||||||
jira [-v ...] [-u USER] [-e URI] stop ISSUE [-m COMMENT]
|
jira [-v ...] [-u USER] [-e URI] stop ISSUE [-m COMMENT]
|
||||||
|
jira [-v ...] [-u USER] [-e URI] [-t FILE] comment ISSUE [-m COMMENT]
|
||||||
|
|
||||||
|
|
||||||
jira TODO [-v ...] [-u USER] [-e URI] comment ISSUE [-m COMMENT]
|
|
||||||
jira TODO [-v ...] [-u USER] [-e URI] take ISSUE
|
jira TODO [-v ...] [-u USER] [-e URI] take ISSUE
|
||||||
jira TODO [-v ...] [-u USER] [-e URI] assign ISSUE ASSIGNEE
|
jira TODO [-v ...] [-u USER] [-e URI] assign ISSUE ASSIGNEE
|
||||||
|
|
||||||
@@ -215,6 +214,8 @@ Transition Options:
|
|||||||
err = c.CmdTransition(args["ISSUE"].(string), "start")
|
err = c.CmdTransition(args["ISSUE"].(string), "start")
|
||||||
} else if validCommand("stop") {
|
} else if validCommand("stop") {
|
||||||
err = c.CmdTransition(args["ISSUE"].(string), "stop")
|
err = c.CmdTransition(args["ISSUE"].(string), "stop")
|
||||||
|
} else if validCommand("comment") {
|
||||||
|
err = c.CmdComment(args["ISSUE"].(string))
|
||||||
} else if val, ok := args["ISSUE"]; ok {
|
} else if val, ok := args["ISSUE"]; ok {
|
||||||
err = c.CmdView(val.(string))
|
err = c.CmdView(val.(string))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user