99
1010 actions_model "code.gitea.io/gitea/models/actions"
1111 "code.gitea.io/gitea/models/db"
12+ "code.gitea.io/gitea/modules/setting"
1213 api "code.gitea.io/gitea/modules/structs"
1314 "code.gitea.io/gitea/modules/util"
1415 "code.gitea.io/gitea/routers/api/v1/utils"
@@ -35,13 +36,16 @@ func GetRegistrationToken(ctx *context.APIContext, ownerID, repoID int64) {
3536 ctx .JSON (http .StatusOK , RegistrationToken {Token : token .Token })
3637}
3738
38- // List Runners for api route validated ownerID and repoID
39+ // ListRunners lists runners for api route validated ownerID and repoID
3940// ownerID == 0 and repoID == 0 means all runners including global runners, does not appear in sql where clause
4041// ownerID == 0 and repoID != 0 means all runners for the given repo
4142// ownerID != 0 and repoID == 0 means all runners for the given user/org
4243// ownerID != 0 and repoID != 0 undefined behavior
4344// Access rights are checked at the API route level
4445func ListRunners (ctx * context.APIContext , ownerID , repoID int64 ) {
46+ if ownerID != 0 && repoID != 0 {
47+ setting .PanicInDevOrTesting ("ownerID and repoID should not be both set" )
48+ }
4549 runners , total , err := db .FindAndCount [actions_model.ActionRunner ](ctx , & actions_model.FindRunnerOptions {
4650 OwnerID : ownerID ,
4751 RepoID : repoID ,
@@ -63,38 +67,44 @@ func ListRunners(ctx *context.APIContext, ownerID, repoID int64) {
6367 ctx .JSON (http .StatusOK , & res )
6468}
6569
66- // Get Runners for api route validated ownerID and repoID
70+ // GetRunner get the runner for api route validated ownerID and repoID
6771// ownerID == 0 and repoID == 0 means any runner including global runners
6872// ownerID == 0 and repoID != 0 means any runner for the given repo
6973// ownerID != 0 and repoID == 0 means any runner for the given user/org
7074// ownerID != 0 and repoID != 0 undefined behavior
7175// Access rights are checked at the API route level
7276func GetRunner (ctx * context.APIContext , ownerID , repoID , runnerID int64 ) {
77+ if ownerID != 0 && repoID != 0 {
78+ setting .PanicInDevOrTesting ("ownerID and repoID should not be both set" )
79+ }
7380 runner , err := actions_model .GetRunnerByID (ctx , runnerID )
7481 if err != nil {
7582 ctx .APIErrorNotFound (err )
7683 return
7784 }
78- if ! runner .Editable (ownerID , repoID ) {
85+ if ! runner .EditableInContext (ownerID , repoID ) {
7986 ctx .APIErrorNotFound ("No permission to get this runner" )
8087 return
8188 }
8289 ctx .JSON (http .StatusOK , convert .ToActionRunner (ctx , runner ))
8390}
8491
85- // Delete Runner for api route validated ownerID and repoID
92+ // DeleteRunner deletes the runner for api route validated ownerID and repoID
8693// ownerID == 0 and repoID == 0 means any runner including global runners
8794// ownerID == 0 and repoID != 0 means any runner for the given repo
8895// ownerID != 0 and repoID == 0 means any runner for the given user/org
8996// ownerID != 0 and repoID != 0 undefined behavior
9097// Access rights are checked at the API route level
9198func DeleteRunner (ctx * context.APIContext , ownerID , repoID , runnerID int64 ) {
99+ if ownerID != 0 && repoID != 0 {
100+ setting .PanicInDevOrTesting ("ownerID and repoID should not be both set" )
101+ }
92102 runner , err := actions_model .GetRunnerByID (ctx , runnerID )
93103 if err != nil {
94104 ctx .APIErrorInternal (err )
95105 return
96106 }
97- if ! runner .Editable (ownerID , repoID ) {
107+ if ! runner .EditableInContext (ownerID , repoID ) {
98108 ctx .APIErrorNotFound ("No permission to delete this runner" )
99109 return
100110 }
0 commit comments