From add0f35a117bf1d1d5311931597384de6a1dba9e Mon Sep 17 00:00:00 2001 From: KensoDev Date: Fri, 2 Jun 2017 22:34:33 -0700 Subject: [PATCH] Gong comment is implemented --- README.md | 6 +++--- cmd/gong/main.go | 42 ++++++++++++++++++++++++++++++++++++++++++ issue_details.go | 9 +++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 70e6bfc..7c3c43d 100644 --- a/README.md +++ b/README.md @@ -51,15 +51,15 @@ While working on a branch that matches the gong regular expression (look above), you can type `gong browse` and it will open up a browser opened on the issue automatically. -## Upcoming features - -### gong comment +### `gong comment` While working on a branch that matches the gong regular expression, you can type `gong comment "some comment"` and it will send a comment on the ticket. This is a perfect way to streamline communication +## Upcoming features + ### gong slack Send a message to a slack channel, tagging the issue you are working on diff --git a/cmd/gong/main.go b/cmd/gong/main.go index 9c5a5fb..cdcffaf 100644 --- a/cmd/gong/main.go +++ b/cmd/gong/main.go @@ -126,6 +126,48 @@ func main() { return nil }, }, + + { + Name: "comment", + Usage: "Comment on the issue you are working on, accepts an argument or STDIN", + Action: func(c *cli.Context) error { + comment := c.Args()[0] + + cmd := "git" + args := []string{"rev-parse", "--abbrev-ref", "HEAD"} + + out, err := exec.Command(cmd, args...).Output() + + if err != nil { + return err + } + + branchName := string(out) + + issueID, err := gong.GetIssueID(branchName) + + if err != nil { + return err + } + + jiraClient, err := gong.GetAuthenticatedClient() + if err != nil { + fmt.Println(err) + return err + } + + err = gong.AddComment(jiraClient, issueID, comment) + + if err != nil { + fmt.Println(err) + return err + } + + fmt.Println("Comment added to the jira ticket") + + return nil + }, + }, } app.Run(os.Args) } diff --git a/issue_details.go b/issue_details.go index 15d0007..649f1fe 100644 --- a/issue_details.go +++ b/issue_details.go @@ -18,6 +18,15 @@ func GetIssueID(branchName string) (string, error) { return matches[0], nil } +func AddComment(jiraClient *jira.Client, issueID string, commentBody string) error { + comment := &jira.Comment{ + Body: commentBody, + } + _, _, err := jiraClient.Issue.AddComment(issueID, comment) + + return err +} + func GetBranchName(jiraClient *jira.Client, issueId string, issueType string) string { issue, _, _ := jiraClient.Issue.Get(issueId, nil)