Skip to content

Commit 59e8a37

Browse files
authored
Add function to delete a workflow run by ID (#2207)
1 parent b26fa8f commit 59e8a37

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

github/actions_workflow_runs.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,20 @@ func (s *ActionsService) GetWorkflowRunLogs(ctx context.Context, owner, repo str
211211
return parsedURL, newResponse(resp), err
212212
}
213213

214+
// DeleteWorkflowRun deletes a workflow run by ID.
215+
//
216+
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#delete-a-workflow-run
217+
func (s *ActionsService) DeleteWorkflowRun(ctx context.Context, owner, repo string, runID int64) (*Response, error) {
218+
u := fmt.Sprintf("repos/%v/%v/actions/runs/%v", owner, repo, runID)
219+
220+
req, err := s.client.NewRequest("DELETE", u, nil)
221+
if err != nil {
222+
return nil, err
223+
}
224+
225+
return s.client.Do(ctx, req, nil)
226+
}
227+
214228
// DeleteWorkflowRunLogs deletes all logs for a workflow run.
215229
//
216230
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#delete-workflow-run-logs

github/actions_workflow_runs_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,32 @@ func TestActionService_ListRepositoryWorkflowRuns(t *testing.T) {
334334
})
335335
}
336336

337+
func TestActionService_DeleteWorkflowRun(t *testing.T) {
338+
client, mux, _, teardown := setup()
339+
defer teardown()
340+
341+
mux.HandleFunc("/repos/o/r/actions/runs/399444496", func(w http.ResponseWriter, r *http.Request) {
342+
testMethod(t, r, "DELETE")
343+
344+
w.WriteHeader(http.StatusNoContent)
345+
})
346+
347+
ctx := context.Background()
348+
if _, err := client.Actions.DeleteWorkflowRun(ctx, "o", "r", 399444496); err != nil {
349+
t.Errorf("DeleteWorkflowRun returned error: %v", err)
350+
}
351+
352+
const methodName = "DeleteWorkflowRun"
353+
testBadOptions(t, methodName, func() (err error) {
354+
_, err = client.Actions.DeleteWorkflowRun(ctx, "\n", "\n", 399444496)
355+
return err
356+
})
357+
358+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
359+
return client.Actions.DeleteWorkflowRun(ctx, "o", "r", 399444496)
360+
})
361+
}
362+
337363
func TestActionService_DeleteWorkflowRunLogs(t *testing.T) {
338364
client, mux, _, teardown := setup()
339365
defer teardown()

0 commit comments

Comments
 (0)