Merge pull request '[REFACTOR] add Icon to webhook.Interface' (#2908) from oliverpool/forgejo:webhook_6_icon_method into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2908
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2024-03-31 06:22:51 +00:00
commit ae96a5e725
39 changed files with 124 additions and 107 deletions

View file

@ -341,5 +341,4 @@ package "code.gitea.io/gitea/services/repository/files"
package "code.gitea.io/gitea/services/webhook" package "code.gitea.io/gitea/services/webhook"
func NewNotifier func NewNotifier
func List

View file

@ -935,9 +935,9 @@ settings.web_hook_name_discord = Discord
settings.web_hook_name_telegram = Telegram settings.web_hook_name_telegram = Telegram
settings.web_hook_name_matrix = Matrix settings.web_hook_name_matrix = Matrix
settings.web_hook_name_gogs = Gogs settings.web_hook_name_gogs = Gogs
settings.web_hook_name_feishu_or_larksuite = Feishu / Lark Suite settings.web_hook_name_feishu = Feishu / Lark Suite
settings.web_hook_name_feishu = Feishu settings.web_hook_name_feishu_only = Feishu
settings.web_hook_name_larksuite = Lark Suite settings.web_hook_name_larksuite_only = Lark Suite
settings.web_hook_name_wechatwork = WeCom (Wechat Work) settings.web_hook_name_wechatwork = WeCom (Wechat Work)
settings.web_hook_name_packagist = Packagist settings.web_hook_name_packagist = Packagist
diff.file_byte_size = Размер diff.file_byte_size = Размер

View file

@ -2308,9 +2308,9 @@ settings.web_hook_name_dingtalk=DingTalk
settings.web_hook_name_telegram=Telegram settings.web_hook_name_telegram=Telegram
settings.web_hook_name_matrix=Matrix settings.web_hook_name_matrix=Matrix
settings.web_hook_name_msteams=Microsoft Teams settings.web_hook_name_msteams=Microsoft Teams
settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite settings.web_hook_name_feishu=Feishu / Lark Suite
settings.web_hook_name_feishu=Feishu settings.web_hook_name_feishu_only =Feishu
settings.web_hook_name_larksuite=Lark Suite settings.web_hook_name_larksuite_only =Lark Suite
settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_wechatwork=WeCom (Wechat Work)
settings.web_hook_name_packagist=Packagist settings.web_hook_name_packagist=Packagist
settings.packagist_username=Uživatelské jméno pro Packagist settings.packagist_username=Uživatelské jméno pro Packagist

View file

@ -2304,9 +2304,9 @@ settings.web_hook_name_dingtalk=DingTalk
settings.web_hook_name_telegram=Telegram settings.web_hook_name_telegram=Telegram
settings.web_hook_name_matrix=Matrix settings.web_hook_name_matrix=Matrix
settings.web_hook_name_msteams=Microsoft Teams settings.web_hook_name_msteams=Microsoft Teams
settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite settings.web_hook_name_feishu=Feishu / Lark Suite
settings.web_hook_name_feishu=Feishu settings.web_hook_name_feishu_only =Feishu
settings.web_hook_name_larksuite=Lark Suite settings.web_hook_name_larksuite_only =Lark Suite
settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_wechatwork=WeCom (Wechat Work)
settings.web_hook_name_packagist=Packagist settings.web_hook_name_packagist=Packagist
settings.packagist_username=Benutzername für Packagist settings.packagist_username=Benutzername für Packagist

View file

@ -2293,9 +2293,9 @@ settings.web_hook_name_dingtalk=DingTalk
settings.web_hook_name_telegram=Telegram settings.web_hook_name_telegram=Telegram
settings.web_hook_name_matrix=Matrix settings.web_hook_name_matrix=Matrix
settings.web_hook_name_msteams=Microsoft Teams settings.web_hook_name_msteams=Microsoft Teams
settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite settings.web_hook_name_feishu=Feishu / Lark Suite
settings.web_hook_name_feishu=Feishu settings.web_hook_name_feishu_only =Feishu
settings.web_hook_name_larksuite=Lark Suite settings.web_hook_name_larksuite_only =Lark Suite
settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_wechatwork=WeCom (Wechat Work)
settings.web_hook_name_packagist=Packagist settings.web_hook_name_packagist=Packagist
settings.packagist_username=Όνομα χρήστη Packagist settings.packagist_username=Όνομα χρήστη Packagist

View file

@ -2372,9 +2372,9 @@ settings.web_hook_name_dingtalk = DingTalk
settings.web_hook_name_telegram = Telegram settings.web_hook_name_telegram = Telegram
settings.web_hook_name_matrix = Matrix settings.web_hook_name_matrix = Matrix
settings.web_hook_name_msteams = Microsoft Teams settings.web_hook_name_msteams = Microsoft Teams
settings.web_hook_name_feishu_or_larksuite = Feishu / Lark Suite settings.web_hook_name_feishu = Feishu / Lark Suite
settings.web_hook_name_feishu = Feishu settings.web_hook_name_feishu_only = Feishu
settings.web_hook_name_larksuite = Lark Suite settings.web_hook_name_larksuite_only = Lark Suite
settings.web_hook_name_wechatwork = WeCom (Wechat Work) settings.web_hook_name_wechatwork = WeCom (Wechat Work)
settings.web_hook_name_packagist = Packagist settings.web_hook_name_packagist = Packagist
settings.packagist_username = Packagist username settings.packagist_username = Packagist username

View file

@ -2267,9 +2267,9 @@ settings.web_hook_name_dingtalk=DingTalk
settings.web_hook_name_telegram=Telegram settings.web_hook_name_telegram=Telegram
settings.web_hook_name_matrix=Matrix settings.web_hook_name_matrix=Matrix
settings.web_hook_name_msteams=Microsoft Teams settings.web_hook_name_msteams=Microsoft Teams
settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite settings.web_hook_name_feishu=Feishu / Lark Suite
settings.web_hook_name_feishu=Feishu settings.web_hook_name_feishu_only =Feishu
settings.web_hook_name_larksuite=Lark Suite settings.web_hook_name_larksuite_only =Lark Suite
settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_wechatwork=WeCom (Wechat Work)
settings.web_hook_name_packagist=Packagist settings.web_hook_name_packagist=Packagist
settings.packagist_username=Nombre de usuario Packagist settings.packagist_username=Nombre de usuario Packagist

View file

@ -1184,8 +1184,8 @@ settings.web_hook_name_discord=Discord
settings.web_hook_name_dingtalk=DingTalk settings.web_hook_name_dingtalk=DingTalk
settings.web_hook_name_telegram=Telegram settings.web_hook_name_telegram=Telegram
settings.web_hook_name_matrix=Matrix settings.web_hook_name_matrix=Matrix
settings.web_hook_name_feishu=Feishu settings.web_hook_name_feishu_only =Feishu
settings.web_hook_name_larksuite=Lark Suite settings.web_hook_name_larksuite_only =Lark Suite
settings.web_hook_name_packagist=Packagist settings.web_hook_name_packagist=Packagist
settings.deploy_keys=Julkaisuavaimet settings.deploy_keys=Julkaisuavaimet
settings.add_deploy_key=Lisää julkaisuavain settings.add_deploy_key=Lisää julkaisuavain

View file

@ -2317,9 +2317,9 @@ settings.web_hook_name_dingtalk=DingTalk
settings.web_hook_name_telegram=Telegram settings.web_hook_name_telegram=Telegram
settings.web_hook_name_matrix=Matrix settings.web_hook_name_matrix=Matrix
settings.web_hook_name_msteams=Microsoft Teams settings.web_hook_name_msteams=Microsoft Teams
settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite settings.web_hook_name_feishu=Feishu / Lark Suite
settings.web_hook_name_feishu=Feishu settings.web_hook_name_feishu_only =Feishu
settings.web_hook_name_larksuite=Lark Suite settings.web_hook_name_larksuite_only =Lark Suite
settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_wechatwork=WeCom (Wechat Work)
settings.web_hook_name_packagist=Packagist settings.web_hook_name_packagist=Packagist
settings.packagist_username=Nom d'utilisateur Packagist settings.packagist_username=Nom d'utilisateur Packagist

View file

@ -1065,7 +1065,7 @@ settings.web_hook_name_discord=Discord
settings.web_hook_name_dingtalk=DingTalk settings.web_hook_name_dingtalk=DingTalk
settings.web_hook_name_telegram=Telegram settings.web_hook_name_telegram=Telegram
settings.web_hook_name_msteams=Microsoft Teams settings.web_hook_name_msteams=Microsoft Teams
settings.web_hook_name_feishu=Feishu settings.web_hook_name_feishu_only =Feishu
settings.title=Heiti settings.title=Heiti
settings.deploy_key_content=Innihald settings.deploy_key_content=Innihald
settings.branches=Greinar settings.branches=Greinar

View file

@ -2085,9 +2085,9 @@ settings.web_hook_name_dingtalk=DingTalk
settings.web_hook_name_telegram=Telegram settings.web_hook_name_telegram=Telegram
settings.web_hook_name_matrix=Matrix settings.web_hook_name_matrix=Matrix
settings.web_hook_name_msteams=Microsoft Teams settings.web_hook_name_msteams=Microsoft Teams
settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite settings.web_hook_name_feishu=Feishu / Lark Suite
settings.web_hook_name_feishu=Feishu settings.web_hook_name_feishu_only =Feishu
settings.web_hook_name_larksuite=Lark Suite settings.web_hook_name_larksuite_only =Lark Suite
settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_wechatwork=WeCom (Wechat Work)
settings.web_hook_name_packagist=Packagist settings.web_hook_name_packagist=Packagist
settings.packagist_username=Nome utente Packagist settings.packagist_username=Nome utente Packagist

View file

@ -2303,9 +2303,9 @@ settings.web_hook_name_dingtalk=DingTalk
settings.web_hook_name_telegram=Telegram settings.web_hook_name_telegram=Telegram
settings.web_hook_name_matrix=Matrix settings.web_hook_name_matrix=Matrix
settings.web_hook_name_msteams=Microsoft Teams settings.web_hook_name_msteams=Microsoft Teams
settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite settings.web_hook_name_feishu=Feishu / Lark Suite
settings.web_hook_name_feishu=Feishu settings.web_hook_name_feishu_only =Feishu
settings.web_hook_name_larksuite=Lark Suite settings.web_hook_name_larksuite_only =Lark Suite
settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_wechatwork=WeCom (Wechat Work)
settings.web_hook_name_packagist=Packagist settings.web_hook_name_packagist=Packagist
settings.packagist_username=Packagist ユーザー名 settings.packagist_username=Packagist ユーザー名

View file

@ -2253,9 +2253,9 @@ settings.web_hook_name_dingtalk=DingTalk
settings.web_hook_name_telegram=Telegram settings.web_hook_name_telegram=Telegram
settings.web_hook_name_matrix=Matrix settings.web_hook_name_matrix=Matrix
settings.web_hook_name_msteams=Microsoft Teams settings.web_hook_name_msteams=Microsoft Teams
settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite settings.web_hook_name_feishu=Feishu / Lark Suite
settings.web_hook_name_feishu=Feishu settings.web_hook_name_feishu_only =Feishu
settings.web_hook_name_larksuite=Lark Suite settings.web_hook_name_larksuite_only =Lark Suite
settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_wechatwork=WeCom (Wechat Work)
settings.web_hook_name_packagist=Packagist settings.web_hook_name_packagist=Packagist
settings.packagist_username=Packagist lietotājvārds settings.packagist_username=Packagist lietotājvārds

View file

@ -2032,9 +2032,9 @@ settings.web_hook_name_dingtalk=DingTalk
settings.web_hook_name_telegram=Telegram settings.web_hook_name_telegram=Telegram
settings.web_hook_name_matrix=Matrix settings.web_hook_name_matrix=Matrix
settings.web_hook_name_msteams=Microsoft Teams settings.web_hook_name_msteams=Microsoft Teams
settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite settings.web_hook_name_feishu=Feishu / Lark Suite
settings.web_hook_name_feishu=Feishu settings.web_hook_name_feishu_only =Feishu
settings.web_hook_name_larksuite=Lark Suite settings.web_hook_name_larksuite_only =Lark Suite
settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_wechatwork=WeCom (Wechat Work)
settings.web_hook_name_packagist=Packagist settings.web_hook_name_packagist=Packagist
settings.packagist_username=Packagist gebruikersnaam settings.packagist_username=Packagist gebruikersnaam

View file

@ -2236,9 +2236,9 @@ settings.web_hook_name_dingtalk=DingTalk
settings.web_hook_name_telegram=Telegram settings.web_hook_name_telegram=Telegram
settings.web_hook_name_matrix=Matrix settings.web_hook_name_matrix=Matrix
settings.web_hook_name_msteams=Microsoft Teams settings.web_hook_name_msteams=Microsoft Teams
settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite settings.web_hook_name_feishu=Feishu / Lark Suite
settings.web_hook_name_feishu=Feishu settings.web_hook_name_feishu_only =Feishu
settings.web_hook_name_larksuite=Lark Suite settings.web_hook_name_larksuite_only =Lark Suite
settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_wechatwork=WeCom (Wechat Work)
settings.web_hook_name_packagist=Packagist settings.web_hook_name_packagist=Packagist
settings.packagist_username=Nome de usuário no Packagist settings.packagist_username=Nome de usuário no Packagist

View file

@ -2269,9 +2269,9 @@ settings.web_hook_name_dingtalk=DingTalk
settings.web_hook_name_telegram=Telegram settings.web_hook_name_telegram=Telegram
settings.web_hook_name_matrix=Matrix settings.web_hook_name_matrix=Matrix
settings.web_hook_name_msteams=Microsoft Teams settings.web_hook_name_msteams=Microsoft Teams
settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite settings.web_hook_name_feishu=Feishu / Lark Suite
settings.web_hook_name_feishu=Feishu settings.web_hook_name_feishu_only =Feishu
settings.web_hook_name_larksuite=Lark Suite settings.web_hook_name_larksuite_only =Lark Suite
settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_wechatwork=WeCom (Wechat Work)
settings.web_hook_name_packagist=Packagist settings.web_hook_name_packagist=Packagist
settings.packagist_username=Nome de utilizador no Packagist settings.packagist_username=Nome de utilizador no Packagist

View file

@ -2278,9 +2278,9 @@ settings.web_hook_name_dingtalk=DingTalk
settings.web_hook_name_telegram=Telegram settings.web_hook_name_telegram=Telegram
settings.web_hook_name_matrix=Matrix settings.web_hook_name_matrix=Matrix
settings.web_hook_name_msteams=Microsoft Teams settings.web_hook_name_msteams=Microsoft Teams
settings.web_hook_name_feishu_or_larksuite=Feishu или Lark Suite settings.web_hook_name_feishu=Feishu или Lark Suite
settings.web_hook_name_feishu=Feishu settings.web_hook_name_feishu_only =Feishu
settings.web_hook_name_larksuite=Lark Suite settings.web_hook_name_larksuite_only =Lark Suite
settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_wechatwork=WeCom (Wechat Work)
settings.web_hook_name_packagist=Packagist settings.web_hook_name_packagist=Packagist
settings.packagist_username=Имя пользователя Packagist settings.packagist_username=Имя пользователя Packagist

View file

@ -2252,9 +2252,9 @@ settings.web_hook_name_dingtalk=DingTalk
settings.web_hook_name_telegram=Telegram settings.web_hook_name_telegram=Telegram
settings.web_hook_name_matrix=Matrix settings.web_hook_name_matrix=Matrix
settings.web_hook_name_msteams=Microsoft Teams settings.web_hook_name_msteams=Microsoft Teams
settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite settings.web_hook_name_feishu=Feishu / Lark Suite
settings.web_hook_name_feishu=Feishu settings.web_hook_name_feishu_only =Feishu
settings.web_hook_name_larksuite=Lark Suite settings.web_hook_name_larksuite_only =Lark Suite
settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_wechatwork=WeCom (Wechat Work)
settings.web_hook_name_packagist=Packagist settings.web_hook_name_packagist=Packagist
settings.packagist_username=Packagist kullanıcı adı settings.packagist_username=Packagist kullanıcı adı

View file

@ -2318,9 +2318,9 @@ settings.web_hook_name_dingtalk=钉钉
settings.web_hook_name_telegram=Telegram settings.web_hook_name_telegram=Telegram
settings.web_hook_name_matrix=Matrix settings.web_hook_name_matrix=Matrix
settings.web_hook_name_msteams=Microsoft Teams settings.web_hook_name_msteams=Microsoft Teams
settings.web_hook_name_feishu_or_larksuite=飞书 / Lark Suite settings.web_hook_name_feishu=飞书 / Lark Suite
settings.web_hook_name_feishu=飞书 settings.web_hook_name_feishu_only =飞书
settings.web_hook_name_larksuite=Lark Suite settings.web_hook_name_larksuite_only =Lark Suite
settings.web_hook_name_wechatwork=企业微信 settings.web_hook_name_wechatwork=企业微信
settings.web_hook_name_packagist=Packagist settings.web_hook_name_packagist=Packagist
settings.packagist_username=Packagist 用户名 settings.packagist_username=Packagist 用户名

View file

@ -2071,9 +2071,9 @@ settings.web_hook_name_dingtalk=DingTalk
settings.web_hook_name_telegram=Telegram settings.web_hook_name_telegram=Telegram
settings.web_hook_name_matrix=Matrix settings.web_hook_name_matrix=Matrix
settings.web_hook_name_msteams=Microsoft Teams settings.web_hook_name_msteams=Microsoft Teams
settings.web_hook_name_feishu_or_larksuite=Feishu / Lark Suite settings.web_hook_name_feishu=Feishu / Lark Suite
settings.web_hook_name_feishu=Feishu settings.web_hook_name_feishu_only =Feishu
settings.web_hook_name_larksuite=Lark Suite settings.web_hook_name_larksuite_only =Lark Suite
settings.web_hook_name_wechatwork=WeCom (Wechat Work) settings.web_hook_name_wechatwork=WeCom (Wechat Work)
settings.web_hook_name_packagist=Packagist settings.web_hook_name_packagist=Packagist
settings.packagist_username=Packagist 帳號 settings.packagist_username=Packagist 帳號

View file

@ -26,6 +26,7 @@ import (
org_service "code.gitea.io/gitea/services/org" org_service "code.gitea.io/gitea/services/org"
repo_service "code.gitea.io/gitea/services/repository" repo_service "code.gitea.io/gitea/services/repository"
user_service "code.gitea.io/gitea/services/user" user_service "code.gitea.io/gitea/services/user"
webhook_service "code.gitea.io/gitea/services/webhook"
) )
const ( const (
@ -210,6 +211,7 @@ func Webhooks(ctx *context.Context) {
ctx.Data["PageIsSettingsHooks"] = true ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["BaseLink"] = ctx.Org.OrgLink + "/settings/hooks" ctx.Data["BaseLink"] = ctx.Org.OrgLink + "/settings/hooks"
ctx.Data["BaseLinkNew"] = 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") ctx.Data["Description"] = ctx.Tr("org.settings.hooks_desc")
ws, err := db.Find[webhook.Webhook](ctx, webhook.ListWebhookOptions{OwnerID: ctx.Org.Organization.ID}) ws, err := db.Find[webhook.Webhook](ctx, webhook.ListWebhookOptions{OwnerID: ctx.Org.Organization.ID})

View file

@ -45,6 +45,7 @@ func WebhookList(ctx *context.Context) {
ctx.Data["PageIsSettingsHooks"] = true ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["BaseLink"] = ctx.Repo.RepoLink + "/settings/hooks" ctx.Data["BaseLink"] = ctx.Repo.RepoLink + "/settings/hooks"
ctx.Data["BaseLinkNew"] = 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/") 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}) ws, err := db.Find[webhook.Webhook](ctx, webhook.ListWebhookOptions{RepoID: ctx.Repo.Repository.ID})
@ -132,13 +133,16 @@ func WebhookNew(ctx *context.Context) {
} }
hookType := ctx.Params(":type") hookType := ctx.Params(":type")
if webhook_service.GetWebhookHandler(hookType) == nil { handler := webhook_service.GetWebhookHandler(hookType)
if handler == nil {
ctx.NotFound("GetWebhookHandler", nil) ctx.NotFound("GetWebhookHandler", nil)
return return
} }
ctx.Data["HookType"] = hookType ctx.Data["HookType"] = hookType
ctx.Data["WebhookHandler"] = handler
ctx.Data["BaseLink"] = orCtx.LinkNew ctx.Data["BaseLink"] = orCtx.LinkNew
ctx.Data["BaseLinkNew"] = orCtx.LinkNew ctx.Data["BaseLinkNew"] = orCtx.LinkNew
ctx.Data["WebhookList"] = webhook_service.List()
ctx.HTML(http.StatusOK, orCtx.NewTemplate) ctx.HTML(http.StatusOK, orCtx.NewTemplate)
} }
@ -194,6 +198,7 @@ func WebhookCreate(ctx *context.Context) {
ctx.Data["PageIsSettingsHooksNew"] = true ctx.Data["PageIsSettingsHooksNew"] = true
ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook_module.HookEvent{}} ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook_module.HookEvent{}}
ctx.Data["HookType"] = hookType ctx.Data["HookType"] = hookType
ctx.Data["WebhookHandler"] = handler
orCtx, err := getOwnerRepoCtx(ctx) orCtx, err := getOwnerRepoCtx(ctx)
if err != nil { if err != nil {
@ -202,6 +207,7 @@ func WebhookCreate(ctx *context.Context) {
} }
ctx.Data["BaseLink"] = orCtx.LinkNew ctx.Data["BaseLink"] = orCtx.LinkNew
ctx.Data["BaseLinkNew"] = orCtx.LinkNew ctx.Data["BaseLinkNew"] = orCtx.LinkNew
ctx.Data["WebhookList"] = webhook_service.List()
if ctx.HasError() { if ctx.HasError() {
// pre-fill the form with the submitted data // pre-fill the form with the submitted data
@ -336,6 +342,7 @@ func checkWebhook(ctx *context.Context) (*ownerRepoCtx, *webhook.Webhook) {
} }
ctx.Data["BaseLink"] = orCtx.Link ctx.Data["BaseLink"] = orCtx.Link
ctx.Data["BaseLinkNew"] = orCtx.LinkNew ctx.Data["BaseLinkNew"] = orCtx.LinkNew
ctx.Data["WebhookList"] = webhook_service.List()
var w *webhook.Webhook var w *webhook.Webhook
if orCtx.RepoID > 0 { if orCtx.RepoID > 0 {
@ -358,6 +365,7 @@ func checkWebhook(ctx *context.Context) (*ownerRepoCtx, *webhook.Webhook) {
if handler := webhook_service.GetWebhookHandler(w.Type); handler != nil { if handler := webhook_service.GetWebhookHandler(w.Type); handler != nil {
ctx.Data["HookMetadata"] = handler.Metadata(w) ctx.Data["HookMetadata"] = handler.Metadata(w)
ctx.Data["WebhookHandler"] = handler
} }
ctx.Data["History"], err = w.History(ctx, 1) ctx.Data["History"], err = w.History(ctx, 1)

View file

@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
webhook_service "code.gitea.io/gitea/services/webhook"
) )
const ( const (
@ -23,6 +24,7 @@ func Webhooks(ctx *context.Context) {
ctx.Data["PageIsSettingsHooks"] = true ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["BaseLink"] = setting.AppSubURL + "/user/settings/hooks" ctx.Data["BaseLink"] = setting.AppSubURL + "/user/settings/hooks"
ctx.Data["BaseLinkNew"] = 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") ctx.Data["Description"] = ctx.Tr("settings.hooks.desc")
ws, err := db.Find[webhook.Webhook](ctx, webhook.ListWebhookOptions{OwnerID: ctx.Doer.ID}) ws, err := db.Find[webhook.Webhook](ctx, webhook.ListWebhookOptions{OwnerID: ctx.Doer.ID})

View file

@ -10,6 +10,7 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"html/template"
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
@ -17,6 +18,7 @@ import (
webhook_model "code.gitea.io/gitea/models/webhook" webhook_model "code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/svg"
webhook_module "code.gitea.io/gitea/modules/webhook" webhook_module "code.gitea.io/gitea/modules/webhook"
"code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/forms"
) )
@ -34,6 +36,14 @@ func (dh defaultHandler) Type() webhook_module.HookType {
return webhook_module.GITEA 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) Metadata(*webhook_model.Webhook) any { return nil }
func (defaultHandler) FormFields(bind func(any)) FormFields { func (defaultHandler) FormFields(bind func(any)) FormFields {

View file

@ -6,6 +6,7 @@ package webhook
import ( import (
"context" "context"
"fmt" "fmt"
"html/template"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
@ -22,6 +23,8 @@ type dingtalkHandler struct{}
func (dingtalkHandler) Type() webhook_module.HookType { return webhook_module.DINGTALK } func (dingtalkHandler) Type() webhook_module.HookType { return webhook_module.DINGTALK }
func (dingtalkHandler) Metadata(*webhook_model.Webhook) any { return nil } 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 { func (dingtalkHandler) FormFields(bind func(any)) FormFields {
var form struct { var form struct {
forms.WebhookForm forms.WebhookForm

View file

@ -7,6 +7,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"html/template"
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
@ -26,6 +27,7 @@ import (
type discordHandler struct{} type discordHandler struct{}
func (discordHandler) Type() webhook_module.HookType { return webhook_module.DISCORD } 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 { func (discordHandler) FormFields(bind func(any)) FormFields {
var form struct { var form struct {

View file

@ -6,6 +6,7 @@ package webhook
import ( import (
"context" "context"
"fmt" "fmt"
"html/template"
"net/http" "net/http"
"strings" "strings"
@ -19,6 +20,7 @@ import (
type feishuHandler struct{} type feishuHandler struct{}
func (feishuHandler) Type() webhook_module.HookType { return webhook_module.FEISHU } 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 { func (feishuHandler) FormFields(bind func(any)) FormFields {
var form struct { var form struct {

View file

@ -6,7 +6,9 @@ package webhook
import ( import (
"fmt" "fmt"
"html" "html"
"html/template"
"net/url" "net/url"
"strconv"
"strings" "strings"
webhook_model "code.gitea.io/gitea/models/webhook" 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(), Created: w.CreatedUnix.AsTime(),
}, nil }, nil
} }
func imgIcon(name string, size int) template.HTML {
s := strconv.Itoa(size)
src := html.EscapeString(setting.StaticURLPrefix + "/assets/img/" + name)
return template.HTML(`<img width="` + s + `" height="` + s + `" src="` + src + `">`)
}

View file

@ -4,6 +4,7 @@
package webhook package webhook
import ( import (
"html/template"
"net/http" "net/http"
webhook_model "code.gitea.io/gitea/models/webhook" webhook_model "code.gitea.io/gitea/models/webhook"
@ -14,6 +15,7 @@ import (
type gogsHandler struct{ defaultHandler } type gogsHandler struct{ defaultHandler }
func (gogsHandler) Type() webhook_module.HookType { return webhook_module.GOGS } 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 { func (gogsHandler) FormFields(bind func(any)) FormFields {
var form struct { var form struct {

View file

@ -9,6 +9,7 @@ import (
"crypto/sha1" "crypto/sha1"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"html/template"
"net/http" "net/http"
"net/url" "net/url"
"regexp" "regexp"
@ -20,6 +21,7 @@ import (
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/svg"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
webhook_module "code.gitea.io/gitea/modules/webhook" webhook_module "code.gitea.io/gitea/modules/webhook"
"code.gitea.io/gitea/services/forms" "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) 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 { func (matrixHandler) FormFields(bind func(any)) FormFields {
var form struct { var form struct {
forms.WebhookForm forms.WebhookForm

View file

@ -6,6 +6,7 @@ package webhook
import ( import (
"context" "context"
"fmt" "fmt"
"html/template"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
@ -22,6 +23,7 @@ type msteamsHandler struct{}
func (msteamsHandler) Type() webhook_module.HookType { return webhook_module.MSTEAMS } func (msteamsHandler) Type() webhook_module.HookType { return webhook_module.MSTEAMS }
func (msteamsHandler) Metadata(*webhook_model.Webhook) any { return nil } 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 { func (msteamsHandler) FormFields(bind func(any)) FormFields {
var form struct { var form struct {

View file

@ -6,6 +6,7 @@ package webhook
import ( import (
"context" "context"
"fmt" "fmt"
"html/template"
"net/http" "net/http"
"net/url" "net/url"
@ -19,6 +20,7 @@ import (
type packagistHandler struct{} type packagistHandler struct{}
func (packagistHandler) Type() webhook_module.HookType { return webhook_module.PACKAGIST } 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 { func (packagistHandler) FormFields(bind func(any)) FormFields {
var form struct { var form struct {

View file

@ -6,6 +6,7 @@ package webhook
import ( import (
"context" "context"
"fmt" "fmt"
"html/template"
"net/http" "net/http"
"regexp" "regexp"
"strings" "strings"
@ -26,6 +27,7 @@ import (
type slackHandler struct{} type slackHandler struct{}
func (slackHandler) Type() webhook_module.HookType { return webhook_module.SLACK } 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 { type slackForm struct {
forms.WebhookForm forms.WebhookForm

View file

@ -6,6 +6,7 @@ package webhook
import ( import (
"context" "context"
"fmt" "fmt"
"html/template"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
@ -22,6 +23,7 @@ import (
type telegramHandler struct{} type telegramHandler struct{}
func (telegramHandler) Type() webhook_module.HookType { return webhook_module.TELEGRAM } 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 { func (telegramHandler) FormFields(bind func(any)) FormFields {
var form struct { var form struct {

View file

@ -7,6 +7,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"html/template"
"net/http" "net/http"
"strings" "strings"
@ -35,6 +36,7 @@ type Handler interface {
// If form implements the [binding.Validator] interface, the Validate method will be called // If form implements the [binding.Validator] interface, the Validate method will be called
FormFields(bind func(form any)) FormFields FormFields(bind func(form any)) FormFields
NewRequest(context.Context, *webhook_model.Webhook, *webhook_model.HookTask) (req *http.Request, body []byte, err error) NewRequest(context.Context, *webhook_model.Webhook, *webhook_model.HookTask) (req *http.Request, body []byte, err error)
Icon(size int) template.HTML
} }
type FormFields struct { type FormFields struct {

View file

@ -6,6 +6,7 @@ package webhook
import ( import (
"context" "context"
"fmt" "fmt"
"html/template"
"net/http" "net/http"
"strings" "strings"
@ -21,6 +22,10 @@ type wechatworkHandler struct{}
func (wechatworkHandler) Type() webhook_module.HookType { return webhook_module.WECHATWORK } func (wechatworkHandler) Type() webhook_module.HookType { return webhook_module.WECHATWORK }
func (wechatworkHandler) Metadata(*webhook_model.Webhook) any { return nil } 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 { func (wechatworkHandler) FormFields(bind func(any)) FormFields {
var form struct { var form struct {
forms.WebhookForm forms.WebhookForm

View file

@ -3,52 +3,10 @@
{{$size = .Size}} {{$size = .Size}}
{{end}} {{end}}
<div class="menu"> <div class="menu">
<a class="item" href="{{.BaseLinkNew}}/forgejo/new"> {{range .WebhookList}}
{{template "shared/webhook/icon" (dict "HookType" "forgejo" "Size" $size)}} <a class="item" href="{{$.BaseLinkNew}}/{{.Type}}/new">
{{ctx.Locale.Tr "repo.settings.web_hook_name_forgejo"}} {{.Icon $size}}
</a> {{ctx.Locale.Tr (print "repo.settings.web_hook_name_" .Type)}}
<a class="item" href="{{.BaseLinkNew}}/gitea/new">
{{template "shared/webhook/icon" (dict "HookType" "gitea" "Size" $size)}}
{{ctx.Locale.Tr "repo.settings.web_hook_name_gitea"}}
</a>
<a class="item" href="{{.BaseLinkNew}}/gogs/new">
{{template "shared/webhook/icon" (dict "HookType" "gogs" "Size" $size)}}
{{ctx.Locale.Tr "repo.settings.web_hook_name_gogs"}}
</a>
<a class="item" href="{{.BaseLinkNew}}/slack/new">
{{template "shared/webhook/icon" (dict "HookType" "slack" "Size" $size)}}
{{ctx.Locale.Tr "repo.settings.web_hook_name_slack"}}
</a>
<a class="item" href="{{.BaseLinkNew}}/discord/new">
{{template "shared/webhook/icon" (dict "HookType" "discord" "Size" $size)}}
{{ctx.Locale.Tr "repo.settings.web_hook_name_discord"}}
</a>
<a class="item" href="{{.BaseLinkNew}}/dingtalk/new">
{{template "shared/webhook/icon" (dict "HookType" "dingtalk" "Size" $size)}}
{{ctx.Locale.Tr "repo.settings.web_hook_name_dingtalk"}}
</a>
<a class="item" href="{{.BaseLinkNew}}/telegram/new">
{{template "shared/webhook/icon" (dict "HookType" "telegram" "Size" $size)}}
{{ctx.Locale.Tr "repo.settings.web_hook_name_telegram"}}
</a>
<a class="item" href="{{.BaseLinkNew}}/msteams/new">
{{template "shared/webhook/icon" (dict "HookType" "msteams" "Size" $size)}}
{{ctx.Locale.Tr "repo.settings.web_hook_name_msteams"}}
</a>
<a class="item" href="{{.BaseLinkNew}}/feishu/new">
{{template "shared/webhook/icon" (dict "HookType" "feishu" "Size" $size)}}
{{ctx.Locale.Tr "repo.settings.web_hook_name_feishu_or_larksuite"}}
</a>
<a class="item" href="{{.BaseLinkNew}}/matrix/new">
{{template "shared/webhook/icon" (dict "HookType" "matrix" "Size" $size)}}
{{ctx.Locale.Tr "repo.settings.web_hook_name_matrix"}}
</a>
<a class="item" href="{{.BaseLinkNew}}/wechatwork/new">
{{template "shared/webhook/icon" (dict "HookType" "wechatwork" "Size" $size)}}
{{ctx.Locale.Tr "repo.settings.web_hook_name_wechatwork"}}
</a>
<a class="item" href="{{.BaseLinkNew}}/packagist/new">
{{template "shared/webhook/icon" (dict "HookType" "packagist" "Size" $size)}}
{{ctx.Locale.Tr "repo.settings.web_hook_name_packagist"}}
</a> </a>
{{end}}
</div> </div>

View file

@ -2,7 +2,7 @@
{{.CustomHeaderTitle}} {{.CustomHeaderTitle}}
<div class="ui right type dropdown"> <div class="ui right type dropdown">
<div class="text tw-flex tw-items-center"> <div class="text tw-flex tw-items-center">
{{template "shared/webhook/icon" (dict "Size" 20 "HookType" .ctxData.HookType)}} {{.ctxData.WebhookHandler.Icon 20}}
{{ctx.Locale.Tr (print "repo.settings.web_hook_name_" .ctxData.HookType)}} {{ctx.Locale.Tr (print "repo.settings.web_hook_name_" .ctxData.HookType)}}
</div> </div>
{{svg "octicon-triangle-down" 14 "dropdown icon"}} {{svg "octicon-triangle-down" 14 "dropdown icon"}}

View file

@ -1,5 +1,5 @@
<p>{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://feishu.cn" (ctx.Locale.Tr "repo.settings.web_hook_name_feishu")}}</p> <p>{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://feishu.cn" (ctx.Locale.Tr "repo.settings.web_hook_name_feishu_only")}}</p>
<p>{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://larksuite.com" (ctx.Locale.Tr "repo.settings.web_hook_name_larksuite")}}</p> <p>{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://larksuite.com" (ctx.Locale.Tr "repo.settings.web_hook_name_larksuite_only")}}</p>
<form class="ui form" action="{{.BaseLink}}/{{or .Webhook.ID "feishu/new"}}" method="post"> <form class="ui form" action="{{.BaseLink}}/{{or .Webhook.ID "feishu/new"}}" method="post">
{{.CsrfTokenHtml}} {{.CsrfTokenHtml}}
<div class="required field {{if .Err_PayloadURL}}error{{end}}"> <div class="required field {{if .Err_PayloadURL}}error{{end}}">