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 /routers | |
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 'routers')
-rw-r--r-- | routers/api/v1/utils/hook.go | 35 | ||||
-rw-r--r-- | routers/repo/webhook.go | 27 |
2 files changed, 44 insertions, 18 deletions
diff --git a/routers/api/v1/utils/hook.go b/routers/api/v1/utils/hook.go index 9a6733f9dc..eb2371c50b 100644 --- a/routers/api/v1/utils/hook.go +++ b/routers/api/v1/utils/hook.go @@ -87,6 +87,14 @@ func AddRepoHook(ctx *context.APIContext, form *api.CreateHookOption) { } } +func issuesHook(events []string, event string) bool { + return com.IsSliceContainsStr(events, event) || com.IsSliceContainsStr(events, string(models.HookEventIssues)) +} + +func pullHook(events []string, event string) bool { + return com.IsSliceContainsStr(events, event) || com.IsSliceContainsStr(events, string(models.HookEventPullRequest)) +} + // addHook add the hook specified by `form`, `orgID` and `repoID`. If there is // an error, write to `ctx` accordingly. Return (webhook, ok) func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID int64) (*models.Webhook, bool) { @@ -103,15 +111,24 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID HookEvent: &models.HookEvent{ ChooseEvents: true, HookEvents: models.HookEvents{ - Create: com.IsSliceContainsStr(form.Events, string(models.HookEventCreate)), - Delete: com.IsSliceContainsStr(form.Events, string(models.HookEventDelete)), - Fork: com.IsSliceContainsStr(form.Events, string(models.HookEventFork)), - Issues: com.IsSliceContainsStr(form.Events, string(models.HookEventIssues)), - IssueComment: com.IsSliceContainsStr(form.Events, string(models.HookEventIssueComment)), - Push: com.IsSliceContainsStr(form.Events, string(models.HookEventPush)), - PullRequest: com.IsSliceContainsStr(form.Events, string(models.HookEventPullRequest)), - Repository: com.IsSliceContainsStr(form.Events, string(models.HookEventRepository)), - Release: com.IsSliceContainsStr(form.Events, string(models.HookEventRelease)), + Create: com.IsSliceContainsStr(form.Events, string(models.HookEventCreate)), + Delete: com.IsSliceContainsStr(form.Events, string(models.HookEventDelete)), + Fork: com.IsSliceContainsStr(form.Events, string(models.HookEventFork)), + Issues: issuesHook(form.Events, "issues_only"), + IssueAssign: issuesHook(form.Events, string(models.HookEventIssueAssign)), + IssueLabel: issuesHook(form.Events, string(models.HookEventIssueLabel)), + IssueMilestone: issuesHook(form.Events, string(models.HookEventIssueMilestone)), + IssueComment: issuesHook(form.Events, string(models.HookEventIssueComment)), + Push: com.IsSliceContainsStr(form.Events, string(models.HookEventPush)), + PullRequest: pullHook(form.Events, "pull_request_only"), + PullRequestAssign: pullHook(form.Events, string(models.HookEventPullRequestAssign)), + PullRequestLabel: pullHook(form.Events, string(models.HookEventPullRequestLabel)), + PullRequestMilestone: pullHook(form.Events, string(models.HookEventPullRequestMilestone)), + PullRequestComment: pullHook(form.Events, string(models.HookEventPullRequestComment)), + PullRequestReview: pullHook(form.Events, "pull_request_review"), + PullRequestSync: pullHook(form.Events, string(models.HookEventPullRequestSync)), + Repository: com.IsSliceContainsStr(form.Events, string(models.HookEventRepository)), + Release: com.IsSliceContainsStr(form.Events, string(models.HookEventRelease)), }, BranchFilter: form.BranchFilter, }, diff --git a/routers/repo/webhook.go b/routers/repo/webhook.go index 8454989679..cf6ff27542 100644 --- a/routers/repo/webhook.go +++ b/routers/repo/webhook.go @@ -136,15 +136,24 @@ func ParseHookEvent(form auth.WebhookForm) *models.HookEvent { SendEverything: form.SendEverything(), ChooseEvents: form.ChooseEvents(), HookEvents: models.HookEvents{ - Create: form.Create, - Delete: form.Delete, - Fork: form.Fork, - Issues: form.Issues, - IssueComment: form.IssueComment, - Release: form.Release, - Push: form.Push, - PullRequest: form.PullRequest, - Repository: form.Repository, + Create: form.Create, + Delete: form.Delete, + Fork: form.Fork, + Issues: form.Issues, + IssueAssign: form.IssueAssign, + IssueLabel: form.IssueLabel, + IssueMilestone: form.IssueMilestone, + IssueComment: form.IssueComment, + Release: form.Release, + Push: form.Push, + PullRequest: form.PullRequest, + PullRequestAssign: form.PullRequestAssign, + PullRequestLabel: form.PullRequestLabel, + PullRequestMilestone: form.PullRequestMilestone, + PullRequestComment: form.PullRequestComment, + PullRequestReview: form.PullRequestReview, + PullRequestSync: form.PullRequestSync, + Repository: form.Repository, }, BranchFilter: form.BranchFilter, } |