github: add issue events

This commit is contained in:
Chris Sexton 2020-11-08 11:52:52 -05:00 committed by Chris Sexton
parent 3e8a474f13
commit 910b28666b
1 changed files with 56 additions and 1 deletions

View File

@ -22,6 +22,8 @@ func (p *GitPlugin) githubEvent(w http.ResponseWriter, r *http.Request) {
github.PushEvent, github.PushEvent,
github.PullRequestEvent, github.PullRequestEvent,
github.PingEvent, github.PingEvent,
github.IssuesEvent,
github.IssueCommentEvent,
) )
if err != nil { if err != nil {
log.Error().Err(err).Msg("unknown event") log.Error().Err(err).Msg("unknown event")
@ -77,7 +79,60 @@ func (p *GitPlugin) githubEvent(w http.ResponseWriter, r *http.Request) {
ping := payload.(github.PingPayload) ping := payload.(github.PingPayload)
repo = ping.Repository.Name repo = ping.Repository.Name
owner = ping.Repository.Owner.Login owner = ping.Repository.Owner.Login
msg += fmt.Sprintf(icon+" Got a ping request on %s", repo) msg += fmt.Sprintf("%s Got a ping request on %s", icon, repo)
case github.IssueCommentPayload:
cmt := payload.(github.IssueCommentPayload)
commentEvents := p.c.GetMap("github.commentevents", map[string]string{
"created": "commented",
"deleted": "removed their comment",
})
action := cmt.Action
for k, v := range commentEvents {
if cmt.Action == k {
action = v
goto sendCommentEvent
}
}
log.Debug().Msgf("Unknown issue comment event: %s", cmt.Action)
return
sendCommentEvent:
repo = cmt.Repository.Name
owner = cmt.Comment.User.Login
msg += fmt.Sprintf("%s %s %s on <%s|%s #%d>",
icon,
owner,
action,
cmt.Issue.URL,
cmt.Issue.Title,
cmt.Issue.Number,
)
case github.IssuesPayload:
issueEvent := payload.(github.IssuesPayload)
issueEvents := p.c.GetMap("github.issueevents", map[string]string{
"opened": "opened",
"reopened": "reopened",
"closed": "closed",
})
action := issueEvent.Action
for k, v := range issueEvents {
if issueEvent.Action == k {
action = v
goto sendIssueEvent
}
}
log.Debug().Msgf("Unknown issue event: %s", issueEvent.Action)
return
sendIssueEvent:
repo = issueEvent.Repository.Name
owner = issueEvent.Sender.Login
msg += fmt.Sprintf("%s %s %s issue <%s|%s #%d>",
icon,
owner,
action,
issueEvent.Issue.URL,
issueEvent.Issue.Title,
issueEvent.Issue.Number,
)
default: default:
log.Error().Interface("payload", payload).Msg("unknown event payload") log.Error().Interface("payload", payload).Msg("unknown event payload")
w.WriteHeader(500) w.WriteHeader(500)