Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit59df03b

Browse files
Fix get / delete runner to use consistent http 404 and 500 status (#34480)
* previously deleting an already deleted runner returned http 500* previously any database error for the get endpoint was http 404 and never 500
1 parent7b518bc commit59df03b

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

‎routers/api/v1/shared/runners.go‎

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,28 @@ func ListRunners(ctx *context.APIContext, ownerID, repoID int64) {
6767
ctx.JSON(http.StatusOK,&res)
6868
}
6969

70+
funcgetRunnerByID(ctx*context.APIContext,ownerID,repoID,runnerIDint64) (*actions_model.ActionRunner,bool) {
71+
ifownerID!=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+
iferr!=nil {
77+
iferrors.Is(err,util.ErrNotExist) {
78+
ctx.APIErrorNotFound("Runner not found")
79+
}else {
80+
ctx.APIErrorInternal(err)
81+
}
82+
returnnil,false
83+
}
84+
85+
if!runner.EditableInContext(ownerID,repoID) {
86+
ctx.APIErrorNotFound("No permission to access this runner")
87+
returnnil,false
88+
}
89+
returnrunner,true
90+
}
91+
7092
// GetRunner get the runner for api route validated ownerID and repoID
7193
// ownerID == 0 and repoID == 0 means any runner including global runners
7294
// 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) {
7799
ifownerID!=0&&repoID!=0 {
78100
setting.PanicInDevOrTesting("ownerID and repoID should not be both set")
79101
}
80-
runner,err:=actions_model.GetRunnerByID(ctx,runnerID)
81-
iferr!=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 {
87104
return
88105
}
89106
ctx.JSON(http.StatusOK,convert.ToActionRunner(ctx,runner))
@@ -96,20 +113,12 @@ func GetRunner(ctx *context.APIContext, ownerID, repoID, runnerID int64) {
96113
// ownerID != 0 and repoID != 0 undefined behavior
97114
// Access rights are checked at the API route level
98115
funcDeleteRunner(ctx*context.APIContext,ownerID,repoID,runnerIDint64) {
99-
ifownerID!=0&&repoID!=0 {
100-
setting.PanicInDevOrTesting("ownerID and repoID should not be both set")
101-
}
102-
runner,err:=actions_model.GetRunnerByID(ctx,runnerID)
103-
iferr!=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 {
109118
return
110119
}
111120

112-
err=actions_model.DeleteRunner(ctx,runner.ID)
121+
err:=actions_model.DeleteRunner(ctx,runner.ID)
113122
iferr!=nil {
114123
ctx.APIErrorInternal(err)
115124
return

‎tests/integration/api_actions_runner_test.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,4 +329,12 @@ func testActionsRunnerRepo(t *testing.T) {
329329
req:=NewRequest(t,"DELETE",fmt.Sprintf("/api/v1/repos/user2/repo1/actions/runners/%d",34349)).AddTokenAuth(token)
330330
MakeRequest(t,req,http.StatusNotFound)
331331
})
332+
333+
t.Run("DeleteAdminRunnerNotFoundUnknownID",func(t*testing.T) {
334+
userUsername:="user2"
335+
token:=getUserToken(t,userUsername,auth_model.AccessTokenScopeWriteRepository)
336+
// Verify delete a runner by unknown id is not found
337+
req:=NewRequest(t,"DELETE",fmt.Sprintf("/api/v1/repos/user2/repo1/actions/runners/%d",4384797347934)).AddTokenAuth(token)
338+
MakeRequest(t,req,http.StatusNotFound)
339+
})
332340
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp