diff --git a/pkg/github/actions.go b/pkg/github/actions.go index 12bbb3394..38719f155 100644 --- a/pkg/github/actions.go +++ b/pkg/github/actions.go @@ -955,7 +955,9 @@ func CancelWorkflowRun(getClient GetClientFn, t translations.TranslationHelperFu resp, err := client.Actions.CancelWorkflowRunByID(ctx, owner, repo, runID) if err != nil { - return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to cancel workflow run", resp, err), nil + if _, ok := err.(*github.AcceptedError); !ok { + return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to cancel workflow run", resp, err), nil + } } defer func() { _ = resp.Body.Close() }() diff --git a/pkg/github/actions_test.go b/pkg/github/actions_test.go index 58759dbd0..3d7521125 100644 --- a/pkg/github/actions_test.go +++ b/pkg/github/actions_test.go @@ -323,12 +323,14 @@ func Test_CancelWorkflowRun(t *testing.T) { { name: "successful workflow run cancellation", mockedClient: mock.NewMockedHTTPClient( - mock.WithRequestMatch( + mock.WithRequestMatchHandler( mock.EndpointPattern{ Pattern: "/repos/owner/repo/actions/runs/12345/cancel", Method: "POST", }, - "", // Empty response body for 202 Accepted + http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusAccepted) + }), ), ), requestArgs: map[string]any{ @@ -338,6 +340,27 @@ func Test_CancelWorkflowRun(t *testing.T) { }, expectError: false, }, + { + name: "conflict when cancelling a workflow run", + mockedClient: mock.NewMockedHTTPClient( + mock.WithRequestMatchHandler( + mock.EndpointPattern{ + Pattern: "/repos/owner/repo/actions/runs/12345/cancel", + Method: "POST", + }, + http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusConflict) + }), + ), + ), + requestArgs: map[string]any{ + "owner": "owner", + "repo": "repo", + "run_id": float64(12345), + }, + expectError: true, + expectedErrMsg: "failed to cancel workflow run", + }, { name: "missing required parameter run_id", mockedClient: mock.NewMockedHTTPClient(), @@ -369,7 +392,7 @@ func Test_CancelWorkflowRun(t *testing.T) { textContent := getTextResult(t, result) if tc.expectedErrMsg != "" { - assert.Equal(t, tc.expectedErrMsg, textContent.Text) + assert.Contains(t, textContent.Text, tc.expectedErrMsg) return }