Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/github/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() }()

Expand Down
29 changes: 26 additions & 3 deletions pkg/github/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,14 @@
{
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, r *http.Request) {

Check failure on line 331 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
w.WriteHeader(http.StatusAccepted)
}),
),
),
requestArgs: map[string]any{
Expand All @@ -338,6 +340,27 @@
},
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, r *http.Request) {

Check failure on line 351 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
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(),
Expand Down Expand Up @@ -369,7 +392,7 @@
textContent := getTextResult(t, result)

if tc.expectedErrMsg != "" {
assert.Equal(t, tc.expectedErrMsg, textContent.Text)
assert.Contains(t, textContent.Text, tc.expectedErrMsg)
return
}

Expand Down
Loading