Skip to content

Commit 949a93f

Browse files
committed
Fixed listing system and default webhooks
1 parent 88366f2 commit 949a93f

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

models/webhook/webhook_system.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ import (
1111
"code.gitea.io/gitea/modules/optional"
1212
)
1313

14+
// GetSystemOrDefaultWebhooks returns webhooks by given argument or all if argument is missing.
15+
func GetSystemOrDefaultWebhooks(ctx context.Context, isSystemWebhook optional.Option[bool]) ([]*Webhook, error) {
16+
webhooks := make([]*Webhook, 0, 5)
17+
if !isSystemWebhook.Has() {
18+
return webhooks, db.GetEngine(ctx).Where("repo_id=? AND owner_id=?", 0, 0).
19+
Find(&webhooks)
20+
}
21+
22+
return webhooks, db.GetEngine(ctx).
23+
Where("repo_id=? AND owner_id=? AND is_system_webhook=?", 0, 0, isSystemWebhook.Value()).
24+
Find(&webhooks)
25+
}
26+
1427
// GetDefaultWebhooks returns all admin-default webhooks.
1528
func GetDefaultWebhooks(ctx context.Context) ([]*Webhook, error) {
1629
webhooks := make([]*Webhook, 0, 5)

routers/api/v1/admin/hooks.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,30 @@ func ListHooks(ctx *context.APIContext) {
3434
// in: query
3535
// description: page size of results
3636
// type: integer
37+
// - type: string
38+
// enum:
39+
// - system
40+
// - default
41+
// - all
42+
// description: system, default or both kinds of webhooks
43+
// name: type
44+
// default: system
45+
// in: query
46+
//
3747
// responses:
3848
// "200":
3949
// "$ref": "#/responses/HookList"
4050

41-
sysHooks, err := webhook.GetSystemWebhooks(ctx, optional.None[bool]())
51+
//for compatibility the default value is true
52+
isSystemWebhook := optional.Some(true)
53+
typeValue := ctx.FormString("type")
54+
if typeValue == "default" {
55+
isSystemWebhook = optional.Some(false)
56+
} else if typeValue == "all" {
57+
isSystemWebhook = optional.None[bool]()
58+
}
59+
60+
sysHooks, err := webhook.GetSystemOrDefaultWebhooks(ctx, isSystemWebhook)
4261
if err != nil {
4362
ctx.Error(http.StatusInternalServerError, "GetSystemWebhooks", err)
4463
return

templates/swagger/v1_json.tmpl

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)