mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-03 21:08:25 +00:00 
			
		
		
		
	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>
This commit is contained in:
		@@ -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,
 | 
			
		||||
		},
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user