Repository: go-gitea/gitea
File: routers/api/v1/utils/hook.go (Go)

Code before:
	hookEvents[webhook_module.HookEventPackage] = util.SliceContainsString(events, string(webhook_module.HookEventPackage), true)
	hookEvents[webhook_module.HookEventStatus] = util.SliceContainsString(events, string(webhook_module.HookEventStatus), true)
	hookEvents[webhook_module.HookEventWorkflowJob] = util.SliceContainsString(events, string(webhook_module.HookEventWorkflowJob), true)

	// Issues
	hookEvents[webhook_module.HookEventIssues] = issuesHook(events, "issues_only")
	hookEvents[webhook_module.HookEventIssueAssign] = issuesHook(events, string(webhook_module.HookEventIssueAssign))
	hookEvents[webhook_module.HookEventIssueLabel] = issuesHook(events, string(webhook_module.HookEventIssueLabel))
	hookEvents[webhook_module.HookEventIssueMilestone] = issuesHook(events, string(webhook_module.HookEventIssueMilestone))
	hookEvents[webhook_module.HookEventIssueComment] = issuesHook(events, string(webhook_module.HookEventIssueComment))

	// Pull requests
	hookEvents[webhook_module.HookEventPullRequest] = pullHook(events, "pull_request_only")
	hookEvents[webhook_module.HookEventPullRequestAssign] = pullHook(events, string(webhook_module.HookEventPullRequestAssign))
	hookEvents[webhook_module.HookEventPullRequestLabel] = pullHook(events, string(webhook_module.HookEventPullRequestLabel))
	hookEvents[webhook_module.HookEventPullRequestMilestone] = pullHook(events, string(webhook_module.HookEventPullRequestMilestone))
	hookEvents[webhook_module.HookEventPullRequestComment] = pullHook(events, string(webhook_module.HookEventPullRequestComment))
	hookEvents[webhook_module.HookEventPullRequestReview] = pullHook(events, "pull_request_review")
	hookEvents[webhook_module.HookEventPullRequestReviewRequest] = pullHook(events, string(webhook_module.HookEventPullRequestReviewRequest))
	hookEvents[webhook_module.HookEventPullRequestSync] = pullHook(events, string(webhook_module.HookEventPullRequestSync))
	return hookEvents
}

// addHook add the hook specified by `form`, `ownerID` and `repoID`. If there is
// an error, write to `ctx` accordingly. Return (webhook, ok)
func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoID int64) (*webhook.Webhook, bool) {
	var isSystemWebhook bool
	if !checkCreateHookOption(ctx, form) {
		return nil, false
	}

	if form.Config["is_system_webhook"] != "" {
		sw, err := strconv.ParseBool(form.Config["is_system_webhook"])
		if err != nil {
			ctx.APIError(http.StatusUnprocessableEntity, "Invalid is_system_webhook value")
			return nil, false
		}
		isSystemWebhook = sw
	}
	w := &webhook.Webhook{
		OwnerID:         ownerID,
		RepoID:          repoID,
		URL:             form.Config["url"],
		ContentType:     webhook.ToHookContentType(form.Config["content_type"]),
		Secret:          form.Config["secret"],
		HTTPMethod:      "POST",
		IsSystemWebhook: isSystemWebhook,
		HookEvent: &webhook_module.HookEvent{
			ChooseEvents: true,
			HookEvents:   updateHookEvents(form.Events),
			BranchFilter: form.BranchFilter,

Review comment (suggestion):
You can decide, we can use the code from addwebhook as well, different style but similar

```suggestion
	return webhook_module.HookEvents{
		webhook_module.HookEventCreate:                   util.SliceContainsString(events, string(webhook_module.HookEventCreate), true),
		webhook_module.HookEventDelete:                   util.SliceContainsString(events, string(webhook_module.HookEventDelete), true),
		webhook_module.HookEventFork:                     util.SliceContainsString(events, string(webhook_module.HookEventFork), true),
		webhook_module.HookEventIssues:                   issuesHook(events, "issues_only"),
		webhook_module.HookEventIssueAssign:              issuesHook(events, string(webhook_module.HookEventIssueAssign)),
		webhook_module.HookEventIssueLabel:               issuesHook(events, string(webhook_module.HookEventIssueLabel)),
		webhook_module.HookEventIssueMilestone:           issuesHook(events, string(webhook_module.HookEventIssueMilestone)),
		webhook_module.HookEventIssueComment:             issuesHook(events, string(webhook_module.HookEventIssueComment)),
		webhook_module.HookEventPush:                     util.SliceContainsString(events, string(webhook_module.HookEventPush), true),
		webhook_module.HookEventPullRequest:              pullHook(events, "pull_request_only"),
		webhook_module.HookEventPullRequestAssign:        pullHook(events, string(webhook_module.HookEventPullRequestAssign)),
		webhook_module.HookEventPullRequestLabel:         pullHook(events, string(webhook_module.HookEventPullRequestLabel)),
		webhook_module.HookEventPullRequestMilestone:     pullHook(events, string(webhook_module.HookEventPullRequestMilestone)),
		webhook_module.HookEventPullRequestComment:       pullHook(events, string(webhook_module.HookEventPullRequestComment)),
		webhook_module.HookEventPullRequestReview:        pullHook(events, "pull_request_review"),
		webhook_module.HookEventPullRequestReviewRequest: pullHook(events, string(webhook_module.HookEventPullRequestReviewRequest)),
		webhook_module.HookEventPullRequestSync:          pullHook(events, string(webhook_module.HookEventPullRequestSync)),
		webhook_module.HookEventWiki:                     util.SliceContainsString(events, string(webhook_module.HookEventWiki), true),
		webhook_module.HookEventRepository:               util.SliceContainsString(events, string(webhook_module.HookEventRepository), true),
		webhook_module.HookEventRelease:                  util.SliceContainsString(events, string(webhook_module.HookEventRelease), true),
		webhook_module.HookEventPackage:                  util.SliceContainsString(events, string(webhook_module.HookEventPackage), true),
		webhook_module.HookEventStatus:                   util.SliceContainsString(events, string(webhook_module.HookEventStatus), true),
		webhook_module.HookEventWorkflowJob:              util.SliceContainsString(events, string(webhook_module.HookEventWorkflowJob), true),
	}
```

Code after:
	hookEvents[webhook_module.HookEventDelete] = util.SliceContainsString(events, string(webhook_module.HookEventDelete), true)
	hookEvents[webhook_module.HookEventFork] = util.SliceContainsString(events, string(webhook_module.HookEventFork), true)
	hookEvents[webhook_module.HookEventRepository] = util.SliceContainsString(events, string(webhook_module.HookEventRepository), true)
	hookEvents[webhook_module.HookEventWiki] = util.SliceContainsString(events, string(webhook_module.HookEventWiki), true)
	hookEvents[webhook_module.HookEventRelease] = util.SliceContainsString(events, string(webhook_module.HookEventRelease), true)
	hookEvents[webhook_module.HookEventPackage] = util.SliceContainsString(events, string(webhook_module.HookEventPackage), true)
	hookEvents[webhook_module.HookEventStatus] = util.SliceContainsString(events, string(webhook_module.HookEventStatus), true)
	hookEvents[webhook_module.HookEventWorkflowJob] = util.SliceContainsString(events, string(webhook_module.HookEventWorkflowJob), true)

	// Issues
	hookEvents[webhook_module.HookEventIssues] = issuesHook(events, "issues_only")
	hookEvents[webhook_module.HookEventIssueAssign] = issuesHook(events, string(webhook_module.HookEventIssueAssign))
	hookEvents[webhook_module.HookEventIssueLabel] = issuesHook(events, string(webhook_module.HookEventIssueLabel))
	hookEvents[webhook_module.HookEventIssueMilestone] = issuesHook(events, string(webhook_module.HookEventIssueMilestone))
	hookEvents[webhook_module.HookEventIssueComment] = issuesHook(events, string(webhook_module.HookEventIssueComment))

	// Pull requests
	hookEvents[webhook_module.HookEventPullRequest] = pullHook(events, "pull_request_only")
	hookEvents[webhook_module.HookEventPullRequestAssign] = pullHook(events, string(webhook_module.HookEventPullRequestAssign))
	hookEvents[webhook_module.HookEventPullRequestLabel] = pullHook(events, string(webhook_module.HookEventPullRequestLabel))
	hookEvents[webhook_module.HookEventPullRequestMilestone] = pullHook(events, string(webhook_module.HookEventPullRequestMilestone))
	hookEvents[webhook_module.HookEventPullRequestComment] = pullHook(events, string(webhook_module.HookEventPullRequestComment))
	hookEvents[webhook_module.HookEventPullRequestReview] = pullHook(events, "pull_request_review")
	hookEvents[webhook_module.HookEventPullRequestReviewRequest] = pullHook(events, string(webhook_module.HookEventPullRequestReviewRequest))
	hookEvents[webhook_module.HookEventPullRequestSync] = pullHook(events, string(webhook_module.HookEventPullRequestSync))
	return hookEvents
}

// addHook add the hook specified by `form`, `ownerID` and `repoID`. If there is
// an error, write to `ctx` accordingly. Return (webhook, ok)
func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoID int64) (*webhook.Webhook, bool) {
	var isSystemWebhook bool
	if !checkCreateHookOption(ctx, form) {
		return nil, false
	}

	if form.Config["is_system_webhook"] != "" {
		sw, err := strconv.ParseBool(form.Config["is_system_webhook"])
		if err != nil {
			ctx.APIError(http.StatusUnprocessableEntity, "Invalid is_system_webhook value")
			return nil, false
		}
		isSystemWebhook = sw
	}
	w := &webhook.Webhook{
		OwnerID:         ownerID,
		RepoID:          repoID,
		URL:             form.Config["url"],
		ContentType:     webhook.ToHookContentType(form.Config["content_type"]),
		Secret:          form.Config["secret"],
		HTTPMethod:      "POST",