From 70b1d856053990064ea210da562647ea61b3deab Mon Sep 17 00:00:00 2001 From: A_D Date: Sat, 17 Nov 2018 16:32:22 +0200 Subject: [PATCH] added handling for issue comments --- webhooks-structs.go | 22 +++++++++++++++++----- webhooks.go | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/webhooks-structs.go b/webhooks-structs.go index ed6a833..9f8bc44 100644 --- a/webhooks-structs.go +++ b/webhooks-structs.go @@ -78,6 +78,17 @@ type Issue struct { PullRequest string `json:"pull_request"` } +type IssueComment struct { + Id float64 `json:"id"` + HtmlUrl string `json:"html_url"` + PullRequestUrl string `json:"pull_request_url"` + IssueUrl string `json:"issue_url"` + User RepoUser `json:"user"` + Body string `json:"body"` + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` +} + type BaseWebHook struct { Secret string `json:"secret"` } @@ -96,9 +107,10 @@ type Push struct { type IssueAction struct { BaseWebHook - Action string `json:"action"` - Number float64 `json:"number"` - Issue Issue `json:"issue"` - Repository Repository `json:"repository"` - Sender RepoUser `json:"sender"` + Action string `json:"action"` + Number float64 `json:"number"` + Issue Issue `json:"issue"` + Repository Repository `json:"repository"` + Sender RepoUser `json:"sender"` + Comment IssueComment `json:"comment"` } diff --git a/webhooks.go b/webhooks.go index 18c0b80..c41f39d 100644 --- a/webhooks.go +++ b/webhooks.go @@ -42,6 +42,9 @@ func handleWebHook(writer http.ResponseWriter, request *http.Request) { case "issues": handleIssueAction(data) + case "issue_comment": + handleIssueComment(data) + } } @@ -96,3 +99,21 @@ func handleIssueAction(data []byte) { action.Issue.Title, ) } + +func handleIssueComment(data []byte) { + action := IssueAction{} + json.Unmarshal(data, &action) + printSep() + fmt.Printf( + "%q (%q) performed the comment action %q on repo %q and issue %q\n", + action.Sender.Login, + action.Sender.Email, + action.Action, + action.Repository.FullName, + action.Issue.Title, + ) + + fmt.Printf(INDENT + "---") + msg := strings.Replace(action.Comment.Body, "\n", strings.Repeat(INDENT, 2), -1) + fmt.Printf(strings.Repeat(INDENT, 2) + msg) +}