diff options
Diffstat (limited to 'services/webhook/webhook.go')
-rw-r--r-- | services/webhook/webhook.go | 65 |
1 files changed, 33 insertions, 32 deletions
diff --git a/services/webhook/webhook.go b/services/webhook/webhook.go index 00b2ef05b8..d4fe4e3bcc 100644 --- a/services/webhook/webhook.go +++ b/services/webhook/webhook.go @@ -9,6 +9,7 @@ import ( "strings" "code.gitea.io/gitea/models" + webhook_model "code.gitea.io/gitea/models/webhook" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" @@ -20,42 +21,42 @@ import ( ) type webhook struct { - name models.HookType - payloadCreator func(p api.Payloader, event models.HookEventType, meta string) (api.Payloader, error) + name webhook_model.HookType + payloadCreator func(p api.Payloader, event webhook_model.HookEventType, meta string) (api.Payloader, error) } var ( - webhooks = map[models.HookType]*webhook{ - models.SLACK: { - name: models.SLACK, + webhooks = map[webhook_model.HookType]*webhook{ + webhook_model.SLACK: { + name: webhook_model.SLACK, payloadCreator: GetSlackPayload, }, - models.DISCORD: { - name: models.DISCORD, + webhook_model.DISCORD: { + name: webhook_model.DISCORD, payloadCreator: GetDiscordPayload, }, - models.DINGTALK: { - name: models.DINGTALK, + webhook_model.DINGTALK: { + name: webhook_model.DINGTALK, payloadCreator: GetDingtalkPayload, }, - models.TELEGRAM: { - name: models.TELEGRAM, + webhook_model.TELEGRAM: { + name: webhook_model.TELEGRAM, payloadCreator: GetTelegramPayload, }, - models.MSTEAMS: { - name: models.MSTEAMS, + webhook_model.MSTEAMS: { + name: webhook_model.MSTEAMS, payloadCreator: GetMSTeamsPayload, }, - models.FEISHU: { - name: models.FEISHU, + webhook_model.FEISHU: { + name: webhook_model.FEISHU, payloadCreator: GetFeishuPayload, }, - models.MATRIX: { - name: models.MATRIX, + webhook_model.MATRIX: { + name: webhook_model.MATRIX, payloadCreator: GetMatrixPayload, }, - models.WECHATWORK: { - name: models.WECHATWORK, + webhook_model.WECHATWORK: { + name: webhook_model.WECHATWORK, payloadCreator: GetWechatworkPayload, }, } @@ -63,15 +64,15 @@ var ( // RegisterWebhook registers a webhook func RegisterWebhook(name string, webhook *webhook) { - webhooks[models.HookType(name)] = webhook + webhooks[webhook_model.HookType(name)] = webhook } // IsValidHookTaskType returns true if a webhook registered func IsValidHookTaskType(name string) bool { - if name == models.GITEA || name == models.GOGS { + if name == webhook_model.GITEA || name == webhook_model.GOGS { return true } - _, ok := webhooks[models.HookType(name)] + _, ok := webhooks[webhook_model.HookType(name)] return ok } @@ -98,7 +99,7 @@ func getPayloadBranch(p api.Payloader) string { } // PrepareWebhook adds special webhook to task queue for given payload. -func PrepareWebhook(w *models.Webhook, repo *models.Repository, event models.HookEventType, p api.Payloader) error { +func PrepareWebhook(w *webhook_model.Webhook, repo *models.Repository, event webhook_model.HookEventType, p api.Payloader) error { if err := prepareWebhook(w, repo, event, p); err != nil { return err } @@ -107,7 +108,7 @@ func PrepareWebhook(w *models.Webhook, repo *models.Repository, event models.Hoo return nil } -func checkBranch(w *models.Webhook, branch string) bool { +func checkBranch(w *webhook_model.Webhook, branch string) bool { if w.BranchFilter == "" || w.BranchFilter == "*" { return true } @@ -122,7 +123,7 @@ func checkBranch(w *models.Webhook, branch string) bool { return g.Match(branch) } -func prepareWebhook(w *models.Webhook, repo *models.Repository, event models.HookEventType, p api.Payloader) error { +func prepareWebhook(w *webhook_model.Webhook, repo *models.Repository, event webhook_model.HookEventType, p api.Payloader) error { // Skip sending if webhooks are disabled. if setting.DisableWebhooks { return nil @@ -141,7 +142,7 @@ func prepareWebhook(w *models.Webhook, repo *models.Repository, event models.Hoo // Avoid sending "0 new commits" to non-integration relevant webhooks (e.g. slack, discord, etc.). // Integration webhooks (e.g. drone) still receive the required data. if pushEvent, ok := p.(*api.PushPayload); ok && - w.Type != models.GITEA && w.Type != models.GOGS && + w.Type != webhook_model.GITEA && w.Type != webhook_model.GOGS && len(pushEvent.Commits) == 0 { return nil } @@ -167,7 +168,7 @@ func prepareWebhook(w *models.Webhook, repo *models.Repository, event models.Hoo payloader = p } - if err = models.CreateHookTask(&models.HookTask{ + if err = webhook_model.CreateHookTask(&webhook_model.HookTask{ RepoID: repo.ID, HookID: w.ID, Payloader: payloader, @@ -179,7 +180,7 @@ func prepareWebhook(w *models.Webhook, repo *models.Repository, event models.Hoo } // PrepareWebhooks adds new webhooks to task queue for given payload. -func PrepareWebhooks(repo *models.Repository, event models.HookEventType, p api.Payloader) error { +func PrepareWebhooks(repo *models.Repository, event webhook_model.HookEventType, p api.Payloader) error { if err := prepareWebhooks(repo, event, p); err != nil { return err } @@ -188,8 +189,8 @@ func PrepareWebhooks(repo *models.Repository, event models.HookEventType, p api. return nil } -func prepareWebhooks(repo *models.Repository, event models.HookEventType, p api.Payloader) error { - ws, err := models.ListWebhooksByOpts(&models.ListWebhookOptions{ +func prepareWebhooks(repo *models.Repository, event webhook_model.HookEventType, p api.Payloader) error { + ws, err := webhook_model.ListWebhooksByOpts(&webhook_model.ListWebhookOptions{ RepoID: repo.ID, IsActive: util.OptionalBoolTrue, }) @@ -200,7 +201,7 @@ func prepareWebhooks(repo *models.Repository, event models.HookEventType, p api. // check if repo belongs to org and append additional webhooks if repo.MustOwner().IsOrganization() { // get hooks for org - orgHooks, err := models.ListWebhooksByOpts(&models.ListWebhookOptions{ + orgHooks, err := webhook_model.ListWebhooksByOpts(&webhook_model.ListWebhookOptions{ OrgID: repo.OwnerID, IsActive: util.OptionalBoolTrue, }) @@ -211,7 +212,7 @@ func prepareWebhooks(repo *models.Repository, event models.HookEventType, p api. } // Add any admin-defined system webhooks - systemHooks, err := models.GetSystemWebhooks() + systemHooks, err := webhook_model.GetSystemWebhooks() if err != nil { return fmt.Errorf("GetSystemWebhooks: %v", err) } |