@@ -25,6 +25,7 @@ import (
2525 api "code.gitea.io/gitea/modules/structs"
2626 "code.gitea.io/gitea/modules/util"
2727 "code.gitea.io/gitea/modules/web"
28+ cwebhook "code.gitea.io/gitea/modules/webhook"
2829 "code.gitea.io/gitea/services/forms"
2930 webhook_service "code.gitea.io/gitea/services/webhook"
3031)
@@ -50,6 +51,7 @@ func Webhooks(ctx *context.Context) {
5051 return
5152 }
5253 ctx .Data ["Webhooks" ] = ws
54+ ctx .Data ["CustomWebhooks" ] = cwebhook .Webhooks
5355
5456 ctx .HTML (http .StatusOK , tplHooks )
5557}
@@ -108,19 +110,21 @@ func getOrgRepoCtx(ctx *context.Context) (*orgRepoCtx, error) {
108110 return nil , errors .New ("unable to set OrgRepo context" )
109111}
110112
111- func checkHookType (ctx * context.Context ) string {
113+ func checkHookType (ctx * context.Context ) ( string , bool ) {
112114 hookType := strings .ToLower (ctx .Params (":type" ))
113- if ! util .IsStringInSlice (hookType , setting .Webhook .Types , true ) {
115+ _ , isCustom := cwebhook .Webhooks [hookType ]
116+ if ! util .IsStringInSlice (hookType , setting .Webhook .Types , true ) && ! isCustom {
114117 ctx .NotFound ("checkHookType" , nil )
115- return ""
118+ return "" , false
116119 }
117- return hookType
120+ return hookType , isCustom
118121}
119122
120123// WebhooksNew render creating webhook page
121124func WebhooksNew (ctx * context.Context ) {
122125 ctx .Data ["Title" ] = ctx .Tr ("repo.settings.add_webhook" )
123126 ctx .Data ["Webhook" ] = webhook.Webhook {HookEvent : & webhook.HookEvent {}}
127+ ctx .Data ["CustomWebhooks" ] = cwebhook .Webhooks
124128
125129 orCtx , err := getOrgRepoCtx (ctx )
126130 if err != nil {
@@ -139,7 +143,7 @@ func WebhooksNew(ctx *context.Context) {
139143 ctx .Data ["PageIsSettingsHooksNew" ] = true
140144 }
141145
142- hookType := checkHookType (ctx )
146+ hookType , isCustom := checkHookType (ctx )
143147 ctx .Data ["HookType" ] = hookType
144148 if ctx .Written () {
145149 return
@@ -149,6 +153,9 @@ func WebhooksNew(ctx *context.Context) {
149153 "Username" : "Gitea" ,
150154 }
151155 }
156+ if isCustom {
157+ ctx .Data ["CustomHook" ] = cwebhook .Webhooks [hookType ]
158+ }
152159 ctx .Data ["BaseLink" ] = orCtx .LinkNew
153160
154161 ctx .HTML (http .StatusOK , orCtx .NewTemplate )
@@ -771,6 +778,13 @@ func checkWebhook(ctx *context.Context) (*orgRepoCtx, *webhook.Webhook) {
771778 ctx .Data ["MatrixHook" ] = webhook_service .GetMatrixHook (w )
772779 case webhook .PACKAGIST :
773780 ctx .Data ["PackagistHook" ] = webhook_service .GetPackagistHook (w )
781+ case webhook .CUSTOM :
782+ ctx .Data ["CustomHook" ] = cwebhook .Webhooks [w .CustomID ]
783+ hook := webhook_service .GetCustomHook (w )
784+ ctx .Data ["Webhook" ] = hook
785+ for key , val := range hook .Form {
786+ ctx .Data ["CustomHook_" + key ] = val
787+ }
774788 }
775789
776790 ctx .Data ["History" ], err = w .History (1 )
0 commit comments