@@ -17,33 +17,36 @@ import (
17
17
webhook_service "code.gitea.io/gitea/services/webhook"
18
18
)
19
19
20
- // ListHooks list system's webhooks
20
+ // swaggeroperation GET /admin/{hookType:default-hooks|system-hooks} admin adminListHooks
21
+
22
+ // list system or default webhooks
21
23
func ListHooks (ctx * context.APIContext ) {
22
- // swagger:operation GET /admin/hooks admin adminListHooks
24
+ // swagger:operation GET /admin/{hookType} admin adminListHooks
23
25
// ---
24
26
// summary: List system's webhooks
25
27
// produces:
26
28
// - application/json
27
29
// parameters:
28
- // - name: page
29
- // in: query
30
- // description: page number of results to return (1-based)
31
- // type: integer
32
- // - name: limit
33
- // in: query
34
- // description: page size of results
35
- // type: integer
30
+ // - name: hookType
31
+ // in: path
32
+ // description: whether the hook is system-wide or copied-to-each-new-repo
33
+ // type: string
34
+ // enum: [system-hooks, default-hooks]
35
+ // required: true
36
36
// responses:
37
37
// "200":
38
38
// "$ref": "#/responses/HookList"
39
39
40
- sysHooks , err := webhook .GetSystemOrDefaultWebhooks (ctx , util .OptionalBoolNone )
40
+ isSystemWebhook := ctx .Params (":hookType" ) == "system-hooks"
41
+
42
+ adminHooks , err := webhook .GetAdminWebhooks (ctx , isSystemWebhook , util .OptionalBoolNone )
41
43
if err != nil {
42
- ctx .Error (http .StatusInternalServerError , "GetSystemWebhooks " , err )
44
+ ctx .Error (http .StatusInternalServerError , "GetAdminWebhooks " , err )
43
45
return
44
46
}
45
- hooks := make ([]* api.Hook , len (sysHooks ))
46
- for i , hook := range sysHooks {
47
+
48
+ hooks := make ([]* api.Hook , len (adminHooks ))
49
+ for i , hook := range adminHooks {
47
50
h , err := webhook_service .ToHook (setting .AppURL + "/admin" , hook )
48
51
if err != nil {
49
52
ctx .Error (http .StatusInternalServerError , "convert.ToHook" , err )
@@ -54,14 +57,20 @@ func ListHooks(ctx *context.APIContext) {
54
57
ctx .JSON (http .StatusOK , hooks )
55
58
}
56
59
57
- // GetHook get an organization's hook by id
60
+ // get a system/default hook by id
58
61
func GetHook (ctx * context.APIContext ) {
59
- // swagger:operation GET /admin/hooks /{id} admin adminGetHook
62
+ // swagger:operation GET /admin/{hookType} /{id} admin adminGetHook
60
63
// ---
61
64
// summary: Get a hook
62
65
// produces:
63
66
// - application/json
64
67
// parameters:
68
+ // - name: hookType
69
+ // in: path
70
+ // description: whether the hook is system-wide or copied-to-each-new-repo
71
+ // type: string
72
+ // enum: [system-hooks, default-hooks]
73
+ // required: true
65
74
// - name: id
66
75
// in: path
67
76
// description: id of the hook to get
@@ -72,16 +81,19 @@ func GetHook(ctx *context.APIContext) {
72
81
// "200":
73
82
// "$ref": "#/responses/Hook"
74
83
84
+ isSystemWebhook := ctx .Params (":hookType" ) == "system-hooks"
85
+
75
86
hookID := ctx .ParamsInt64 (":id" )
76
- hook , err := webhook .GetSystemOrDefaultWebhook (ctx , hookID )
87
+ hook , err := webhook .GetAdminWebhook (ctx , hookID , isSystemWebhook )
77
88
if err != nil {
78
89
if errors .Is (err , util .ErrNotExist ) {
79
90
ctx .NotFound ()
80
91
} else {
81
- ctx .Error (http .StatusInternalServerError , "GetSystemOrDefaultWebhook " , err )
92
+ ctx .Error (http .StatusInternalServerError , "GetAdminWebhook " , err )
82
93
}
83
94
return
84
95
}
96
+
85
97
h , err := webhook_service .ToHook ("/admin/" , hook )
86
98
if err != nil {
87
99
ctx .Error (http .StatusInternalServerError , "convert.ToHook" , err )
@@ -90,16 +102,22 @@ func GetHook(ctx *context.APIContext) {
90
102
ctx .JSON (http .StatusOK , h )
91
103
}
92
104
93
- // CreateHook create a hook for an organization
105
+ // create a system or default hook
94
106
func CreateHook (ctx * context.APIContext ) {
95
- // swagger:operation POST /admin/hooks admin adminCreateHook
107
+ // swagger:operation POST /admin/{hookType} admin adminCreateHook
96
108
// ---
97
109
// summary: Create a hook
98
110
// consumes:
99
111
// - application/json
100
112
// produces:
101
113
// - application/json
102
114
// parameters:
115
+ // - name: hookType
116
+ // in: path
117
+ // description: whether the hook is system-wide or copied-to-each-new-repo
118
+ // type: string
119
+ // enum: [system-hooks, default-hooks]
120
+ // required: true
103
121
// - name: body
104
122
// in: body
105
123
// required: true
@@ -109,21 +127,29 @@ func CreateHook(ctx *context.APIContext) {
109
127
// "201":
110
128
// "$ref": "#/responses/Hook"
111
129
130
+ isSystemWebhook := ctx .Params (":hookType" ) == "system-hooks"
131
+
112
132
form := web .GetForm (ctx ).(* api.CreateHookOption )
113
133
114
- utils .AddSystemHook (ctx , form )
134
+ utils .AddAdminHook (ctx , form , isSystemWebhook )
115
135
}
116
136
117
- // EditHook modify a hook of a repository
137
+ // modify a system or default hook
118
138
func EditHook (ctx * context.APIContext ) {
119
- // swagger:operation PATCH /admin/hooks /{id} admin adminEditHook
139
+ // swagger:operation PATCH /admin/{hookType} /{id} admin adminEditHook
120
140
// ---
121
141
// summary: Update a hook
122
142
// consumes:
123
143
// - application/json
124
144
// produces:
125
145
// - application/json
126
146
// parameters:
147
+ // - name: hookType
148
+ // in: path
149
+ // description: whether the hook is system-wide or copied-to-each-new-repo
150
+ // type: string
151
+ // enum: [system-hooks, default-hooks]
152
+ // required: true
127
153
// - name: id
128
154
// in: path
129
155
// description: id of the hook to update
@@ -138,21 +164,29 @@ func EditHook(ctx *context.APIContext) {
138
164
// "200":
139
165
// "$ref": "#/responses/Hook"
140
166
167
+ isSystemWebhook := ctx .Params (":hookType" ) == "system-hooks"
168
+
141
169
form := web .GetForm (ctx ).(* api.EditHookOption )
142
170
143
171
// TODO in body params
144
172
hookID := ctx .ParamsInt64 (":id" )
145
- utils .EditSystemHook (ctx , form , hookID )
173
+ utils .EditHook (ctx , form , hookID , isSystemWebhook )
146
174
}
147
175
148
- // DeleteHook delete a system hook
176
+ // delete a system or default hook
149
177
func DeleteHook (ctx * context.APIContext ) {
150
- // swagger:operation DELETE /admin/hooks /{id} admin adminDeleteHook
178
+ // swagger:operation DELETE /admin/{hookType} /{id} admin adminDeleteHook
151
179
// ---
152
180
// summary: Delete a hook
153
181
// produces:
154
182
// - application/json
155
183
// parameters:
184
+ // - name: hookType
185
+ // in: path
186
+ // description: whether the hook is system-wide or copied-to-each-new-repo
187
+ // type: string
188
+ // enum: [system-hooks, default-hooks]
189
+ // required: true
156
190
// - name: id
157
191
// in: path
158
192
// description: id of the hook to delete
@@ -164,11 +198,11 @@ func DeleteHook(ctx *context.APIContext) {
164
198
// "$ref": "#/responses/empty"
165
199
166
200
hookID := ctx .ParamsInt64 (":id" )
167
- if err := webhook .DeleteDefaultSystemWebhook (ctx , hookID ); err != nil {
201
+ if err := webhook .DeleteAdminWebhook (ctx , hookID ); err != nil {
168
202
if errors .Is (err , util .ErrNotExist ) {
169
203
ctx .NotFound ()
170
204
} else {
171
- ctx .Error (http .StatusInternalServerError , "DeleteDefaultSystemWebhook " , err )
205
+ ctx .Error (http .StatusInternalServerError , "DeleteAdminWebhook " , err )
172
206
}
173
207
return
174
208
}
0 commit comments