mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 08:54:23 +01:00
parent
f74293f9c2
commit
3dbd2d942b
2 changed files with 35 additions and 98 deletions
|
@ -24,69 +24,6 @@ import (
|
|||
// \___|_ / \____/ \____/|__|_ \ |____| (____ /____ >__|_ \
|
||||
// \/ \/ \/ \/ \/
|
||||
|
||||
// HookEventType is the type of an hook event
|
||||
type HookEventType string
|
||||
|
||||
// Types of hook events
|
||||
const (
|
||||
HookEventCreate HookEventType = "create"
|
||||
HookEventDelete HookEventType = "delete"
|
||||
HookEventFork HookEventType = "fork"
|
||||
HookEventPush HookEventType = "push"
|
||||
HookEventIssues HookEventType = "issues"
|
||||
HookEventIssueAssign HookEventType = "issue_assign"
|
||||
HookEventIssueLabel HookEventType = "issue_label"
|
||||
HookEventIssueMilestone HookEventType = "issue_milestone"
|
||||
HookEventIssueComment HookEventType = "issue_comment"
|
||||
HookEventPullRequest HookEventType = "pull_request"
|
||||
HookEventPullRequestAssign HookEventType = "pull_request_assign"
|
||||
HookEventPullRequestLabel HookEventType = "pull_request_label"
|
||||
HookEventPullRequestMilestone HookEventType = "pull_request_milestone"
|
||||
HookEventPullRequestComment HookEventType = "pull_request_comment"
|
||||
HookEventPullRequestReviewApproved HookEventType = "pull_request_review_approved"
|
||||
HookEventPullRequestReviewRejected HookEventType = "pull_request_review_rejected"
|
||||
HookEventPullRequestReviewComment HookEventType = "pull_request_review_comment"
|
||||
HookEventPullRequestSync HookEventType = "pull_request_sync"
|
||||
HookEventWiki HookEventType = "wiki"
|
||||
HookEventRepository HookEventType = "repository"
|
||||
HookEventRelease HookEventType = "release"
|
||||
HookEventPackage HookEventType = "package"
|
||||
)
|
||||
|
||||
// Event returns the HookEventType as an event string
|
||||
func (h HookEventType) Event() string {
|
||||
switch h {
|
||||
case HookEventCreate:
|
||||
return "create"
|
||||
case HookEventDelete:
|
||||
return "delete"
|
||||
case HookEventFork:
|
||||
return "fork"
|
||||
case HookEventPush:
|
||||
return "push"
|
||||
case HookEventIssues, HookEventIssueAssign, HookEventIssueLabel, HookEventIssueMilestone:
|
||||
return "issues"
|
||||
case HookEventPullRequest, HookEventPullRequestAssign, HookEventPullRequestLabel, HookEventPullRequestMilestone,
|
||||
HookEventPullRequestSync:
|
||||
return "pull_request"
|
||||
case HookEventIssueComment, HookEventPullRequestComment:
|
||||
return "issue_comment"
|
||||
case HookEventPullRequestReviewApproved:
|
||||
return "pull_request_approved"
|
||||
case HookEventPullRequestReviewRejected:
|
||||
return "pull_request_rejected"
|
||||
case HookEventPullRequestReviewComment:
|
||||
return "pull_request_comment"
|
||||
case HookEventWiki:
|
||||
return "wiki"
|
||||
case HookEventRepository:
|
||||
return "repository"
|
||||
case HookEventRelease:
|
||||
return "release"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// HookRequest represents hook task request information.
|
||||
type HookRequest struct {
|
||||
URL string `json:"url"`
|
||||
|
|
|
@ -107,11 +107,11 @@ func toAPIHook(ctx *context.APIContext, repoLink string, hook *webhook.Webhook)
|
|||
}
|
||||
|
||||
func issuesHook(events []string, event string) bool {
|
||||
return util.IsStringInSlice(event, events, true) || util.IsStringInSlice(string(webhook.HookEventIssues), events, true)
|
||||
return util.IsStringInSlice(event, events, true) || util.IsStringInSlice(string(webhook_module.HookEventIssues), events, true)
|
||||
}
|
||||
|
||||
func pullHook(events []string, event string) bool {
|
||||
return util.IsStringInSlice(event, events, true) || util.IsStringInSlice(string(webhook.HookEventPullRequest), events, true)
|
||||
return util.IsStringInSlice(event, events, true) || util.IsStringInSlice(string(webhook_module.HookEventPullRequest), events, true)
|
||||
}
|
||||
|
||||
// addHook add the hook specified by `form`, `orgID` and `repoID`. If there is
|
||||
|
@ -130,25 +130,25 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID
|
|||
HookEvent: &webhook_module.HookEvent{
|
||||
ChooseEvents: true,
|
||||
HookEvents: webhook_module.HookEvents{
|
||||
Create: util.IsStringInSlice(string(webhook.HookEventCreate), form.Events, true),
|
||||
Delete: util.IsStringInSlice(string(webhook.HookEventDelete), form.Events, true),
|
||||
Fork: util.IsStringInSlice(string(webhook.HookEventFork), form.Events, true),
|
||||
Create: util.IsStringInSlice(string(webhook_module.HookEventCreate), form.Events, true),
|
||||
Delete: util.IsStringInSlice(string(webhook_module.HookEventDelete), form.Events, true),
|
||||
Fork: util.IsStringInSlice(string(webhook_module.HookEventFork), form.Events, true),
|
||||
Issues: issuesHook(form.Events, "issues_only"),
|
||||
IssueAssign: issuesHook(form.Events, string(webhook.HookEventIssueAssign)),
|
||||
IssueLabel: issuesHook(form.Events, string(webhook.HookEventIssueLabel)),
|
||||
IssueMilestone: issuesHook(form.Events, string(webhook.HookEventIssueMilestone)),
|
||||
IssueComment: issuesHook(form.Events, string(webhook.HookEventIssueComment)),
|
||||
Push: util.IsStringInSlice(string(webhook.HookEventPush), form.Events, true),
|
||||
IssueAssign: issuesHook(form.Events, string(webhook_module.HookEventIssueAssign)),
|
||||
IssueLabel: issuesHook(form.Events, string(webhook_module.HookEventIssueLabel)),
|
||||
IssueMilestone: issuesHook(form.Events, string(webhook_module.HookEventIssueMilestone)),
|
||||
IssueComment: issuesHook(form.Events, string(webhook_module.HookEventIssueComment)),
|
||||
Push: util.IsStringInSlice(string(webhook_module.HookEventPush), form.Events, true),
|
||||
PullRequest: pullHook(form.Events, "pull_request_only"),
|
||||
PullRequestAssign: pullHook(form.Events, string(webhook.HookEventPullRequestAssign)),
|
||||
PullRequestLabel: pullHook(form.Events, string(webhook.HookEventPullRequestLabel)),
|
||||
PullRequestMilestone: pullHook(form.Events, string(webhook.HookEventPullRequestMilestone)),
|
||||
PullRequestComment: pullHook(form.Events, string(webhook.HookEventPullRequestComment)),
|
||||
PullRequestAssign: pullHook(form.Events, string(webhook_module.HookEventPullRequestAssign)),
|
||||
PullRequestLabel: pullHook(form.Events, string(webhook_module.HookEventPullRequestLabel)),
|
||||
PullRequestMilestone: pullHook(form.Events, string(webhook_module.HookEventPullRequestMilestone)),
|
||||
PullRequestComment: pullHook(form.Events, string(webhook_module.HookEventPullRequestComment)),
|
||||
PullRequestReview: pullHook(form.Events, "pull_request_review"),
|
||||
PullRequestSync: pullHook(form.Events, string(webhook.HookEventPullRequestSync)),
|
||||
Wiki: util.IsStringInSlice(string(webhook.HookEventWiki), form.Events, true),
|
||||
Repository: util.IsStringInSlice(string(webhook.HookEventRepository), form.Events, true),
|
||||
Release: util.IsStringInSlice(string(webhook.HookEventRelease), form.Events, true),
|
||||
PullRequestSync: pullHook(form.Events, string(webhook_module.HookEventPullRequestSync)),
|
||||
Wiki: util.IsStringInSlice(string(webhook_module.HookEventWiki), form.Events, true),
|
||||
Repository: util.IsStringInSlice(string(webhook_module.HookEventRepository), form.Events, true),
|
||||
Release: util.IsStringInSlice(string(webhook_module.HookEventRelease), form.Events, true),
|
||||
},
|
||||
BranchFilter: form.BranchFilter,
|
||||
},
|
||||
|
@ -277,14 +277,14 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh
|
|||
w.PushOnly = false
|
||||
w.SendEverything = false
|
||||
w.ChooseEvents = true
|
||||
w.Create = util.IsStringInSlice(string(webhook.HookEventCreate), form.Events, true)
|
||||
w.Push = util.IsStringInSlice(string(webhook.HookEventPush), form.Events, true)
|
||||
w.Create = util.IsStringInSlice(string(webhook.HookEventCreate), form.Events, true)
|
||||
w.Delete = util.IsStringInSlice(string(webhook.HookEventDelete), form.Events, true)
|
||||
w.Fork = util.IsStringInSlice(string(webhook.HookEventFork), form.Events, true)
|
||||
w.Repository = util.IsStringInSlice(string(webhook.HookEventRepository), form.Events, true)
|
||||
w.Wiki = util.IsStringInSlice(string(webhook.HookEventWiki), form.Events, true)
|
||||
w.Release = util.IsStringInSlice(string(webhook.HookEventRelease), form.Events, true)
|
||||
w.Create = util.IsStringInSlice(string(webhook_module.HookEventCreate), form.Events, true)
|
||||
w.Push = util.IsStringInSlice(string(webhook_module.HookEventPush), form.Events, true)
|
||||
w.Create = util.IsStringInSlice(string(webhook_module.HookEventCreate), form.Events, true)
|
||||
w.Delete = util.IsStringInSlice(string(webhook_module.HookEventDelete), form.Events, true)
|
||||
w.Fork = util.IsStringInSlice(string(webhook_module.HookEventFork), form.Events, true)
|
||||
w.Repository = util.IsStringInSlice(string(webhook_module.HookEventRepository), form.Events, true)
|
||||
w.Wiki = util.IsStringInSlice(string(webhook_module.HookEventWiki), form.Events, true)
|
||||
w.Release = util.IsStringInSlice(string(webhook_module.HookEventRelease), form.Events, true)
|
||||
w.BranchFilter = form.BranchFilter
|
||||
|
||||
err := w.SetHeaderAuthorization(form.AuthorizationHeader)
|
||||
|
@ -295,19 +295,19 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh
|
|||
|
||||
// Issues
|
||||
w.Issues = issuesHook(form.Events, "issues_only")
|
||||
w.IssueAssign = issuesHook(form.Events, string(webhook.HookEventIssueAssign))
|
||||
w.IssueLabel = issuesHook(form.Events, string(webhook.HookEventIssueLabel))
|
||||
w.IssueMilestone = issuesHook(form.Events, string(webhook.HookEventIssueMilestone))
|
||||
w.IssueComment = issuesHook(form.Events, string(webhook.HookEventIssueComment))
|
||||
w.IssueAssign = issuesHook(form.Events, string(webhook_module.HookEventIssueAssign))
|
||||
w.IssueLabel = issuesHook(form.Events, string(webhook_module.HookEventIssueLabel))
|
||||
w.IssueMilestone = issuesHook(form.Events, string(webhook_module.HookEventIssueMilestone))
|
||||
w.IssueComment = issuesHook(form.Events, string(webhook_module.HookEventIssueComment))
|
||||
|
||||
// Pull requests
|
||||
w.PullRequest = pullHook(form.Events, "pull_request_only")
|
||||
w.PullRequestAssign = pullHook(form.Events, string(webhook.HookEventPullRequestAssign))
|
||||
w.PullRequestLabel = pullHook(form.Events, string(webhook.HookEventPullRequestLabel))
|
||||
w.PullRequestMilestone = pullHook(form.Events, string(webhook.HookEventPullRequestMilestone))
|
||||
w.PullRequestComment = pullHook(form.Events, string(webhook.HookEventPullRequestComment))
|
||||
w.PullRequestAssign = pullHook(form.Events, string(webhook_module.HookEventPullRequestAssign))
|
||||
w.PullRequestLabel = pullHook(form.Events, string(webhook_module.HookEventPullRequestLabel))
|
||||
w.PullRequestMilestone = pullHook(form.Events, string(webhook_module.HookEventPullRequestMilestone))
|
||||
w.PullRequestComment = pullHook(form.Events, string(webhook_module.HookEventPullRequestComment))
|
||||
w.PullRequestReview = pullHook(form.Events, "pull_request_review")
|
||||
w.PullRequestSync = pullHook(form.Events, string(webhook.HookEventPullRequestSync))
|
||||
w.PullRequestSync = pullHook(form.Events, string(webhook_module.HookEventPullRequestSync))
|
||||
|
||||
if err := w.UpdateEvent(); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "UpdateEvent", err)
|
||||
|
|
Loading…
Reference in a new issue