Skip to content

Commit dbda9f6

Browse files
committed
fix copilot suggestions
1 parent a15fce7 commit dbda9f6

File tree

13 files changed

+191
-339
lines changed

13 files changed

+191
-339
lines changed

assets/go-licenses.json

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

modules/structs/repo_actions.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package structs
55

66
import (
77
"time"
8+
9+
"code.gitea.io/gitea/modules/json"
810
)
911

1012
// ActionTask represents a ActionTask
@@ -201,6 +203,37 @@ type ActionRunner struct {
201203
Labels []*ActionRunnerLabel `json:"labels"`
202204
}
203205

206+
// EditActionRunnerOption represents the editable fields for a runner.
207+
// swagger:model
208+
type EditActionRunnerOption struct {
209+
// required: true
210+
Disabled bool `json:"disabled"`
211+
212+
hasDisabled bool
213+
}
214+
215+
func (o *EditActionRunnerOption) UnmarshalJSON(data []byte) error {
216+
type rawEditActionRunnerOption struct {
217+
Disabled *bool `json:"disabled"`
218+
}
219+
220+
var raw rawEditActionRunnerOption
221+
if err := json.Unmarshal(data, &raw); err != nil {
222+
return err
223+
}
224+
225+
if raw.Disabled != nil {
226+
o.Disabled = *raw.Disabled
227+
o.hasDisabled = true
228+
}
229+
230+
return nil
231+
}
232+
233+
func (o *EditActionRunnerOption) HasDisabled() bool {
234+
return o != nil && o.hasDisabled
235+
}
236+
204237
// ActionRunnersResponse returns Runners
205238
type ActionRunnersResponse struct {
206239
Entries []*ActionRunner `json:"runners"`

routers/api/v1/admin/runners.go

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -94,34 +94,13 @@ func DeleteRunner(ctx *context.APIContext) {
9494
shared.DeleteRunner(ctx, 0, 0, ctx.PathParamInt64("runner_id"))
9595
}
9696

97-
// DisableRunner disable a global runner
98-
func DisableRunner(ctx *context.APIContext) {
99-
// swagger:operation PUT /admin/actions/runners/{runner_id}/disable admin disableAdminRunner
97+
// UpdateRunner update a global runner
98+
func UpdateRunner(ctx *context.APIContext) {
99+
// swagger:operation PATCH /admin/actions/runners/{runner_id} admin updateAdminRunner
100100
// ---
101-
// summary: Disable a global runner
102-
// produces:
101+
// summary: Update a global runner
102+
// consumes:
103103
// - application/json
104-
// parameters:
105-
// - name: runner_id
106-
// in: path
107-
// description: id of the runner
108-
// type: string
109-
// required: true
110-
// responses:
111-
// "200":
112-
// "$ref": "#/definitions/ActionRunner"
113-
// "400":
114-
// "$ref": "#/responses/error"
115-
// "404":
116-
// "$ref": "#/responses/notFound"
117-
shared.DisableRunner(ctx, 0, 0, ctx.PathParamInt64("runner_id"))
118-
}
119-
120-
// EnableRunner enable a global runner
121-
func EnableRunner(ctx *context.APIContext) {
122-
// swagger:operation PUT /admin/actions/runners/{runner_id}/enable admin enableAdminRunner
123-
// ---
124-
// summary: Enable a global runner
125104
// produces:
126105
// - application/json
127106
// parameters:
@@ -130,12 +109,18 @@ func EnableRunner(ctx *context.APIContext) {
130109
// description: id of the runner
131110
// type: string
132111
// required: true
112+
// - name: body
113+
// in: body
114+
// schema:
115+
// "$ref": "#/definitions/EditActionRunnerOption"
133116
// responses:
134117
// "200":
135118
// "$ref": "#/definitions/ActionRunner"
136119
// "400":
137120
// "$ref": "#/responses/error"
138121
// "404":
139122
// "$ref": "#/responses/notFound"
140-
shared.EnableRunner(ctx, 0, 0, ctx.PathParamInt64("runner_id"))
123+
// "422":
124+
// "$ref": "#/responses/validationError"
125+
shared.UpdateRunner(ctx, 0, 0, ctx.PathParamInt64("runner_id"))
141126
}

routers/api/v1/api.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,7 @@ func Routes() *web.Router {
921921
m.Post("/registration-token", reqToken(), reqOwnerCheck, act.CreateRegistrationToken)
922922
m.Get("/{runner_id}", reqToken(), reqOwnerCheck, act.GetRunner)
923923
m.Delete("/{runner_id}", reqToken(), reqOwnerCheck, act.DeleteRunner)
924-
m.Put("/{runner_id}/disable", reqToken(), reqOwnerCheck, act.DisableRunner)
925-
m.Put("/{runner_id}/enable", reqToken(), reqOwnerCheck, act.EnableRunner)
924+
m.Patch("/{runner_id}", reqToken(), reqOwnerCheck, bind(api.EditActionRunnerOption{}), act.UpdateRunner)
926925
})
927926
m.Get("/runs", reqToken(), reqReaderCheck, act.ListWorkflowRuns)
928927
m.Get("/jobs", reqToken(), reqReaderCheck, act.ListWorkflowJobs)
@@ -1050,8 +1049,7 @@ func Routes() *web.Router {
10501049
m.Post("/registration-token", reqToken(), user.CreateRegistrationToken)
10511050
m.Get("/{runner_id}", reqToken(), user.GetRunner)
10521051
m.Delete("/{runner_id}", reqToken(), user.DeleteRunner)
1053-
m.Put("/{runner_id}/disable", reqToken(), user.DisableRunner)
1054-
m.Put("/{runner_id}/enable", reqToken(), user.EnableRunner)
1052+
m.Patch("/{runner_id}", reqToken(), bind(api.EditActionRunnerOption{}), user.UpdateRunner)
10551053
})
10561054

10571055
m.Get("/runs", reqToken(), user.ListWorkflowRuns)
@@ -1737,8 +1735,7 @@ func Routes() *web.Router {
17371735
m.Post("/registration-token", admin.CreateRegistrationToken)
17381736
m.Get("/{runner_id}", admin.GetRunner)
17391737
m.Delete("/{runner_id}", admin.DeleteRunner)
1740-
m.Put("/{runner_id}/disable", admin.DisableRunner)
1741-
m.Put("/{runner_id}/enable", admin.EnableRunner)
1738+
m.Patch("/{runner_id}", bind(api.EditActionRunnerOption{}), admin.UpdateRunner)
17421739
})
17431740
m.Get("/runs", admin.ListWorkflowRuns)
17441741
m.Get("/jobs", admin.ListWorkflowJobs)

routers/api/v1/org/action.go

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -556,39 +556,13 @@ func (Action) DeleteRunner(ctx *context.APIContext) {
556556
shared.DeleteRunner(ctx, ctx.Org.Organization.ID, 0, ctx.PathParamInt64("runner_id"))
557557
}
558558

559-
// DisableRunner disable an org-level runner
560-
func (Action) DisableRunner(ctx *context.APIContext) {
561-
// swagger:operation PUT /orgs/{org}/actions/runners/{runner_id}/disable organization disableOrgRunner
559+
// UpdateRunner update an org-level runner
560+
func (Action) UpdateRunner(ctx *context.APIContext) {
561+
// swagger:operation PATCH /orgs/{org}/actions/runners/{runner_id} organization updateOrgRunner
562562
// ---
563-
// summary: Disable an org-level runner
564-
// produces:
563+
// summary: Update an org-level runner
564+
// consumes:
565565
// - application/json
566-
// parameters:
567-
// - name: org
568-
// in: path
569-
// description: name of the organization
570-
// type: string
571-
// required: true
572-
// - name: runner_id
573-
// in: path
574-
// description: id of the runner
575-
// type: string
576-
// required: true
577-
// responses:
578-
// "200":
579-
// "$ref": "#/definitions/ActionRunner"
580-
// "400":
581-
// "$ref": "#/responses/error"
582-
// "404":
583-
// "$ref": "#/responses/notFound"
584-
shared.DisableRunner(ctx, ctx.Org.Organization.ID, 0, ctx.PathParamInt64("runner_id"))
585-
}
586-
587-
// EnableRunner enable an org-level runner
588-
func (Action) EnableRunner(ctx *context.APIContext) {
589-
// swagger:operation PUT /orgs/{org}/actions/runners/{runner_id}/enable organization enableOrgRunner
590-
// ---
591-
// summary: Enable an org-level runner
592566
// produces:
593567
// - application/json
594568
// parameters:
@@ -602,14 +576,20 @@ func (Action) EnableRunner(ctx *context.APIContext) {
602576
// description: id of the runner
603577
// type: string
604578
// required: true
579+
// - name: body
580+
// in: body
581+
// schema:
582+
// "$ref": "#/definitions/EditActionRunnerOption"
605583
// responses:
606584
// "200":
607585
// "$ref": "#/definitions/ActionRunner"
608586
// "400":
609587
// "$ref": "#/responses/error"
610588
// "404":
611589
// "$ref": "#/responses/notFound"
612-
shared.EnableRunner(ctx, ctx.Org.Organization.ID, 0, ctx.PathParamInt64("runner_id"))
590+
// "422":
591+
// "$ref": "#/responses/validationError"
592+
shared.UpdateRunner(ctx, ctx.Org.Organization.ID, 0, ctx.PathParamInt64("runner_id"))
613593
}
614594

615595
func (Action) ListWorkflowJobs(ctx *context.APIContext) {

0 commit comments

Comments
 (0)