From 9558b18d2284ac9617015b36dd971699fafb30b6 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Fri, 22 Mar 2024 11:50:59 +0100 Subject: [PATCH 1/2] [REFACTOR] webhook move templates --- templates/webhook/new.tmpl | 40 +++++++++++++------ .../webhook => webhook/new}/dingtalk.tmpl | 0 .../webhook => webhook/new}/discord.tmpl | 0 .../webhook => webhook/new}/feishu.tmpl | 0 .../webhook => webhook/new}/forgejo.tmpl | 0 .../webhook => webhook/new}/gitea.tmpl | 0 .../webhook => webhook/new}/gogs.tmpl | 0 .../webhook => webhook/new}/matrix.tmpl | 0 .../webhook => webhook/new}/msteams.tmpl | 0 .../webhook => webhook/new}/packagist.tmpl | 0 .../webhook => webhook/new}/slack.tmpl | 0 .../webhook => webhook/new}/telegram.tmpl | 0 .../webhook => webhook/new}/wechatwork.tmpl | 0 13 files changed, 28 insertions(+), 12 deletions(-) rename templates/{repo/settings/webhook => webhook/new}/dingtalk.tmpl (100%) rename templates/{repo/settings/webhook => webhook/new}/discord.tmpl (100%) rename templates/{repo/settings/webhook => webhook/new}/feishu.tmpl (100%) rename templates/{repo/settings/webhook => webhook/new}/forgejo.tmpl (100%) rename templates/{repo/settings/webhook => webhook/new}/gitea.tmpl (100%) rename templates/{repo/settings/webhook => webhook/new}/gogs.tmpl (100%) rename templates/{repo/settings/webhook => webhook/new}/matrix.tmpl (100%) rename templates/{repo/settings/webhook => webhook/new}/msteams.tmpl (100%) rename templates/{repo/settings/webhook => webhook/new}/packagist.tmpl (100%) rename templates/{repo/settings/webhook => webhook/new}/slack.tmpl (100%) rename templates/{repo/settings/webhook => webhook/new}/telegram.tmpl (100%) rename templates/{repo/settings/webhook => webhook/new}/wechatwork.tmpl (100%) diff --git a/templates/webhook/new.tmpl b/templates/webhook/new.tmpl index 0347455f2c..17eb578b0e 100644 --- a/templates/webhook/new.tmpl +++ b/templates/webhook/new.tmpl @@ -10,17 +10,33 @@
- {{template "repo/settings/webhook/forgejo" .ctxData}} - {{template "repo/settings/webhook/gitea" .ctxData}} - {{template "repo/settings/webhook/gogs" .ctxData}} - {{template "repo/settings/webhook/slack" .ctxData}} - {{template "repo/settings/webhook/discord" .ctxData}} - {{template "repo/settings/webhook/dingtalk" .ctxData}} - {{template "repo/settings/webhook/telegram" .ctxData}} - {{template "repo/settings/webhook/msteams" .ctxData}} - {{template "repo/settings/webhook/feishu" .ctxData}} - {{template "repo/settings/webhook/matrix" .ctxData}} - {{template "repo/settings/webhook/wechatwork" .ctxData}} - {{template "repo/settings/webhook/packagist" .ctxData}} + {{with .ctxData}} + + {{if eq .HookType "forgejo"}} + {{template "webhook/new/forgejo" .}} + {{else if eq .HookType "gitea"}} + {{template "webhook/new/gitea" .}} + {{else if eq .HookType "gogs"}} + {{template "webhook/new/gogs" .}} + {{else if eq .HookType "slack"}} + {{template "webhook/new/slack" .}} + {{else if eq .HookType "discord"}} + {{template "webhook/new/discord" .}} + {{else if eq .HookType "dingtalk"}} + {{template "webhook/new/dingtalk" .}} + {{else if eq .HookType "telegram"}} + {{template "webhook/new/telegram" .}} + {{else if eq .HookType "msteams"}} + {{template "webhook/new/msteams" .}} + {{else if eq .HookType "feishu"}} + {{template "webhook/new/feishu" .}} + {{else if eq .HookType "matrix"}} + {{template "webhook/new/matrix" .}} + {{else if eq .HookType "wechatwork"}} + {{template "webhook/new/wechatwork" .}} + {{else if eq .HookType "packagist"}} + {{template "webhook/new/packagist" .}} + {{end}} + {{end}}
{{template "repo/settings/webhook/history" .ctxData}} diff --git a/templates/repo/settings/webhook/dingtalk.tmpl b/templates/webhook/new/dingtalk.tmpl similarity index 100% rename from templates/repo/settings/webhook/dingtalk.tmpl rename to templates/webhook/new/dingtalk.tmpl diff --git a/templates/repo/settings/webhook/discord.tmpl b/templates/webhook/new/discord.tmpl similarity index 100% rename from templates/repo/settings/webhook/discord.tmpl rename to templates/webhook/new/discord.tmpl diff --git a/templates/repo/settings/webhook/feishu.tmpl b/templates/webhook/new/feishu.tmpl similarity index 100% rename from templates/repo/settings/webhook/feishu.tmpl rename to templates/webhook/new/feishu.tmpl diff --git a/templates/repo/settings/webhook/forgejo.tmpl b/templates/webhook/new/forgejo.tmpl similarity index 100% rename from templates/repo/settings/webhook/forgejo.tmpl rename to templates/webhook/new/forgejo.tmpl diff --git a/templates/repo/settings/webhook/gitea.tmpl b/templates/webhook/new/gitea.tmpl similarity index 100% rename from templates/repo/settings/webhook/gitea.tmpl rename to templates/webhook/new/gitea.tmpl diff --git a/templates/repo/settings/webhook/gogs.tmpl b/templates/webhook/new/gogs.tmpl similarity index 100% rename from templates/repo/settings/webhook/gogs.tmpl rename to templates/webhook/new/gogs.tmpl diff --git a/templates/repo/settings/webhook/matrix.tmpl b/templates/webhook/new/matrix.tmpl similarity index 100% rename from templates/repo/settings/webhook/matrix.tmpl rename to templates/webhook/new/matrix.tmpl diff --git a/templates/repo/settings/webhook/msteams.tmpl b/templates/webhook/new/msteams.tmpl similarity index 100% rename from templates/repo/settings/webhook/msteams.tmpl rename to templates/webhook/new/msteams.tmpl diff --git a/templates/repo/settings/webhook/packagist.tmpl b/templates/webhook/new/packagist.tmpl similarity index 100% rename from templates/repo/settings/webhook/packagist.tmpl rename to templates/webhook/new/packagist.tmpl diff --git a/templates/repo/settings/webhook/slack.tmpl b/templates/webhook/new/slack.tmpl similarity index 100% rename from templates/repo/settings/webhook/slack.tmpl rename to templates/webhook/new/slack.tmpl diff --git a/templates/repo/settings/webhook/telegram.tmpl b/templates/webhook/new/telegram.tmpl similarity index 100% rename from templates/repo/settings/webhook/telegram.tmpl rename to templates/webhook/new/telegram.tmpl diff --git a/templates/repo/settings/webhook/wechatwork.tmpl b/templates/webhook/new/wechatwork.tmpl similarity index 100% rename from templates/repo/settings/webhook/wechatwork.tmpl rename to templates/webhook/new/wechatwork.tmpl From be6434662a8247545489c035e3630cf993dd345c Mon Sep 17 00:00:00 2001 From: oliverpool Date: Fri, 22 Mar 2024 11:52:39 +0100 Subject: [PATCH 2/2] [REFACTOR] webhook/new remove redundant if --- templates/webhook/new/dingtalk.tmpl | 20 ++++---- templates/webhook/new/discord.tmpl | 36 +++++++------- templates/webhook/new/feishu.tmpl | 22 ++++----- templates/webhook/new/forgejo.tmpl | 70 +++++++++++++-------------- templates/webhook/new/gitea.tmpl | 70 +++++++++++++-------------- templates/webhook/new/gogs.tmpl | 50 +++++++++---------- templates/webhook/new/matrix.tmpl | 48 +++++++++--------- templates/webhook/new/msteams.tmpl | 20 ++++---- templates/webhook/new/packagist.tmpl | 36 +++++++------- templates/webhook/new/slack.tmpl | 52 ++++++++++---------- templates/webhook/new/telegram.tmpl | 36 +++++++------- templates/webhook/new/wechatwork.tmpl | 20 ++++---- 12 files changed, 228 insertions(+), 252 deletions(-) diff --git a/templates/webhook/new/dingtalk.tmpl b/templates/webhook/new/dingtalk.tmpl index f1cd6a1932..398cb45f8c 100644 --- a/templates/webhook/new/dingtalk.tmpl +++ b/templates/webhook/new/dingtalk.tmpl @@ -1,11 +1,9 @@ -{{if eq .HookType "dingtalk"}} -

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://dingtalk.com" (ctx.Locale.Tr "repo.settings.web_hook_name_dingtalk")}}

-
- {{.CsrfTokenHtml}} -
- - -
- {{template "repo/settings/webhook/settings" .}} -
-{{end}} +

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://dingtalk.com" (ctx.Locale.Tr "repo.settings.web_hook_name_dingtalk")}}

+
+ {{.CsrfTokenHtml}} +
+ + +
+ {{template "repo/settings/webhook/settings" .}} +
diff --git a/templates/webhook/new/discord.tmpl b/templates/webhook/new/discord.tmpl index 95a3806c89..c6a7ea7d19 100644 --- a/templates/webhook/new/discord.tmpl +++ b/templates/webhook/new/discord.tmpl @@ -1,19 +1,17 @@ -{{if eq .HookType "discord"}} -

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://discord.com" (ctx.Locale.Tr "repo.settings.web_hook_name_discord")}}

-
- {{.CsrfTokenHtml}} -
- - -
-
- - -
-
- - -
- {{template "repo/settings/webhook/settings" .}} -
-{{end}} +

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://discord.com" (ctx.Locale.Tr "repo.settings.web_hook_name_discord")}}

+
+ {{.CsrfTokenHtml}} +
+ + +
+
+ + +
+
+ + +
+ {{template "repo/settings/webhook/settings" .}} +
diff --git a/templates/webhook/new/feishu.tmpl b/templates/webhook/new/feishu.tmpl index cd6aaf935a..b691c3f18c 100644 --- a/templates/webhook/new/feishu.tmpl +++ b/templates/webhook/new/feishu.tmpl @@ -1,12 +1,10 @@ -{{if eq .HookType "feishu"}} -

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://feishu.cn" (ctx.Locale.Tr "repo.settings.web_hook_name_feishu")}}

-

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://larksuite.com" (ctx.Locale.Tr "repo.settings.web_hook_name_larksuite")}}

-
- {{.CsrfTokenHtml}} -
- - -
- {{template "repo/settings/webhook/settings" .}} -
-{{end}} +

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://feishu.cn" (ctx.Locale.Tr "repo.settings.web_hook_name_feishu")}}

+

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://larksuite.com" (ctx.Locale.Tr "repo.settings.web_hook_name_larksuite")}}

+
+ {{.CsrfTokenHtml}} +
+ + +
+ {{template "repo/settings/webhook/settings" .}} +
diff --git a/templates/webhook/new/forgejo.tmpl b/templates/webhook/new/forgejo.tmpl index 5c8233a638..6bc4eb489e 100644 --- a/templates/webhook/new/forgejo.tmpl +++ b/templates/webhook/new/forgejo.tmpl @@ -1,40 +1,38 @@ -{{if eq .HookType "forgejo"}} -

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://forgejo.org/docs/latest/user/webhooks/" (ctx.Locale.Tr "repo.settings.web_hook_name_forgejo")}}

-
- {{template "base/disable_form_autofill"}} - {{.CsrfTokenHtml}} -
- - -
-
- -