9
9
10
10
actions_model "code.gitea.io/gitea/models/actions"
11
11
"code.gitea.io/gitea/models/db"
12
+ "code.gitea.io/gitea/modules/setting"
12
13
api "code.gitea.io/gitea/modules/structs"
13
14
"code.gitea.io/gitea/modules/util"
14
15
"code.gitea.io/gitea/routers/api/v1/utils"
@@ -35,13 +36,16 @@ func GetRegistrationToken(ctx *context.APIContext, ownerID, repoID int64) {
35
36
ctx .JSON (http .StatusOK , RegistrationToken {Token : token .Token })
36
37
}
37
38
38
- // List Runners for api route validated ownerID and repoID
39
+ // ListRunners lists runners for api route validated ownerID and repoID
39
40
// ownerID == 0 and repoID == 0 means all runners including global runners, does not appear in sql where clause
40
41
// ownerID == 0 and repoID != 0 means all runners for the given repo
41
42
// ownerID != 0 and repoID == 0 means all runners for the given user/org
42
43
// ownerID != 0 and repoID != 0 undefined behavior
43
44
// Access rights are checked at the API route level
44
45
func 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
+ }
45
49
runners , total , err := db .FindAndCount [actions_model.ActionRunner ](ctx , & actions_model.FindRunnerOptions {
46
50
OwnerID : ownerID ,
47
51
RepoID : repoID ,
@@ -63,38 +67,44 @@ func ListRunners(ctx *context.APIContext, ownerID, repoID int64) {
63
67
ctx .JSON (http .StatusOK , & res )
64
68
}
65
69
66
- // Get Runners for api route validated ownerID and repoID
70
+ // GetRunner get the runner for api route validated ownerID and repoID
67
71
// ownerID == 0 and repoID == 0 means any runner including global runners
68
72
// ownerID == 0 and repoID != 0 means any runner for the given repo
69
73
// ownerID != 0 and repoID == 0 means any runner for the given user/org
70
74
// ownerID != 0 and repoID != 0 undefined behavior
71
75
// Access rights are checked at the API route level
72
76
func 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
+ }
73
80
runner , err := actions_model .GetRunnerByID (ctx , runnerID )
74
81
if err != nil {
75
82
ctx .APIErrorNotFound (err )
76
83
return
77
84
}
78
- if ! runner .Editable (ownerID , repoID ) {
85
+ if ! runner .EditableInContext (ownerID , repoID ) {
79
86
ctx .APIErrorNotFound ("No permission to get this runner" )
80
87
return
81
88
}
82
89
ctx .JSON (http .StatusOK , convert .ToActionRunner (ctx , runner ))
83
90
}
84
91
85
- // Delete Runner for api route validated ownerID and repoID
92
+ // DeleteRunner deletes the runner for api route validated ownerID and repoID
86
93
// ownerID == 0 and repoID == 0 means any runner including global runners
87
94
// ownerID == 0 and repoID != 0 means any runner for the given repo
88
95
// ownerID != 0 and repoID == 0 means any runner for the given user/org
89
96
// ownerID != 0 and repoID != 0 undefined behavior
90
97
// Access rights are checked at the API route level
91
98
func 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
+ }
92
102
runner , err := actions_model .GetRunnerByID (ctx , runnerID )
93
103
if err != nil {
94
104
ctx .APIErrorInternal (err )
95
105
return
96
106
}
97
- if ! runner .Editable (ownerID , repoID ) {
107
+ if ! runner .EditableInContext (ownerID , repoID ) {
98
108
ctx .APIErrorNotFound ("No permission to delete this runner" )
99
109
return
100
110
}
0 commit comments