From 94072a50a4c8d1722a5c47c67080f6cd11412829 Mon Sep 17 00:00:00 2001 From: Xabier Martinez Date: Mon, 22 Nov 2021 11:41:01 +0100 Subject: [PATCH 1/2] Add function to delete a workflow run by ID --- github/actions_workflow_runs.go | 12 ++++++++++++ github/actions_workflow_runs_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/github/actions_workflow_runs.go b/github/actions_workflow_runs.go index 37bc819abab..5d22196727a 100644 --- a/github/actions_workflow_runs.go +++ b/github/actions_workflow_runs.go @@ -211,6 +211,18 @@ func (s *ActionsService) GetWorkflowRunLogs(ctx context.Context, owner, repo str return parsedURL, newResponse(resp), err } +// DeleteWorkflowRunLogs deletes a workflow run by ID. +func (s *ActionsService) DeleteWorkflowRun(ctx context.Context, owner, repo string, runID int64) (*Response, error) { + u := fmt.Sprintf("repos/%v/%v/actions/runs/%v", owner, repo, runID) + + req, err := s.client.NewRequest("DELETE", u, nil) + if err != nil { + return nil, err + } + + return s.client.Do(ctx, req, nil) +} + // DeleteWorkflowRunLogs deletes all logs for a workflow run. // // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#delete-workflow-run-logs diff --git a/github/actions_workflow_runs_test.go b/github/actions_workflow_runs_test.go index fcfbd36039a..d3623621f50 100644 --- a/github/actions_workflow_runs_test.go +++ b/github/actions_workflow_runs_test.go @@ -334,6 +334,32 @@ func TestActionService_ListRepositoryWorkflowRuns(t *testing.T) { }) } +func TestActionService_DeleteWorkflowRun(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/actions/runs/399444496", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + + w.WriteHeader(http.StatusNoContent) + }) + + ctx := context.Background() + if _, err := client.Actions.DeleteWorkflowRun(ctx, "o", "r", 399444496); err != nil { + t.Errorf("DeleteWorkflowRun returned error: %v", err) + } + + const methodName = "DeleteWorkflowRun" + testBadOptions(t, methodName, func() (err error) { + _, err = client.Actions.DeleteWorkflowRun(ctx, "\n", "\n", 399444496) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Actions.DeleteWorkflowRun(ctx, "o", "r", 399444496) + }) +} + func TestActionService_DeleteWorkflowRunLogs(t *testing.T) { client, mux, _, teardown := setup() defer teardown() From 432a561e61b507457a5d585b635d2ef8424b40c2 Mon Sep 17 00:00:00 2001 From: Xabi Date: Mon, 22 Nov 2021 14:12:17 +0100 Subject: [PATCH 2/2] Fix function name godoc Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- github/actions_workflow_runs.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/github/actions_workflow_runs.go b/github/actions_workflow_runs.go index 5d22196727a..2c90956c268 100644 --- a/github/actions_workflow_runs.go +++ b/github/actions_workflow_runs.go @@ -211,7 +211,9 @@ func (s *ActionsService) GetWorkflowRunLogs(ctx context.Context, owner, repo str return parsedURL, newResponse(resp), err } -// DeleteWorkflowRunLogs deletes a workflow run by ID. +// DeleteWorkflowRun deletes a workflow run by ID. +// +// GitHub API docs: https://docs.github.com/en/rest/reference/actions#delete-a-workflow-run func (s *ActionsService) DeleteWorkflowRun(ctx context.Context, owner, repo string, runID int64) (*Response, error) { u := fmt.Sprintf("repos/%v/%v/actions/runs/%v", owner, repo, runID)