From 7f03fdf9f9ee98f2fb37b0d6fa9f152ef5a3cfa2 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Sat, 23 Mar 2024 21:28:30 +0100 Subject: [PATCH 1/2] [REFACTOR] use Icon from interface in webhook list --- .deadcode-out | 1 - options/locale/locale_bg.ini | 6 +-- options/locale/locale_cs-CZ.ini | 6 +-- options/locale/locale_de-DE.ini | 6 +-- options/locale/locale_el-GR.ini | 6 +-- options/locale/locale_en-US.ini | 6 +-- options/locale/locale_es-ES.ini | 6 +-- options/locale/locale_fi-FI.ini | 4 +- options/locale/locale_fr-FR.ini | 6 +-- options/locale/locale_is-IS.ini | 2 +- options/locale/locale_it-IT.ini | 6 +-- options/locale/locale_ja-JP.ini | 6 +-- options/locale/locale_lv-LV.ini | 6 +-- options/locale/locale_nl-NL.ini | 6 +-- options/locale/locale_pt-BR.ini | 6 +-- options/locale/locale_pt-PT.ini | 6 +-- options/locale/locale_ru-RU.ini | 6 +-- options/locale/locale_tr-TR.ini | 6 +-- options/locale/locale_zh-CN.ini | 6 +-- options/locale/locale_zh-TW.ini | 6 +-- routers/web/org/setting.go | 2 + routers/web/repo/setting/webhook.go | 4 ++ routers/web/user/setting/webhooks.go | 2 + .../repo/settings/webhook/link_menu.tmpl | 54 +++---------------- templates/webhook/new/feishu.tmpl | 4 +- 25 files changed, 70 insertions(+), 105 deletions(-) diff --git a/.deadcode-out b/.deadcode-out index c63fd9e0af..1b65e3203d 100644 --- a/.deadcode-out +++ b/.deadcode-out @@ -341,5 +341,4 @@ package "code.gitea.io/gitea/services/repository/files" package "code.gitea.io/gitea/services/webhook" func NewNotifier - func List diff --git a/options/locale/locale_bg.ini b/options/locale/locale_bg.ini index 227e13419a..f2aeb2a8b9 100644 --- a/options/locale/locale_bg.ini +++ b/options/locale/locale_bg.ini @@ -935,9 +935,9 @@ settings.web_hook_name_discord = Discord settings.web_hook_name_telegram = Telegram settings.web_hook_name_matrix = Matrix settings.web_hook_name_gogs = Gogs -settings.web_hook_name_feishu_or_larksuite = Feishu / Lark Suite -settings.web_hook_name_feishu = Feishu -settings.web_hook_name_larksuite = Lark Suite +settings.web_hook_name_feishu = Feishu / Lark Suite +settings.web_hook_name_feishu_only = Feishu +settings.web_hook_name_larksuite_only = Lark Suite settings.web_hook_name_wechatwork = WeCom (Wechat Work) settings.web_hook_name_packagist = Packagist diff.file_byte_size = Размер diff --git a/options/locale/locale_cs-CZ.ini b/options/locale/locale_cs-CZ.ini index 907b5d5c4a..092c25aa80 100644 --- a/options/locale/locale_cs-CZ.ini +++ b/options/locale/locale_cs-CZ.ini @@ -2308,9 +2308,9 @@ settings.web_hook_name_dingtalk=DingTalk settings.web_hook_name_telegram=Telegram settings.web_hook_name_matrix=Matrix settings.web_hook_name_msteams=Microsoft Teams -settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite -settings.web_hook_name_feishu=Feishu -settings.web_hook_name_larksuite=Lark Suite +settings.web_hook_name_feishu=Feishu / Lark Suite +settings.web_hook_name_feishu_only =Feishu +settings.web_hook_name_larksuite_only =Lark Suite settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_packagist=Packagist settings.packagist_username=Uživatelské jméno pro Packagist diff --git a/options/locale/locale_de-DE.ini b/options/locale/locale_de-DE.ini index e974d555c3..2cab9733ac 100644 --- a/options/locale/locale_de-DE.ini +++ b/options/locale/locale_de-DE.ini @@ -2304,9 +2304,9 @@ settings.web_hook_name_dingtalk=DingTalk settings.web_hook_name_telegram=Telegram settings.web_hook_name_matrix=Matrix settings.web_hook_name_msteams=Microsoft Teams -settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite -settings.web_hook_name_feishu=Feishu -settings.web_hook_name_larksuite=Lark Suite +settings.web_hook_name_feishu=Feishu / Lark Suite +settings.web_hook_name_feishu_only =Feishu +settings.web_hook_name_larksuite_only =Lark Suite settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_packagist=Packagist settings.packagist_username=Benutzername für Packagist diff --git a/options/locale/locale_el-GR.ini b/options/locale/locale_el-GR.ini index 36b7518c62..b9d2881d8a 100644 --- a/options/locale/locale_el-GR.ini +++ b/options/locale/locale_el-GR.ini @@ -2293,9 +2293,9 @@ settings.web_hook_name_dingtalk=DingTalk settings.web_hook_name_telegram=Telegram settings.web_hook_name_matrix=Matrix settings.web_hook_name_msteams=Microsoft Teams -settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite -settings.web_hook_name_feishu=Feishu -settings.web_hook_name_larksuite=Lark Suite +settings.web_hook_name_feishu=Feishu / Lark Suite +settings.web_hook_name_feishu_only =Feishu +settings.web_hook_name_larksuite_only =Lark Suite settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_packagist=Packagist settings.packagist_username=Όνομα χρήστη Packagist diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index c28ed6c376..67ec3b1960 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2372,9 +2372,9 @@ settings.web_hook_name_dingtalk = DingTalk settings.web_hook_name_telegram = Telegram settings.web_hook_name_matrix = Matrix settings.web_hook_name_msteams = Microsoft Teams -settings.web_hook_name_feishu_or_larksuite = Feishu / Lark Suite -settings.web_hook_name_feishu = Feishu -settings.web_hook_name_larksuite = Lark Suite +settings.web_hook_name_feishu = Feishu / Lark Suite +settings.web_hook_name_feishu_only = Feishu +settings.web_hook_name_larksuite_only = Lark Suite settings.web_hook_name_wechatwork = WeCom (Wechat Work) settings.web_hook_name_packagist = Packagist settings.packagist_username = Packagist username diff --git a/options/locale/locale_es-ES.ini b/options/locale/locale_es-ES.ini index 3dbca87381..a2794ccd3d 100644 --- a/options/locale/locale_es-ES.ini +++ b/options/locale/locale_es-ES.ini @@ -2267,9 +2267,9 @@ settings.web_hook_name_dingtalk=DingTalk settings.web_hook_name_telegram=Telegram settings.web_hook_name_matrix=Matrix settings.web_hook_name_msteams=Microsoft Teams -settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite -settings.web_hook_name_feishu=Feishu -settings.web_hook_name_larksuite=Lark Suite +settings.web_hook_name_feishu=Feishu / Lark Suite +settings.web_hook_name_feishu_only =Feishu +settings.web_hook_name_larksuite_only =Lark Suite settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_packagist=Packagist settings.packagist_username=Nombre de usuario Packagist diff --git a/options/locale/locale_fi-FI.ini b/options/locale/locale_fi-FI.ini index c6c64ad6ce..31dca19f33 100644 --- a/options/locale/locale_fi-FI.ini +++ b/options/locale/locale_fi-FI.ini @@ -1184,8 +1184,8 @@ settings.web_hook_name_discord=Discord settings.web_hook_name_dingtalk=DingTalk settings.web_hook_name_telegram=Telegram settings.web_hook_name_matrix=Matrix -settings.web_hook_name_feishu=Feishu -settings.web_hook_name_larksuite=Lark Suite +settings.web_hook_name_feishu_only =Feishu +settings.web_hook_name_larksuite_only =Lark Suite settings.web_hook_name_packagist=Packagist settings.deploy_keys=Julkaisuavaimet settings.add_deploy_key=Lisää julkaisuavain diff --git a/options/locale/locale_fr-FR.ini b/options/locale/locale_fr-FR.ini index 659615e6ff..d3e015a632 100644 --- a/options/locale/locale_fr-FR.ini +++ b/options/locale/locale_fr-FR.ini @@ -2317,9 +2317,9 @@ settings.web_hook_name_dingtalk=DingTalk settings.web_hook_name_telegram=Telegram settings.web_hook_name_matrix=Matrix settings.web_hook_name_msteams=Microsoft Teams -settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite -settings.web_hook_name_feishu=Feishu -settings.web_hook_name_larksuite=Lark Suite +settings.web_hook_name_feishu=Feishu / Lark Suite +settings.web_hook_name_feishu_only =Feishu +settings.web_hook_name_larksuite_only =Lark Suite settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_packagist=Packagist settings.packagist_username=Nom d'utilisateur Packagist diff --git a/options/locale/locale_is-IS.ini b/options/locale/locale_is-IS.ini index 27b9a4b17c..e76174cde2 100644 --- a/options/locale/locale_is-IS.ini +++ b/options/locale/locale_is-IS.ini @@ -1065,7 +1065,7 @@ settings.web_hook_name_discord=Discord settings.web_hook_name_dingtalk=DingTalk settings.web_hook_name_telegram=Telegram settings.web_hook_name_msteams=Microsoft Teams -settings.web_hook_name_feishu=Feishu +settings.web_hook_name_feishu_only =Feishu settings.title=Heiti settings.deploy_key_content=Innihald settings.branches=Greinar diff --git a/options/locale/locale_it-IT.ini b/options/locale/locale_it-IT.ini index dc6f4c127e..d25fc0942d 100644 --- a/options/locale/locale_it-IT.ini +++ b/options/locale/locale_it-IT.ini @@ -2085,9 +2085,9 @@ settings.web_hook_name_dingtalk=DingTalk settings.web_hook_name_telegram=Telegram settings.web_hook_name_matrix=Matrix settings.web_hook_name_msteams=Microsoft Teams -settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite -settings.web_hook_name_feishu=Feishu -settings.web_hook_name_larksuite=Lark Suite +settings.web_hook_name_feishu=Feishu / Lark Suite +settings.web_hook_name_feishu_only =Feishu +settings.web_hook_name_larksuite_only =Lark Suite settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_packagist=Packagist settings.packagist_username=Nome utente Packagist diff --git a/options/locale/locale_ja-JP.ini b/options/locale/locale_ja-JP.ini index b468041756..4fd6641dfd 100644 --- a/options/locale/locale_ja-JP.ini +++ b/options/locale/locale_ja-JP.ini @@ -2303,9 +2303,9 @@ settings.web_hook_name_dingtalk=DingTalk settings.web_hook_name_telegram=Telegram settings.web_hook_name_matrix=Matrix settings.web_hook_name_msteams=Microsoft Teams -settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite -settings.web_hook_name_feishu=Feishu -settings.web_hook_name_larksuite=Lark Suite +settings.web_hook_name_feishu=Feishu / Lark Suite +settings.web_hook_name_feishu_only =Feishu +settings.web_hook_name_larksuite_only =Lark Suite settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_packagist=Packagist settings.packagist_username=Packagist ユーザー名 diff --git a/options/locale/locale_lv-LV.ini b/options/locale/locale_lv-LV.ini index ce8f05e4b5..20ca341ee4 100644 --- a/options/locale/locale_lv-LV.ini +++ b/options/locale/locale_lv-LV.ini @@ -2253,9 +2253,9 @@ settings.web_hook_name_dingtalk=DingTalk settings.web_hook_name_telegram=Telegram settings.web_hook_name_matrix=Matrix settings.web_hook_name_msteams=Microsoft Teams -settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite -settings.web_hook_name_feishu=Feishu -settings.web_hook_name_larksuite=Lark Suite +settings.web_hook_name_feishu=Feishu / Lark Suite +settings.web_hook_name_feishu_only =Feishu +settings.web_hook_name_larksuite_only =Lark Suite settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_packagist=Packagist settings.packagist_username=Packagist lietotājvārds diff --git a/options/locale/locale_nl-NL.ini b/options/locale/locale_nl-NL.ini index b7fcfaa3d0..d0564d2ebd 100644 --- a/options/locale/locale_nl-NL.ini +++ b/options/locale/locale_nl-NL.ini @@ -2032,9 +2032,9 @@ settings.web_hook_name_dingtalk=DingTalk settings.web_hook_name_telegram=Telegram settings.web_hook_name_matrix=Matrix settings.web_hook_name_msteams=Microsoft Teams -settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite -settings.web_hook_name_feishu=Feishu -settings.web_hook_name_larksuite=Lark Suite +settings.web_hook_name_feishu=Feishu / Lark Suite +settings.web_hook_name_feishu_only =Feishu +settings.web_hook_name_larksuite_only =Lark Suite settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_packagist=Packagist settings.packagist_username=Packagist gebruikersnaam diff --git a/options/locale/locale_pt-BR.ini b/options/locale/locale_pt-BR.ini index 086cea74fa..f2a72c5c7f 100644 --- a/options/locale/locale_pt-BR.ini +++ b/options/locale/locale_pt-BR.ini @@ -2236,9 +2236,9 @@ settings.web_hook_name_dingtalk=DingTalk settings.web_hook_name_telegram=Telegram settings.web_hook_name_matrix=Matrix settings.web_hook_name_msteams=Microsoft Teams -settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite -settings.web_hook_name_feishu=Feishu -settings.web_hook_name_larksuite=Lark Suite +settings.web_hook_name_feishu=Feishu / Lark Suite +settings.web_hook_name_feishu_only =Feishu +settings.web_hook_name_larksuite_only =Lark Suite settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_packagist=Packagist settings.packagist_username=Nome de usuário no Packagist diff --git a/options/locale/locale_pt-PT.ini b/options/locale/locale_pt-PT.ini index 3538ac9460..552695a455 100644 --- a/options/locale/locale_pt-PT.ini +++ b/options/locale/locale_pt-PT.ini @@ -2269,9 +2269,9 @@ settings.web_hook_name_dingtalk=DingTalk settings.web_hook_name_telegram=Telegram settings.web_hook_name_matrix=Matrix settings.web_hook_name_msteams=Microsoft Teams -settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite -settings.web_hook_name_feishu=Feishu -settings.web_hook_name_larksuite=Lark Suite +settings.web_hook_name_feishu=Feishu / Lark Suite +settings.web_hook_name_feishu_only =Feishu +settings.web_hook_name_larksuite_only =Lark Suite settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_packagist=Packagist settings.packagist_username=Nome de utilizador no Packagist diff --git a/options/locale/locale_ru-RU.ini b/options/locale/locale_ru-RU.ini index eabd8b5b4d..e9daba082e 100644 --- a/options/locale/locale_ru-RU.ini +++ b/options/locale/locale_ru-RU.ini @@ -2278,9 +2278,9 @@ settings.web_hook_name_dingtalk=DingTalk settings.web_hook_name_telegram=Telegram settings.web_hook_name_matrix=Matrix settings.web_hook_name_msteams=Microsoft Teams -settings.web_hook_name_feishu_or_larksuite=Feishu или Lark Suite -settings.web_hook_name_feishu=Feishu -settings.web_hook_name_larksuite=Lark Suite +settings.web_hook_name_feishu=Feishu или Lark Suite +settings.web_hook_name_feishu_only =Feishu +settings.web_hook_name_larksuite_only =Lark Suite settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_packagist=Packagist settings.packagist_username=Имя пользователя Packagist diff --git a/options/locale/locale_tr-TR.ini b/options/locale/locale_tr-TR.ini index 74ef77eb19..b6bb510ab4 100644 --- a/options/locale/locale_tr-TR.ini +++ b/options/locale/locale_tr-TR.ini @@ -2252,9 +2252,9 @@ settings.web_hook_name_dingtalk=DingTalk settings.web_hook_name_telegram=Telegram settings.web_hook_name_matrix=Matrix settings.web_hook_name_msteams=Microsoft Teams -settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite -settings.web_hook_name_feishu=Feishu -settings.web_hook_name_larksuite=Lark Suite +settings.web_hook_name_feishu=Feishu / Lark Suite +settings.web_hook_name_feishu_only =Feishu +settings.web_hook_name_larksuite_only =Lark Suite settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_packagist=Packagist settings.packagist_username=Packagist kullanıcı adı diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 81cf9d6d07..c5a5aabb97 100644 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -2318,9 +2318,9 @@ settings.web_hook_name_dingtalk=钉钉 settings.web_hook_name_telegram=Telegram settings.web_hook_name_matrix=Matrix settings.web_hook_name_msteams=Microsoft Teams -settings.web_hook_name_feishu_or_larksuite=飞书 / Lark Suite -settings.web_hook_name_feishu=飞书 -settings.web_hook_name_larksuite=Lark Suite +settings.web_hook_name_feishu=飞书 / Lark Suite +settings.web_hook_name_feishu_only =飞书 +settings.web_hook_name_larksuite_only =Lark Suite settings.web_hook_name_wechatwork=企业微信 settings.web_hook_name_packagist=Packagist settings.packagist_username=Packagist 用户名 diff --git a/options/locale/locale_zh-TW.ini b/options/locale/locale_zh-TW.ini index 5bfff77fd2..a2e3f512ff 100644 --- a/options/locale/locale_zh-TW.ini +++ b/options/locale/locale_zh-TW.ini @@ -2071,9 +2071,9 @@ settings.web_hook_name_dingtalk=DingTalk settings.web_hook_name_telegram=Telegram settings.web_hook_name_matrix=Matrix settings.web_hook_name_msteams=Microsoft Teams -settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite -settings.web_hook_name_feishu=Feishu -settings.web_hook_name_larksuite=Lark Suite +settings.web_hook_name_feishu=Feishu / Lark Suite +settings.web_hook_name_feishu_only =Feishu +settings.web_hook_name_larksuite_only =Lark Suite settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_packagist=Packagist settings.packagist_username=Packagist 帳號 diff --git a/routers/web/org/setting.go b/routers/web/org/setting.go index 494ada4323..0be734abaf 100644 --- a/routers/web/org/setting.go +++ b/routers/web/org/setting.go @@ -26,6 +26,7 @@ import ( org_service "code.gitea.io/gitea/services/org" repo_service "code.gitea.io/gitea/services/repository" user_service "code.gitea.io/gitea/services/user" + webhook_service "code.gitea.io/gitea/services/webhook" ) const ( @@ -210,6 +211,7 @@ func Webhooks(ctx *context.Context) { ctx.Data["PageIsSettingsHooks"] = true ctx.Data["BaseLink"] = ctx.Org.OrgLink + "/settings/hooks" ctx.Data["BaseLinkNew"] = ctx.Org.OrgLink + "/settings/hooks" + ctx.Data["WebhookList"] = webhook_service.List() ctx.Data["Description"] = ctx.Tr("org.settings.hooks_desc") ws, err := db.Find[webhook.Webhook](ctx, webhook.ListWebhookOptions{OwnerID: ctx.Org.Organization.ID}) diff --git a/routers/web/repo/setting/webhook.go b/routers/web/repo/setting/webhook.go index bf7770bfdb..bfe1a60016 100644 --- a/routers/web/repo/setting/webhook.go +++ b/routers/web/repo/setting/webhook.go @@ -45,6 +45,7 @@ func WebhookList(ctx *context.Context) { ctx.Data["PageIsSettingsHooks"] = true ctx.Data["BaseLink"] = ctx.Repo.RepoLink + "/settings/hooks" ctx.Data["BaseLinkNew"] = ctx.Repo.RepoLink + "/settings/hooks" + ctx.Data["WebhookList"] = webhook_service.List() ctx.Data["Description"] = ctx.Tr("repo.settings.hooks_desc", "https://forgejo.org/docs/latest/user/webhooks/") ws, err := db.Find[webhook.Webhook](ctx, webhook.ListWebhookOptions{RepoID: ctx.Repo.Repository.ID}) @@ -139,6 +140,7 @@ func WebhookNew(ctx *context.Context) { ctx.Data["HookType"] = hookType ctx.Data["BaseLink"] = orCtx.LinkNew ctx.Data["BaseLinkNew"] = orCtx.LinkNew + ctx.Data["WebhookList"] = webhook_service.List() ctx.HTML(http.StatusOK, orCtx.NewTemplate) } @@ -202,6 +204,7 @@ func WebhookCreate(ctx *context.Context) { } ctx.Data["BaseLink"] = orCtx.LinkNew ctx.Data["BaseLinkNew"] = orCtx.LinkNew + ctx.Data["WebhookList"] = webhook_service.List() if ctx.HasError() { // pre-fill the form with the submitted data @@ -336,6 +339,7 @@ func checkWebhook(ctx *context.Context) (*ownerRepoCtx, *webhook.Webhook) { } ctx.Data["BaseLink"] = orCtx.Link ctx.Data["BaseLinkNew"] = orCtx.LinkNew + ctx.Data["WebhookList"] = webhook_service.List() var w *webhook.Webhook if orCtx.RepoID > 0 { diff --git a/routers/web/user/setting/webhooks.go b/routers/web/user/setting/webhooks.go index 4423b62781..3cc67d9def 100644 --- a/routers/web/user/setting/webhooks.go +++ b/routers/web/user/setting/webhooks.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/services/context" + webhook_service "code.gitea.io/gitea/services/webhook" ) const ( @@ -23,6 +24,7 @@ func Webhooks(ctx *context.Context) { ctx.Data["PageIsSettingsHooks"] = true ctx.Data["BaseLink"] = setting.AppSubURL + "/user/settings/hooks" ctx.Data["BaseLinkNew"] = setting.AppSubURL + "/user/settings/hooks" + ctx.Data["WebhookList"] = webhook_service.List() ctx.Data["Description"] = ctx.Tr("settings.hooks.desc") ws, err := db.Find[webhook.Webhook](ctx, webhook.ListWebhookOptions{OwnerID: ctx.Doer.ID}) diff --git a/templates/repo/settings/webhook/link_menu.tmpl b/templates/repo/settings/webhook/link_menu.tmpl index 811e262db6..2edc5af4ac 100644 --- a/templates/repo/settings/webhook/link_menu.tmpl +++ b/templates/repo/settings/webhook/link_menu.tmpl @@ -3,52 +3,10 @@ {{$size = .Size}} {{end}} diff --git a/templates/webhook/new/feishu.tmpl b/templates/webhook/new/feishu.tmpl index b691c3f18c..ead11770de 100644 --- a/templates/webhook/new/feishu.tmpl +++ b/templates/webhook/new/feishu.tmpl @@ -1,5 +1,5 @@ -

{{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")}}

+

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

+

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

{{.CsrfTokenHtml}}
From 84eeab59afd33c3406e35f5bd16ede62a120d89b Mon Sep 17 00:00:00 2001 From: oliverpool Date: Fri, 22 Mar 2024 16:02:48 +0100 Subject: [PATCH 2/2] [REFACTOR] add Icon to webhook.Interface --- routers/web/repo/setting/webhook.go | 6 +++++- services/webhook/default.go | 10 ++++++++++ services/webhook/dingtalk.go | 3 +++ services/webhook/discord.go | 2 ++ services/webhook/feishu.go | 2 ++ services/webhook/general.go | 8 ++++++++ services/webhook/gogs.go | 2 ++ services/webhook/matrix.go | 6 ++++++ services/webhook/msteams.go | 2 ++ services/webhook/packagist.go | 2 ++ services/webhook/slack.go | 2 ++ services/webhook/telegram.go | 2 ++ services/webhook/webhook.go | 2 ++ services/webhook/wechatwork.go | 5 +++++ templates/webhook/new.tmpl | 2 +- 15 files changed, 54 insertions(+), 2 deletions(-) diff --git a/routers/web/repo/setting/webhook.go b/routers/web/repo/setting/webhook.go index bfe1a60016..4469eac9e8 100644 --- a/routers/web/repo/setting/webhook.go +++ b/routers/web/repo/setting/webhook.go @@ -133,11 +133,13 @@ func WebhookNew(ctx *context.Context) { } hookType := ctx.Params(":type") - if webhook_service.GetWebhookHandler(hookType) == nil { + handler := webhook_service.GetWebhookHandler(hookType) + if handler == nil { ctx.NotFound("GetWebhookHandler", nil) return } ctx.Data["HookType"] = hookType + ctx.Data["WebhookHandler"] = handler ctx.Data["BaseLink"] = orCtx.LinkNew ctx.Data["BaseLinkNew"] = orCtx.LinkNew ctx.Data["WebhookList"] = webhook_service.List() @@ -196,6 +198,7 @@ func WebhookCreate(ctx *context.Context) { ctx.Data["PageIsSettingsHooksNew"] = true ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook_module.HookEvent{}} ctx.Data["HookType"] = hookType + ctx.Data["WebhookHandler"] = handler orCtx, err := getOwnerRepoCtx(ctx) if err != nil { @@ -362,6 +365,7 @@ func checkWebhook(ctx *context.Context) (*ownerRepoCtx, *webhook.Webhook) { if handler := webhook_service.GetWebhookHandler(w.Type); handler != nil { ctx.Data["HookMetadata"] = handler.Metadata(w) + ctx.Data["WebhookHandler"] = handler } ctx.Data["History"], err = w.History(ctx, 1) diff --git a/services/webhook/default.go b/services/webhook/default.go index f725f8a783..be3b9b3c73 100644 --- a/services/webhook/default.go +++ b/services/webhook/default.go @@ -10,6 +10,7 @@ import ( "crypto/sha256" "encoding/hex" "fmt" + "html/template" "io" "net/http" "net/url" @@ -17,6 +18,7 @@ import ( webhook_model "code.gitea.io/gitea/models/webhook" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/svg" webhook_module "code.gitea.io/gitea/modules/webhook" "code.gitea.io/gitea/services/forms" ) @@ -34,6 +36,14 @@ func (dh defaultHandler) Type() webhook_module.HookType { return webhook_module.GITEA } +func (dh defaultHandler) Icon(size int) template.HTML { + if dh.forgejo { + // forgejo.svg is not in web_src/svg/, so svg.RenderHTML does not work + return imgIcon("forgejo.svg", size) + } + return svg.RenderHTML("gitea-gitea", size, "img") +} + func (defaultHandler) Metadata(*webhook_model.Webhook) any { return nil } func (defaultHandler) FormFields(bind func(any)) FormFields { diff --git a/services/webhook/dingtalk.go b/services/webhook/dingtalk.go index f4bc715e08..0a0160ac46 100644 --- a/services/webhook/dingtalk.go +++ b/services/webhook/dingtalk.go @@ -6,6 +6,7 @@ package webhook import ( "context" "fmt" + "html/template" "net/http" "net/url" "strings" @@ -22,6 +23,8 @@ type dingtalkHandler struct{} func (dingtalkHandler) Type() webhook_module.HookType { return webhook_module.DINGTALK } func (dingtalkHandler) Metadata(*webhook_model.Webhook) any { return nil } +func (dingtalkHandler) Icon(size int) template.HTML { return imgIcon("dingtalk.ico", size) } + func (dingtalkHandler) FormFields(bind func(any)) FormFields { var form struct { forms.WebhookForm diff --git a/services/webhook/discord.go b/services/webhook/discord.go index 3a0a973860..2efb46f5bb 100644 --- a/services/webhook/discord.go +++ b/services/webhook/discord.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + "html/template" "net/http" "net/url" "strconv" @@ -26,6 +27,7 @@ import ( type discordHandler struct{} func (discordHandler) Type() webhook_module.HookType { return webhook_module.DISCORD } +func (discordHandler) Icon(size int) template.HTML { return imgIcon("discord.png", size) } func (discordHandler) FormFields(bind func(any)) FormFields { var form struct { diff --git a/services/webhook/feishu.go b/services/webhook/feishu.go index b27acc9070..eba54fa09b 100644 --- a/services/webhook/feishu.go +++ b/services/webhook/feishu.go @@ -6,6 +6,7 @@ package webhook import ( "context" "fmt" + "html/template" "net/http" "strings" @@ -19,6 +20,7 @@ import ( type feishuHandler struct{} func (feishuHandler) Type() webhook_module.HookType { return webhook_module.FEISHU } +func (feishuHandler) Icon(size int) template.HTML { return imgIcon("feishu.png", size) } func (feishuHandler) FormFields(bind func(any)) FormFields { var form struct { diff --git a/services/webhook/general.go b/services/webhook/general.go index c41f58fe8d..454efc6495 100644 --- a/services/webhook/general.go +++ b/services/webhook/general.go @@ -6,7 +6,9 @@ package webhook import ( "fmt" "html" + "html/template" "net/url" + "strconv" "strings" webhook_model "code.gitea.io/gitea/models/webhook" @@ -352,3 +354,9 @@ func ToHook(repoLink string, w *webhook_model.Webhook) (*api.Hook, error) { Created: w.CreatedUnix.AsTime(), }, nil } + +func imgIcon(name string, size int) template.HTML { + s := strconv.Itoa(size) + src := html.EscapeString(setting.StaticURLPrefix + "/assets/img/" + name) + return template.HTML(``) +} diff --git a/services/webhook/gogs.go b/services/webhook/gogs.go index e23673ed35..f616f5e2f3 100644 --- a/services/webhook/gogs.go +++ b/services/webhook/gogs.go @@ -4,6 +4,7 @@ package webhook import ( + "html/template" "net/http" webhook_model "code.gitea.io/gitea/models/webhook" @@ -14,6 +15,7 @@ import ( type gogsHandler struct{ defaultHandler } func (gogsHandler) Type() webhook_module.HookType { return webhook_module.GOGS } +func (gogsHandler) Icon(size int) template.HTML { return imgIcon("gogs.ico", size) } func (gogsHandler) FormFields(bind func(any)) FormFields { var form struct { diff --git a/services/webhook/matrix.go b/services/webhook/matrix.go index d04f0f367f..322b4d6665 100644 --- a/services/webhook/matrix.go +++ b/services/webhook/matrix.go @@ -9,6 +9,7 @@ import ( "crypto/sha1" "encoding/hex" "fmt" + "html/template" "net/http" "net/url" "regexp" @@ -20,6 +21,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/svg" "code.gitea.io/gitea/modules/util" webhook_module "code.gitea.io/gitea/modules/webhook" "code.gitea.io/gitea/services/forms" @@ -29,6 +31,10 @@ type matrixHandler struct{} func (matrixHandler) Type() webhook_module.HookType { return webhook_module.MATRIX } +func (matrixHandler) Icon(size int) template.HTML { + return svg.RenderHTML("gitea-matrix", size, "img") +} + func (matrixHandler) FormFields(bind func(any)) FormFields { var form struct { forms.WebhookForm diff --git a/services/webhook/msteams.go b/services/webhook/msteams.go index 849093e9bf..940a6c49aa 100644 --- a/services/webhook/msteams.go +++ b/services/webhook/msteams.go @@ -6,6 +6,7 @@ package webhook import ( "context" "fmt" + "html/template" "net/http" "net/url" "strings" @@ -22,6 +23,7 @@ type msteamsHandler struct{} func (msteamsHandler) Type() webhook_module.HookType { return webhook_module.MSTEAMS } func (msteamsHandler) Metadata(*webhook_model.Webhook) any { return nil } +func (msteamsHandler) Icon(size int) template.HTML { return imgIcon("msteams.png", size) } func (msteamsHandler) FormFields(bind func(any)) FormFields { var form struct { diff --git a/services/webhook/packagist.go b/services/webhook/packagist.go index d8bf9ea23a..f1f3306109 100644 --- a/services/webhook/packagist.go +++ b/services/webhook/packagist.go @@ -6,6 +6,7 @@ package webhook import ( "context" "fmt" + "html/template" "net/http" "net/url" @@ -19,6 +20,7 @@ import ( type packagistHandler struct{} func (packagistHandler) Type() webhook_module.HookType { return webhook_module.PACKAGIST } +func (packagistHandler) Icon(size int) template.HTML { return imgIcon("packagist.png", size) } func (packagistHandler) FormFields(bind func(any)) FormFields { var form struct { diff --git a/services/webhook/slack.go b/services/webhook/slack.go index 683ef41019..0b4c4b6645 100644 --- a/services/webhook/slack.go +++ b/services/webhook/slack.go @@ -6,6 +6,7 @@ package webhook import ( "context" "fmt" + "html/template" "net/http" "regexp" "strings" @@ -26,6 +27,7 @@ import ( type slackHandler struct{} func (slackHandler) Type() webhook_module.HookType { return webhook_module.SLACK } +func (slackHandler) Icon(size int) template.HTML { return imgIcon("slack.png", size) } type slackForm struct { forms.WebhookForm diff --git a/services/webhook/telegram.go b/services/webhook/telegram.go index 2ede28dbd2..daa986bafb 100644 --- a/services/webhook/telegram.go +++ b/services/webhook/telegram.go @@ -6,6 +6,7 @@ package webhook import ( "context" "fmt" + "html/template" "net/http" "net/url" "strings" @@ -22,6 +23,7 @@ import ( type telegramHandler struct{} func (telegramHandler) Type() webhook_module.HookType { return webhook_module.TELEGRAM } +func (telegramHandler) Icon(size int) template.HTML { return imgIcon("telegram.png", size) } func (telegramHandler) FormFields(bind func(any)) FormFields { var form struct { diff --git a/services/webhook/webhook.go b/services/webhook/webhook.go index a7802d27dc..f27bffc29a 100644 --- a/services/webhook/webhook.go +++ b/services/webhook/webhook.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + "html/template" "net/http" "strings" @@ -35,6 +36,7 @@ type Handler interface { // If form implements the [binding.Validator] interface, the Validate method will be called FormFields(bind func(form any)) FormFields NewRequest(context.Context, *webhook_model.Webhook, *webhook_model.HookTask) (req *http.Request, body []byte, err error) + Icon(size int) template.HTML } type FormFields struct { diff --git a/services/webhook/wechatwork.go b/services/webhook/wechatwork.go index 2ad2acd018..eff5b9b526 100644 --- a/services/webhook/wechatwork.go +++ b/services/webhook/wechatwork.go @@ -6,6 +6,7 @@ package webhook import ( "context" "fmt" + "html/template" "net/http" "strings" @@ -21,6 +22,10 @@ type wechatworkHandler struct{} func (wechatworkHandler) Type() webhook_module.HookType { return webhook_module.WECHATWORK } func (wechatworkHandler) Metadata(*webhook_model.Webhook) any { return nil } +func (wechatworkHandler) Icon(size int) template.HTML { + return imgIcon("wechatwork.png", size) +} + func (wechatworkHandler) FormFields(bind func(any)) FormFields { var form struct { forms.WebhookForm diff --git a/templates/webhook/new.tmpl b/templates/webhook/new.tmpl index 17eb578b0e..8afdb1fa5d 100644 --- a/templates/webhook/new.tmpl +++ b/templates/webhook/new.tmpl @@ -2,7 +2,7 @@ {{.CustomHeaderTitle}}