mirror of
https://github.com/Threnklyn/jira.git
synced 2026-06-07 13:33:32 +02:00
add comment command
This commit is contained in:
@@ -91,6 +91,10 @@ func main() {
|
|||||||
Command: "edit",
|
Command: "edit",
|
||||||
Entry: cli.CmdEditRegistry(),
|
Entry: cli.CmdEditRegistry(),
|
||||||
},
|
},
|
||||||
|
jiracli.CommandRegistry{
|
||||||
|
Command: "comment",
|
||||||
|
Entry: cli.CmdCommentRegistry(),
|
||||||
|
},
|
||||||
jiracli.CommandRegistry{
|
jiracli.CommandRegistry{
|
||||||
Command: "worklog list",
|
Command: "worklog list",
|
||||||
Entry: cli.CmdWorklogListRegistry(),
|
Entry: cli.CmdWorklogListRegistry(),
|
||||||
|
|||||||
@@ -399,3 +399,28 @@ func (j *Jira) IssueRemoveWatcher(issue, user string) error {
|
|||||||
}
|
}
|
||||||
return responseError(resp)
|
return responseError(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CommentProvider interface {
|
||||||
|
ProvideComment() *jiradata.Comment
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://docs.atlassian.com/jira/REST/cloud/#api/2/issue/{issueIdOrKey}/comment-addComment
|
||||||
|
func (j *Jira) IssueAddComment(issue string, cp CommentProvider) (*jiradata.Comment, error) {
|
||||||
|
req := cp.ProvideComment()
|
||||||
|
encoded, err := json.Marshal(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/comment", j.Endpoint, issue)
|
||||||
|
resp, err := j.UA.Post(uri, "application/json", bytes.NewBuffer(encoded))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode == 201 {
|
||||||
|
results := jiradata.Comment{}
|
||||||
|
return &results, readJSON(resp.Body, &results)
|
||||||
|
}
|
||||||
|
return nil, responseError(resp)
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package jiracli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
||||||
|
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CommentOptions struct {
|
||||||
|
GlobalOptions
|
||||||
|
Overrides map[string]string
|
||||||
|
Issue string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (jc *JiraCli) CmdCommentRegistry() *CommandRegistryEntry {
|
||||||
|
opts := CommentOptions{
|
||||||
|
GlobalOptions: GlobalOptions{
|
||||||
|
Template: "comment",
|
||||||
|
},
|
||||||
|
Overrides: map[string]string{},
|
||||||
|
}
|
||||||
|
|
||||||
|
return &CommandRegistryEntry{
|
||||||
|
"Add comment to issue",
|
||||||
|
func() error {
|
||||||
|
return jc.CmdComment(&opts)
|
||||||
|
},
|
||||||
|
func(cmd *kingpin.CmdClause) error {
|
||||||
|
return jc.CmdCommentUsage(cmd, &opts)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (jc *JiraCli) CmdCommentUsage(cmd *kingpin.CmdClause, opts *CommentOptions) error {
|
||||||
|
if err := jc.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
jc.EditorUsage(cmd, &opts.GlobalOptions)
|
||||||
|
jc.TemplateUsage(cmd, &opts.GlobalOptions)
|
||||||
|
cmd.Flag("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
|
||||||
|
opts.Overrides["comment"] = flagValue(ctx, "comment")
|
||||||
|
return nil
|
||||||
|
}).String()
|
||||||
|
cmd.Arg("ISSUE", "issue id to update").StringVar(&opts.Issue)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CmdComment will update issue with comment
|
||||||
|
func (jc *JiraCli) CmdComment(opts *CommentOptions) error {
|
||||||
|
comment := jiradata.Comment{}
|
||||||
|
input := struct {
|
||||||
|
Overrides map[string]string
|
||||||
|
}{
|
||||||
|
opts.Overrides,
|
||||||
|
}
|
||||||
|
err := jc.editLoop(&opts.GlobalOptions, &input, &comment, func() error {
|
||||||
|
_, err := jc.IssueAddComment(opts.Issue, &comment)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, jc.Endpoint, opts.Issue)
|
||||||
|
|
||||||
|
// FIXME implement browse
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -17,3 +17,7 @@ func (l *LinkIssueRequest) ProvideLinkIssueRequest() *LinkIssueRequest {
|
|||||||
func (r *RankRequest) ProvideRankRequest() *RankRequest {
|
func (r *RankRequest) ProvideRankRequest() *RankRequest {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Comment) ProvideComment() *Comment {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user