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