mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Restructure webhook
module (#22256)
Previously, there was an `import services/webhooks` inside `modules/notification/webhook`. This import was removed (after fighting against many import cycles). Additionally, `modules/notification/webhook` was moved to `modules/webhook`, and a few structs/constants were extracted from `models/webhooks` to `modules/webhook`. Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||
"code.gitea.io/gitea/services/convert"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
webhook_service "code.gitea.io/gitea/services/webhook"
|
||||
@@ -119,7 +120,7 @@ func checkHookType(ctx *context.Context) string {
|
||||
// WebhooksNew render creating webhook page
|
||||
func WebhooksNew(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook")
|
||||
ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook.HookEvent{}}
|
||||
ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook_module.HookEvent{}}
|
||||
|
||||
orCtx, err := getOrgRepoCtx(ctx)
|
||||
if err != nil {
|
||||
@@ -154,12 +155,12 @@ func WebhooksNew(ctx *context.Context) {
|
||||
}
|
||||
|
||||
// ParseHookEvent convert web form content to webhook.HookEvent
|
||||
func ParseHookEvent(form forms.WebhookForm) *webhook.HookEvent {
|
||||
return &webhook.HookEvent{
|
||||
func ParseHookEvent(form forms.WebhookForm) *webhook_module.HookEvent {
|
||||
return &webhook_module.HookEvent{
|
||||
PushOnly: form.PushOnly(),
|
||||
SendEverything: form.SendEverything(),
|
||||
ChooseEvents: form.ChooseEvents(),
|
||||
HookEvents: webhook.HookEvents{
|
||||
HookEvents: webhook_module.HookEvents{
|
||||
Create: form.Create,
|
||||
Delete: form.Delete,
|
||||
Fork: form.Fork,
|
||||
@@ -201,7 +202,7 @@ func createWebhook(ctx *context.Context, params webhookParams) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook")
|
||||
ctx.Data["PageIsSettingsHooks"] = true
|
||||
ctx.Data["PageIsSettingsHooksNew"] = true
|
||||
ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook.HookEvent{}}
|
||||
ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook_module.HookEvent{}}
|
||||
ctx.Data["HookType"] = params.Type
|
||||
|
||||
orCtx, err := getOrgRepoCtx(ctx)
|
||||
@@ -326,7 +327,7 @@ func giteaHookParams(ctx *context.Context) webhookParams {
|
||||
}
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook.GITEA,
|
||||
Type: webhook_module.GITEA,
|
||||
URL: form.PayloadURL,
|
||||
ContentType: contentType,
|
||||
Secret: form.Secret,
|
||||
@@ -354,7 +355,7 @@ func gogsHookParams(ctx *context.Context) webhookParams {
|
||||
}
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook.GOGS,
|
||||
Type: webhook_module.GOGS,
|
||||
URL: form.PayloadURL,
|
||||
ContentType: contentType,
|
||||
Secret: form.Secret,
|
||||
@@ -376,7 +377,7 @@ func discordHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewDiscordHookForm)
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook.DISCORD,
|
||||
Type: webhook_module.DISCORD,
|
||||
URL: form.PayloadURL,
|
||||
ContentType: webhook.ContentTypeJSON,
|
||||
WebhookForm: form.WebhookForm,
|
||||
@@ -401,7 +402,7 @@ func dingtalkHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewDingtalkHookForm)
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook.DINGTALK,
|
||||
Type: webhook_module.DINGTALK,
|
||||
URL: form.PayloadURL,
|
||||
ContentType: webhook.ContentTypeJSON,
|
||||
WebhookForm: form.WebhookForm,
|
||||
@@ -422,7 +423,7 @@ func telegramHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewTelegramHookForm)
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook.TELEGRAM,
|
||||
Type: webhook_module.TELEGRAM,
|
||||
URL: fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage?chat_id=%s", url.PathEscape(form.BotToken), url.QueryEscape(form.ChatID)),
|
||||
ContentType: webhook.ContentTypeJSON,
|
||||
WebhookForm: form.WebhookForm,
|
||||
@@ -447,7 +448,7 @@ func matrixHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewMatrixHookForm)
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook.MATRIX,
|
||||
Type: webhook_module.MATRIX,
|
||||
URL: fmt.Sprintf("%s/_matrix/client/r0/rooms/%s/send/m.room.message", form.HomeserverURL, url.PathEscape(form.RoomID)),
|
||||
ContentType: webhook.ContentTypeJSON,
|
||||
HTTPMethod: http.MethodPut,
|
||||
@@ -474,7 +475,7 @@ func mSTeamsHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewMSTeamsHookForm)
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook.MSTEAMS,
|
||||
Type: webhook_module.MSTEAMS,
|
||||
URL: form.PayloadURL,
|
||||
ContentType: webhook.ContentTypeJSON,
|
||||
WebhookForm: form.WebhookForm,
|
||||
@@ -495,7 +496,7 @@ func slackHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewSlackHookForm)
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook.SLACK,
|
||||
Type: webhook_module.SLACK,
|
||||
URL: form.PayloadURL,
|
||||
ContentType: webhook.ContentTypeJSON,
|
||||
WebhookForm: form.WebhookForm,
|
||||
@@ -522,7 +523,7 @@ func feishuHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewFeishuHookForm)
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook.FEISHU,
|
||||
Type: webhook_module.FEISHU,
|
||||
URL: form.PayloadURL,
|
||||
ContentType: webhook.ContentTypeJSON,
|
||||
WebhookForm: form.WebhookForm,
|
||||
@@ -543,7 +544,7 @@ func wechatworkHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewWechatWorkHookForm)
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook.WECHATWORK,
|
||||
Type: webhook_module.WECHATWORK,
|
||||
URL: form.PayloadURL,
|
||||
ContentType: webhook.ContentTypeJSON,
|
||||
WebhookForm: form.WebhookForm,
|
||||
@@ -564,7 +565,7 @@ func packagistHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewPackagistHookForm)
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook.PACKAGIST,
|
||||
Type: webhook_module.PACKAGIST,
|
||||
URL: fmt.Sprintf("https://packagist.org/api/update-package?username=%s&apiToken=%s", url.QueryEscape(form.Username), url.QueryEscape(form.APIToken)),
|
||||
ContentType: webhook.ContentTypeJSON,
|
||||
WebhookForm: form.WebhookForm,
|
||||
@@ -603,15 +604,15 @@ func checkWebhook(ctx *context.Context) (*orgRepoCtx, *webhook.Webhook) {
|
||||
|
||||
ctx.Data["HookType"] = w.Type
|
||||
switch w.Type {
|
||||
case webhook.SLACK:
|
||||
case webhook_module.SLACK:
|
||||
ctx.Data["SlackHook"] = webhook_service.GetSlackHook(w)
|
||||
case webhook.DISCORD:
|
||||
case webhook_module.DISCORD:
|
||||
ctx.Data["DiscordHook"] = webhook_service.GetDiscordHook(w)
|
||||
case webhook.TELEGRAM:
|
||||
case webhook_module.TELEGRAM:
|
||||
ctx.Data["TelegramHook"] = webhook_service.GetTelegramHook(w)
|
||||
case webhook.MATRIX:
|
||||
case webhook_module.MATRIX:
|
||||
ctx.Data["MatrixHook"] = webhook_service.GetMatrixHook(w)
|
||||
case webhook.PACKAGIST:
|
||||
case webhook_module.PACKAGIST:
|
||||
ctx.Data["PackagistHook"] = webhook_service.GetPackagistHook(w)
|
||||
}
|
||||
|
||||
@@ -688,7 +689,7 @@ func TestWebhook(ctx *context.Context) {
|
||||
Pusher: apiUser,
|
||||
Sender: apiUser,
|
||||
}
|
||||
if err := webhook_service.PrepareWebhook(ctx, w, webhook.HookEventPush, p); err != nil {
|
||||
if err := webhook_service.PrepareWebhook(ctx, w, webhook_module.HookEventPush, p); err != nil {
|
||||
ctx.Flash.Error("PrepareWebhook: " + err.Error())
|
||||
ctx.Status(http.StatusInternalServerError)
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user