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

Commit842003a

Browse files
authored
Handle Actions Cancel Workflow Run returning a 202 (#855)
Actions Cancel Workflow Run returns a 202 on success. Check for a `*github.AcceptedError` in response to the API call to handle this correctly.
1 parentcad048b commit842003a

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

‎pkg/github/actions.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,9 @@ func CancelWorkflowRun(getClient GetClientFn, t translations.TranslationHelperFu
955955

956956
resp,err:=client.Actions.CancelWorkflowRunByID(ctx,owner,repo,runID)
957957
iferr!=nil {
958-
returnghErrors.NewGitHubAPIErrorResponse(ctx,"failed to cancel workflow run",resp,err),nil
958+
if_,ok:=err.(*github.AcceptedError);!ok {
959+
returnghErrors.NewGitHubAPIErrorResponse(ctx,"failed to cancel workflow run",resp,err),nil
960+
}
959961
}
960962
deferfunc() {_=resp.Body.Close() }()
961963

‎pkg/github/actions_test.go‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,14 @@ func Test_CancelWorkflowRun(t *testing.T) {
323323
{
324324
name:"successful workflow run cancellation",
325325
mockedClient:mock.NewMockedHTTPClient(
326-
mock.WithRequestMatch(
326+
mock.WithRequestMatchHandler(
327327
mock.EndpointPattern{
328328
Pattern:"/repos/owner/repo/actions/runs/12345/cancel",
329329
Method:"POST",
330330
},
331-
"",// Empty response body for 202 Accepted
331+
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
332+
w.WriteHeader(http.StatusAccepted)
333+
}),
332334
),
333335
),
334336
requestArgs:map[string]any{
@@ -338,6 +340,27 @@ func Test_CancelWorkflowRun(t *testing.T) {
338340
},
339341
expectError:false,
340342
},
343+
{
344+
name:"conflict when cancelling a workflow run",
345+
mockedClient:mock.NewMockedHTTPClient(
346+
mock.WithRequestMatchHandler(
347+
mock.EndpointPattern{
348+
Pattern:"/repos/owner/repo/actions/runs/12345/cancel",
349+
Method:"POST",
350+
},
351+
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
352+
w.WriteHeader(http.StatusConflict)
353+
}),
354+
),
355+
),
356+
requestArgs:map[string]any{
357+
"owner":"owner",
358+
"repo":"repo",
359+
"run_id":float64(12345),
360+
},
361+
expectError:true,
362+
expectedErrMsg:"failed to cancel workflow run",
363+
},
341364
{
342365
name:"missing required parameter run_id",
343366
mockedClient:mock.NewMockedHTTPClient(),
@@ -369,7 +392,7 @@ func Test_CancelWorkflowRun(t *testing.T) {
369392
textContent:=getTextResult(t,result)
370393

371394
iftc.expectedErrMsg!="" {
372-
assert.Equal(t,tc.expectedErrMsg,textContent.Text)
395+
assert.Contains(t,textContent.Text,tc.expectedErrMsg)
373396
return
374397
}
375398

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp