@@ -17,33 +17,34 @@ import (
1717 webhook_service "code.gitea.io/gitea/services/webhook"
1818)
1919
20- // ListHooks list system's webhooks
20+ // list system or default webhooks
2121func ListHooks (ctx * context.APIContext ) {
22- // swagger:operation GET /admin/hooks admin adminListHooks
22+ // swagger:operation GET /admin/hooks/{configType} admin adminListHooks
2323 // ---
2424 // summary: List system's webhooks
2525 // produces:
2626 // - application/json
2727 // 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
3634 // responses:
3735 // "200":
3836 // "$ref": "#/responses/HookList"
3937
40- sysHooks , err := webhook .GetSystemWebhooks (ctx , util .OptionalBoolNone )
38+ isSystemWebhook := ctx .Params (":configType" ) == "system"
39+
40+ adminHooks , err := webhook .GetAdminWebhooks (ctx , isSystemWebhook , util .OptionalBoolNone )
4141 if err != nil {
42- ctx .Error (http .StatusInternalServerError , "GetSystemWebhooks " , err )
42+ ctx .Error (http .StatusInternalServerError , "GetAdminWebhooks " , err )
4343 return
4444 }
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 {
4748 h , err := webhook_service .ToHook (setting .AppURL + "/admin" , hook )
4849 if err != nil {
4950 ctx .Error (http .StatusInternalServerError , "convert.ToHook" , err )
@@ -54,14 +55,20 @@ func ListHooks(ctx *context.APIContext) {
5455 ctx .JSON (http .StatusOK , hooks )
5556}
5657
57- // GetHook get an organization's hook by id
58+ // get a system/default hook by id
5859func GetHook (ctx * context.APIContext ) {
59- // swagger:operation GET /admin/hooks/{id} admin adminGetHook
60+ // swagger:operation GET /admin/hooks/{configType}/{ id} admin adminGetHook
6061 // ---
6162 // summary: Get a hook
6263 // produces:
6364 // - application/json
6465 // 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
6572 // - name: id
6673 // in: path
6774 // description: id of the hook to get
@@ -72,16 +79,19 @@ func GetHook(ctx *context.APIContext) {
7279 // "200":
7380 // "$ref": "#/responses/Hook"
7481
82+ isSystemWebhook := ctx .Params (":configType" ) == "system"
83+
7584 hookID := ctx .ParamsInt64 (":id" )
76- hook , err := webhook .GetSystemOrDefaultWebhook (ctx , hookID )
85+ hook , err := webhook .GetAdminWebhook (ctx , hookID , isSystemWebhook )
7786 if err != nil {
7887 if errors .Is (err , util .ErrNotExist ) {
7988 ctx .NotFound ()
8089 } else {
81- ctx .Error (http .StatusInternalServerError , "GetSystemOrDefaultWebhook " , err )
90+ ctx .Error (http .StatusInternalServerError , "GetAdminWebhook " , err )
8291 }
8392 return
8493 }
94+
8595 h , err := webhook_service .ToHook ("/admin/" , hook )
8696 if err != nil {
8797 ctx .Error (http .StatusInternalServerError , "convert.ToHook" , err )
@@ -90,16 +100,22 @@ func GetHook(ctx *context.APIContext) {
90100 ctx .JSON (http .StatusOK , h )
91101}
92102
93- // CreateHook create a hook for an organization
103+ // create a system or default hook
94104func CreateHook (ctx * context.APIContext ) {
95- // swagger:operation POST /admin/hooks admin adminCreateHook
105+ // swagger:operation POST /admin/hooks/{configType} admin adminCreateHook
96106 // ---
97107 // summary: Create a hook
98108 // consumes:
99109 // - application/json
100110 // produces:
101111 // - application/json
102112 // 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
103119 // - name: body
104120 // in: body
105121 // required: true
@@ -109,21 +125,29 @@ func CreateHook(ctx *context.APIContext) {
109125 // "201":
110126 // "$ref": "#/responses/Hook"
111127
128+ isSystemWebhook := ctx .Params (":configType" ) == "system"
129+
112130 form := web .GetForm (ctx ).(* api.CreateHookOption )
113131
114- utils .AddSystemHook (ctx , form )
132+ utils .AddAdminHook (ctx , form , isSystemWebhook )
115133}
116134
117- // EditHook modify a hook of a repository
135+ // modify a system or default hook
118136func EditHook (ctx * context.APIContext ) {
119- // swagger:operation PATCH /admin/hooks/{id} admin adminEditHook
137+ // swagger:operation PATCH /admin/hooks/{configType}/{ id} admin adminEditHook
120138 // ---
121139 // summary: Update a hook
122140 // consumes:
123141 // - application/json
124142 // produces:
125143 // - application/json
126144 // 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
127151 // - name: id
128152 // in: path
129153 // description: id of the hook to update
@@ -138,21 +162,29 @@ func EditHook(ctx *context.APIContext) {
138162 // "200":
139163 // "$ref": "#/responses/Hook"
140164
165+ isSystemWebhook := ctx .Params (":configType" ) == "system"
166+
141167 form := web .GetForm (ctx ).(* api.EditHookOption )
142168
143169 // TODO in body params
144170 hookID := ctx .ParamsInt64 (":id" )
145- utils .EditSystemHook (ctx , form , hookID )
171+ utils .EditAdminHook (ctx , form , hookID , isSystemWebhook )
146172}
147173
148- // DeleteHook delete a system hook
174+ // delete a system or default hook
149175func DeleteHook (ctx * context.APIContext ) {
150- // swagger:operation DELETE /admin/hooks/{id} admin adminDeleteHook
176+ // swagger:operation DELETE /admin/hooks/{configType}/{ id} admin adminDeleteHook
151177 // ---
152178 // summary: Delete a hook
153179 // produces:
154180 // - application/json
155181 // 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
156188 // - name: id
157189 // in: path
158190 // description: id of the hook to delete
@@ -163,12 +195,14 @@ func DeleteHook(ctx *context.APIContext) {
163195 // "204":
164196 // "$ref": "#/responses/empty"
165197
198+ isSystemWebhook := ctx .Params (":configType" ) == "system"
199+
166200 hookID := ctx .ParamsInt64 (":id" )
167- if err := webhook .DeleteDefaultSystemWebhook (ctx , hookID ); err != nil {
201+ if err := webhook .DeleteAdminWebhook (ctx , hookID , isSystemWebhook ); err != nil {
168202 if errors .Is (err , util .ErrNotExist ) {
169203 ctx .NotFound ()
170204 } else {
171- ctx .Error (http .StatusInternalServerError , "DeleteDefaultSystemWebhook " , err )
205+ ctx .Error (http .StatusInternalServerError , "DeleteAdminWebhook " , err )
172206 }
173207 return
174208 }
0 commit comments