@@ -67,6 +67,28 @@ func ListRunners(ctx *context.APIContext, ownerID, repoID int64) {
67
67
ctx .JSON (http .StatusOK , & res )
68
68
}
69
69
70
+ func getRunnerByID (ctx * context.APIContext , ownerID , repoID , runnerID int64 ) (* actions_model.ActionRunner , bool ) {
71
+ if ownerID != 0 && repoID != 0 {
72
+ setting .PanicInDevOrTesting ("ownerID and repoID should not be both set" )
73
+ }
74
+
75
+ runner , err := actions_model .GetRunnerByID (ctx , runnerID )
76
+ if err != nil {
77
+ if errors .Is (err , util .ErrNotExist ) {
78
+ ctx .APIErrorNotFound ("Runner not found" )
79
+ } else {
80
+ ctx .APIErrorInternal (err )
81
+ }
82
+ return nil , false
83
+ }
84
+
85
+ if ! runner .EditableInContext (ownerID , repoID ) {
86
+ ctx .APIErrorNotFound ("No permission to access this runner" )
87
+ return nil , false
88
+ }
89
+ return runner , true
90
+ }
91
+
70
92
// GetRunner get the runner for api route validated ownerID and repoID
71
93
// ownerID == 0 and repoID == 0 means any runner including global runners
72
94
// ownerID == 0 and repoID != 0 means any runner for the given repo
@@ -77,13 +99,8 @@ func GetRunner(ctx *context.APIContext, ownerID, repoID, runnerID int64) {
77
99
if ownerID != 0 && repoID != 0 {
78
100
setting .PanicInDevOrTesting ("ownerID and repoID should not be both set" )
79
101
}
80
- runner , err := actions_model .GetRunnerByID (ctx , runnerID )
81
- if err != nil {
82
- ctx .APIErrorNotFound (err )
83
- return
84
- }
85
- if ! runner .EditableInContext (ownerID , repoID ) {
86
- ctx .APIErrorNotFound ("No permission to get this runner" )
102
+ runner , ok := getRunnerByID (ctx , ownerID , repoID , runnerID )
103
+ if ! ok {
87
104
return
88
105
}
89
106
ctx .JSON (http .StatusOK , convert .ToActionRunner (ctx , runner ))
@@ -96,20 +113,12 @@ func GetRunner(ctx *context.APIContext, ownerID, repoID, runnerID int64) {
96
113
// ownerID != 0 and repoID != 0 undefined behavior
97
114
// Access rights are checked at the API route level
98
115
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
- }
102
- runner , err := actions_model .GetRunnerByID (ctx , runnerID )
103
- if err != nil {
104
- ctx .APIErrorInternal (err )
105
- return
106
- }
107
- if ! runner .EditableInContext (ownerID , repoID ) {
108
- ctx .APIErrorNotFound ("No permission to delete this runner" )
116
+ runner , ok := getRunnerByID (ctx , ownerID , repoID , runnerID )
117
+ if ! ok {
109
118
return
110
119
}
111
120
112
- err = actions_model .DeleteRunner (ctx , runner .ID )
121
+ err : = actions_model .DeleteRunner (ctx , runner .ID )
113
122
if err != nil {
114
123
ctx .APIErrorInternal (err )
115
124
return
0 commit comments