added handling for issue comments

This commit is contained in:
A_D 2018-11-17 16:32:22 +02:00
parent 931fb26dbc
commit 70b1d85605
No known key found for this signature in database
GPG Key ID: C242F3DD220FA945
2 changed files with 38 additions and 5 deletions

View File

@ -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"`
}

View File

@ -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)
}