diff options
author | John Olheiser <john.olheiser@gmail.com> | 2020-03-05 23:10:48 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-06 07:10:48 +0200 |
commit | 3f1c0841cb9fc61136b85c6b39613679d2851707 (patch) | |
tree | d0b15f3b809891d83f41fed5ab7378765330525a /modules/webhook | |
parent | 80db44267ccb688c596e8375523af5cd92864d87 (diff) | |
download | gitea-3f1c0841cb9fc61136b85c6b39613679d2851707.tar.gz gitea-3f1c0841cb9fc61136b85c6b39613679d2851707.zip |
Granular webhook events (#9626)
* Initial work
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Add PR reviews and API coverage
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Split up events
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Add migration and locale
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Format
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Revert IsPull
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Fix comments
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Fix tests
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Fix PR reviews
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Fix issue_comment
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Make fmt
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Migrations
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Backwards compatible API
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Fix feishu
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Move session commit
Signed-off-by: jolheiser <john.olheiser@gmail.com>
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Diffstat (limited to 'modules/webhook')
-rw-r--r-- | modules/webhook/deliver.go | 6 | ||||
-rw-r--r-- | modules/webhook/dingtalk.go | 11 | ||||
-rw-r--r-- | modules/webhook/discord.go | 19 | ||||
-rw-r--r-- | modules/webhook/feishu.go | 2 | ||||
-rw-r--r-- | modules/webhook/msteams.go | 15 | ||||
-rw-r--r-- | modules/webhook/slack.go | 11 | ||||
-rw-r--r-- | modules/webhook/telegram.go | 11 |
7 files changed, 40 insertions, 35 deletions
diff --git a/modules/webhook/deliver.go b/modules/webhook/deliver.go index 9f5c938f83..505d27a2de 100644 --- a/modules/webhook/deliver.go +++ b/modules/webhook/deliver.go @@ -74,13 +74,13 @@ func Deliver(t *models.HookTask) error { } req.Header.Add("X-Gitea-Delivery", t.UUID) - req.Header.Add("X-Gitea-Event", string(t.EventType)) + req.Header.Add("X-Gitea-Event", t.EventType.Event()) req.Header.Add("X-Gitea-Signature", t.Signature) req.Header.Add("X-Gogs-Delivery", t.UUID) - req.Header.Add("X-Gogs-Event", string(t.EventType)) + req.Header.Add("X-Gogs-Event", t.EventType.Event()) req.Header.Add("X-Gogs-Signature", t.Signature) req.Header["X-GitHub-Delivery"] = []string{t.UUID} - req.Header["X-GitHub-Event"] = []string{string(t.EventType)} + req.Header["X-GitHub-Event"] = []string{t.EventType.Event()} // Record delivery information. t.RequestInfo = &models.HookRequest{ diff --git a/modules/webhook/dingtalk.go b/modules/webhook/dingtalk.go index fc99202a70..f2dd5a79ed 100644 --- a/modules/webhook/dingtalk.go +++ b/modules/webhook/dingtalk.go @@ -181,7 +181,7 @@ func getDingtalkPullRequestPayload(p *api.PullRequestPayload) (*DingtalkPayload, func getDingtalkPullRequestApprovalPayload(p *api.PullRequestPayload, event models.HookEventType) (*DingtalkPayload, error) { var text, title string switch p.Action { - case api.HookIssueSynchronized: + case api.HookIssueReviewed: action, err := parseHookPullRequestEventType(event) if err != nil { return nil, err @@ -261,15 +261,16 @@ func GetDingtalkPayload(p api.Payloader, event models.HookEventType, meta string return getDingtalkDeletePayload(p.(*api.DeletePayload)) case models.HookEventFork: return getDingtalkForkPayload(p.(*api.ForkPayload)) - case models.HookEventIssues: + case models.HookEventIssues, models.HookEventIssueAssign, models.HookEventIssueLabel, models.HookEventIssueMilestone: return getDingtalkIssuesPayload(p.(*api.IssuePayload)) - case models.HookEventIssueComment: + case models.HookEventIssueComment, models.HookEventPullRequestComment: return getDingtalkIssueCommentPayload(p.(*api.IssueCommentPayload)) case models.HookEventPush: return getDingtalkPushPayload(p.(*api.PushPayload)) - case models.HookEventPullRequest: + case models.HookEventPullRequest, models.HookEventPullRequestAssign, models.HookEventPullRequestLabel, + models.HookEventPullRequestMilestone, models.HookEventPullRequestSync: return getDingtalkPullRequestPayload(p.(*api.PullRequestPayload)) - case models.HookEventPullRequestApproved, models.HookEventPullRequestRejected, models.HookEventPullRequestComment: + case models.HookEventPullRequestReviewApproved, models.HookEventPullRequestReviewRejected, models.HookEventPullRequestReviewComment: return getDingtalkPullRequestApprovalPayload(p.(*api.PullRequestPayload), event) case models.HookEventRepository: return getDingtalkRepositoryPayload(p.(*api.RepositoryPayload)) diff --git a/modules/webhook/discord.go b/modules/webhook/discord.go index 732821c183..e455a102bd 100644 --- a/modules/webhook/discord.go +++ b/modules/webhook/discord.go @@ -296,7 +296,7 @@ func getDiscordPullRequestApprovalPayload(p *api.PullRequestPayload, meta *Disco var text, title string var color int switch p.Action { - case api.HookIssueSynchronized: + case api.HookIssueReviewed: action, err := parseHookPullRequestEventType(event) if err != nil { return nil, err @@ -306,9 +306,9 @@ func getDiscordPullRequestApprovalPayload(p *api.PullRequestPayload, meta *Disco text = p.Review.Content switch event { - case models.HookEventPullRequestApproved: + case models.HookEventPullRequestReviewApproved: color = greenColor - case models.HookEventPullRequestRejected: + case models.HookEventPullRequestReviewRejected: color = redColor case models.HookEventPullRequestComment: color = greyColor @@ -405,15 +405,16 @@ func GetDiscordPayload(p api.Payloader, event models.HookEventType, meta string) return getDiscordDeletePayload(p.(*api.DeletePayload), discord) case models.HookEventFork: return getDiscordForkPayload(p.(*api.ForkPayload), discord) - case models.HookEventIssues: + case models.HookEventIssues, models.HookEventIssueAssign, models.HookEventIssueLabel, models.HookEventIssueMilestone: return getDiscordIssuesPayload(p.(*api.IssuePayload), discord) - case models.HookEventIssueComment: + case models.HookEventIssueComment, models.HookEventPullRequestComment: return getDiscordIssueCommentPayload(p.(*api.IssueCommentPayload), discord) case models.HookEventPush: return getDiscordPushPayload(p.(*api.PushPayload), discord) - case models.HookEventPullRequest: + case models.HookEventPullRequest, models.HookEventPullRequestAssign, models.HookEventPullRequestLabel, + models.HookEventPullRequestMilestone, models.HookEventPullRequestSync: return getDiscordPullRequestPayload(p.(*api.PullRequestPayload), discord) - case models.HookEventPullRequestRejected, models.HookEventPullRequestApproved, models.HookEventPullRequestComment: + case models.HookEventPullRequestReviewRejected, models.HookEventPullRequestReviewApproved, models.HookEventPullRequestReviewComment: return getDiscordPullRequestApprovalPayload(p.(*api.PullRequestPayload), discord, event) case models.HookEventRepository: return getDiscordRepositoryPayload(p.(*api.RepositoryPayload), discord) @@ -428,9 +429,9 @@ func parseHookPullRequestEventType(event models.HookEventType) (string, error) { switch event { - case models.HookEventPullRequestApproved: + case models.HookEventPullRequestReviewApproved: return "approved", nil - case models.HookEventPullRequestRejected: + case models.HookEventPullRequestReviewRejected: return "rejected", nil case models.HookEventPullRequestComment: return "comment", nil diff --git a/modules/webhook/feishu.go b/modules/webhook/feishu.go index 6af78494c9..57eb909c48 100644 --- a/modules/webhook/feishu.go +++ b/modules/webhook/feishu.go @@ -189,7 +189,7 @@ func GetFeishuPayload(p api.Payloader, event models.HookEventType, meta string) return getFeishuPushPayload(p.(*api.PushPayload)) case models.HookEventPullRequest: return getFeishuPullRequestPayload(p.(*api.PullRequestPayload)) - case models.HookEventPullRequestApproved, models.HookEventPullRequestRejected, models.HookEventPullRequestComment: + case models.HookEventPullRequestReviewApproved, models.HookEventPullRequestReviewRejected, models.HookEventPullRequestComment: return getFeishuPullRequestApprovalPayload(p.(*api.PullRequestPayload), event) case models.HookEventRepository: return getFeishuRepositoryPayload(p.(*api.RepositoryPayload)) diff --git a/modules/webhook/msteams.go b/modules/webhook/msteams.go index b9ceb5ee0b..a0925010d6 100644 --- a/modules/webhook/msteams.go +++ b/modules/webhook/msteams.go @@ -395,7 +395,7 @@ func getMSTeamsPullRequestApprovalPayload(p *api.PullRequestPayload, event model var text, title string var color int switch p.Action { - case api.HookIssueSynchronized: + case api.HookIssueReviewed: action, err := parseHookPullRequestEventType(event) if err != nil { return nil, err @@ -405,9 +405,9 @@ func getMSTeamsPullRequestApprovalPayload(p *api.PullRequestPayload, event model text = p.Review.Content switch event { - case models.HookEventPullRequestApproved: + case models.HookEventPullRequestReviewApproved: color = greenColor - case models.HookEventPullRequestRejected: + case models.HookEventPullRequestReviewRejected: color = redColor case models.HookEventPullRequestComment: color = greyColor @@ -555,15 +555,16 @@ func GetMSTeamsPayload(p api.Payloader, event models.HookEventType, meta string) return getMSTeamsDeletePayload(p.(*api.DeletePayload)) case models.HookEventFork: return getMSTeamsForkPayload(p.(*api.ForkPayload)) - case models.HookEventIssues: + case models.HookEventIssues, models.HookEventIssueAssign, models.HookEventIssueLabel, models.HookEventIssueMilestone: return getMSTeamsIssuesPayload(p.(*api.IssuePayload)) - case models.HookEventIssueComment: + case models.HookEventIssueComment, models.HookEventPullRequestComment: return getMSTeamsIssueCommentPayload(p.(*api.IssueCommentPayload)) case models.HookEventPush: return getMSTeamsPushPayload(p.(*api.PushPayload)) - case models.HookEventPullRequest: + case models.HookEventPullRequest, models.HookEventPullRequestAssign, models.HookEventPullRequestLabel, + models.HookEventPullRequestMilestone, models.HookEventPullRequestSync: return getMSTeamsPullRequestPayload(p.(*api.PullRequestPayload)) - case models.HookEventPullRequestRejected, models.HookEventPullRequestApproved, models.HookEventPullRequestComment: + case models.HookEventPullRequestReviewRejected, models.HookEventPullRequestReviewApproved, models.HookEventPullRequestReviewComment: return getMSTeamsPullRequestApprovalPayload(p.(*api.PullRequestPayload), event) case models.HookEventRepository: return getMSTeamsRepositoryPayload(p.(*api.RepositoryPayload)) diff --git a/modules/webhook/slack.go b/modules/webhook/slack.go index 361e15ece5..e3715ab00c 100644 --- a/modules/webhook/slack.go +++ b/modules/webhook/slack.go @@ -271,7 +271,7 @@ func getSlackPullRequestApprovalPayload(p *api.PullRequestPayload, slack *SlackM var text string switch p.Action { - case api.HookIssueSynchronized: + case api.HookIssueReviewed: action, err := parseHookPullRequestEventType(event) if err != nil { return nil, err @@ -324,15 +324,16 @@ func GetSlackPayload(p api.Payloader, event models.HookEventType, meta string) ( return getSlackDeletePayload(p.(*api.DeletePayload), slack) case models.HookEventFork: return getSlackForkPayload(p.(*api.ForkPayload), slack) - case models.HookEventIssues: + case models.HookEventIssues, models.HookEventIssueAssign, models.HookEventIssueLabel, models.HookEventIssueMilestone: return getSlackIssuesPayload(p.(*api.IssuePayload), slack) - case models.HookEventIssueComment: + case models.HookEventIssueComment, models.HookEventPullRequestComment: return getSlackIssueCommentPayload(p.(*api.IssueCommentPayload), slack) case models.HookEventPush: return getSlackPushPayload(p.(*api.PushPayload), slack) - case models.HookEventPullRequest: + case models.HookEventPullRequest, models.HookEventPullRequestAssign, models.HookEventPullRequestLabel, + models.HookEventPullRequestMilestone, models.HookEventPullRequestSync: return getSlackPullRequestPayload(p.(*api.PullRequestPayload), slack) - case models.HookEventPullRequestRejected, models.HookEventPullRequestApproved, models.HookEventPullRequestComment: + case models.HookEventPullRequestReviewRejected, models.HookEventPullRequestReviewApproved, models.HookEventPullRequestReviewComment: return getSlackPullRequestApprovalPayload(p.(*api.PullRequestPayload), slack, event) case models.HookEventRepository: return getSlackRepositoryPayload(p.(*api.RepositoryPayload), slack) diff --git a/modules/webhook/telegram.go b/modules/webhook/telegram.go index 47d54f7cb9..cf096e2c66 100644 --- a/modules/webhook/telegram.go +++ b/modules/webhook/telegram.go @@ -151,7 +151,7 @@ func getTelegramPullRequestPayload(p *api.PullRequestPayload) (*TelegramPayload, func getTelegramPullRequestApprovalPayload(p *api.PullRequestPayload, event models.HookEventType) (*TelegramPayload, error) { var text, attachmentText string switch p.Action { - case api.HookIssueSynchronized: + case api.HookIssueReviewed: action, err := parseHookPullRequestEventType(event) if err != nil { return nil, err @@ -203,15 +203,16 @@ func GetTelegramPayload(p api.Payloader, event models.HookEventType, meta string return getTelegramDeletePayload(p.(*api.DeletePayload)) case models.HookEventFork: return getTelegramForkPayload(p.(*api.ForkPayload)) - case models.HookEventIssues: + case models.HookEventIssues, models.HookEventIssueAssign, models.HookEventIssueLabel, models.HookEventIssueMilestone: return getTelegramIssuesPayload(p.(*api.IssuePayload)) - case models.HookEventIssueComment: + case models.HookEventIssueComment, models.HookEventPullRequestComment: return getTelegramIssueCommentPayload(p.(*api.IssueCommentPayload)) case models.HookEventPush: return getTelegramPushPayload(p.(*api.PushPayload)) - case models.HookEventPullRequest: + case models.HookEventPullRequest, models.HookEventPullRequestAssign, models.HookEventPullRequestLabel, + models.HookEventPullRequestMilestone, models.HookEventPullRequestSync: return getTelegramPullRequestPayload(p.(*api.PullRequestPayload)) - case models.HookEventPullRequestRejected, models.HookEventPullRequestApproved, models.HookEventPullRequestComment: + case models.HookEventPullRequestReviewRejected, models.HookEventPullRequestReviewApproved, models.HookEventPullRequestReviewComment: return getTelegramPullRequestApprovalPayload(p.(*api.PullRequestPayload), event) case models.HookEventRepository: return getTelegramRepositoryPayload(p.(*api.RepositoryPayload)) |