diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-11-04 06:13:25 +0800 |
---|---|---|
committer | zeripath <art27@cantab.net> | 2019-11-03 22:13:25 +0000 |
commit | a966a0298ea1a545c383541ca4e72c61de1ed59e (patch) | |
tree | 95e327a9c8df47f1c343f8bad210ae6cdd208483 /routers | |
parent | 491887d44132b8103ed0d753f95ecd43d600adba (diff) | |
download | gitea-a966a0298ea1a545c383541ca4e72c61de1ed59e.tar.gz gitea-a966a0298ea1a545c383541ca4e72c61de1ed59e.zip |
Move more webhook codes from models to webhook module (#8802)
* Move more webhook codes from models to webhook module
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/convert/convert.go | 3 | ||||
-rw-r--r-- | routers/api/v1/utils/hook.go | 5 | ||||
-rw-r--r-- | routers/repo/webhook.go | 18 |
3 files changed, 14 insertions, 12 deletions
diff --git a/routers/api/v1/convert/convert.go b/routers/api/v1/convert/convert.go index 07456f8dd6..6da53d6275 100644 --- a/routers/api/v1/convert/convert.go +++ b/routers/api/v1/convert/convert.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/modules/webhook" "github.com/unknwon/com" ) @@ -166,7 +167,7 @@ func ToHook(repoLink string, w *models.Webhook) *api.Hook { "content_type": w.ContentType.Name(), } if w.HookTaskType == models.SLACK { - s := w.GetSlackHook() + s := webhook.GetSlackHook(w) config["channel"] = s.Channel config["username"] = s.Username config["icon_url"] = s.IconURL diff --git a/routers/api/v1/utils/hook.go b/routers/api/v1/utils/hook.go index 7903d58334..6f72e99b71 100644 --- a/routers/api/v1/utils/hook.go +++ b/routers/api/v1/utils/hook.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/webhook" "code.gitea.io/gitea/routers/api/v1/convert" "code.gitea.io/gitea/routers/utils" @@ -129,7 +130,7 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID return nil, false } - meta, err := json.Marshal(&models.SlackMeta{ + meta, err := json.Marshal(&webhook.SlackMeta{ Channel: strings.TrimSpace(channel), Username: form.Config["username"], IconURL: form.Config["icon_url"], @@ -203,7 +204,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *models.Webho if w.HookTaskType == models.SLACK { if channel, ok := form.Config["channel"]; ok { - meta, err := json.Marshal(&models.SlackMeta{ + meta, err := json.Marshal(&webhook.SlackMeta{ Channel: channel, Username: form.Config["username"], IconURL: form.Config["icon_url"], diff --git a/routers/repo/webhook.go b/routers/repo/webhook.go index a6bd3af264..9ae15882c1 100644 --- a/routers/repo/webhook.go +++ b/routers/repo/webhook.go @@ -268,7 +268,7 @@ func DiscordHooksNewPost(ctx *context.Context, form auth.NewDiscordHookForm) { return } - meta, err := json.Marshal(&models.DiscordMeta{ + meta, err := json.Marshal(&webhook.DiscordMeta{ Username: form.Username, IconURL: form.IconURL, }) @@ -357,7 +357,7 @@ func TelegramHooksNewPost(ctx *context.Context, form auth.NewTelegramHookForm) { return } - meta, err := json.Marshal(&models.TelegramMeta{ + meta, err := json.Marshal(&webhook.TelegramMeta{ BotToken: form.BotToken, ChatID: form.ChatID, }) @@ -452,7 +452,7 @@ func SlackHooksNewPost(ctx *context.Context, form auth.NewSlackHookForm) { return } - meta, err := json.Marshal(&models.SlackMeta{ + meta, err := json.Marshal(&webhook.SlackMeta{ Channel: strings.TrimSpace(form.Channel), Username: form.Username, IconURL: form.IconURL, @@ -515,11 +515,11 @@ func checkWebhook(ctx *context.Context) (*orgRepoCtx, *models.Webhook) { ctx.Data["HookType"] = w.HookTaskType.Name() switch w.HookTaskType { case models.SLACK: - ctx.Data["SlackHook"] = w.GetSlackHook() + ctx.Data["SlackHook"] = webhook.GetSlackHook(w) case models.DISCORD: - ctx.Data["DiscordHook"] = w.GetDiscordHook() + ctx.Data["DiscordHook"] = webhook.GetDiscordHook(w) case models.TELEGRAM: - ctx.Data["TelegramHook"] = w.GetTelegramHook() + ctx.Data["TelegramHook"] = webhook.GetTelegramHook(w) } ctx.Data["History"], err = w.History(1) @@ -646,7 +646,7 @@ func SlackHooksEditPost(ctx *context.Context, form auth.NewSlackHookForm) { return } - meta, err := json.Marshal(&models.SlackMeta{ + meta, err := json.Marshal(&webhook.SlackMeta{ Channel: strings.TrimSpace(form.Channel), Username: form.Username, IconURL: form.IconURL, @@ -690,7 +690,7 @@ func DiscordHooksEditPost(ctx *context.Context, form auth.NewDiscordHookForm) { return } - meta, err := json.Marshal(&models.DiscordMeta{ + meta, err := json.Marshal(&webhook.DiscordMeta{ Username: form.Username, IconURL: form.IconURL, }) @@ -763,7 +763,7 @@ func TelegramHooksEditPost(ctx *context.Context, form auth.NewTelegramHookForm) ctx.HTML(200, orCtx.NewTemplate) return } - meta, err := json.Marshal(&models.TelegramMeta{ + meta, err := json.Marshal(&webhook.TelegramMeta{ BotToken: form.BotToken, ChatID: form.ChatID, }) |