Skip to content

Commit 8947206

Browse files
authored
Add RerunFailedJobsByID and RerunJobByID (#2345)
1 parent 4174796 commit 8947206

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

github/actions_workflow_runs.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,34 @@ func (s *ActionsService) RerunWorkflowByID(ctx context.Context, owner, repo stri
211211
return s.client.Do(ctx, req, nil)
212212
}
213213

214+
// RerunFailedJobsByID re-runs all of the failed jobs and their dependent jobs in a workflow run by ID.
215+
//
216+
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/actions/workflow-runs#re-run-failed-jobs-from-a-workflow-run
217+
func (s *ActionsService) RerunFailedJobsByID(ctx context.Context, owner, repo string, runID int64) (*Response, error) {
218+
u := fmt.Sprintf("repos/%v/%v/actions/runs/%v/rerun-failed-jobs", owner, repo, runID)
219+
220+
req, err := s.client.NewRequest("POST", u, nil)
221+
if err != nil {
222+
return nil, err
223+
}
224+
225+
return s.client.Do(ctx, req, nil)
226+
}
227+
228+
// RerunJobByID re-runs a job and its dependent jobs in a workflow run by ID.
229+
//
230+
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/actions/workflow-runs#re-run-a-job-from-a-workflow-run
231+
func (s *ActionsService) RerunJobByID(ctx context.Context, owner, repo string, jobID int64) (*Response, error) {
232+
u := fmt.Sprintf("repos/%v/%v/actions/jobs/%v/rerun", owner, repo, jobID)
233+
234+
req, err := s.client.NewRequest("POST", u, nil)
235+
if err != nil {
236+
return nil, err
237+
}
238+
239+
return s.client.Do(ctx, req, nil)
240+
}
241+
214242
// CancelWorkflowRunByID cancels a workflow run by ID.
215243
//
216244
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#cancel-a-workflow-run

github/actions_workflow_runs_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,64 @@ func TestActionsService_RerunWorkflowRunByID(t *testing.T) {
216216
})
217217
}
218218

219+
func TestActionsService_RerunFailedJobsByID(t *testing.T) {
220+
client, mux, _, teardown := setup()
221+
defer teardown()
222+
223+
mux.HandleFunc("/repos/o/r/actions/runs/3434/rerun-failed-jobs", func(w http.ResponseWriter, r *http.Request) {
224+
testMethod(t, r, "POST")
225+
w.WriteHeader(http.StatusCreated)
226+
})
227+
228+
ctx := context.Background()
229+
resp, err := client.Actions.RerunFailedJobsByID(ctx, "o", "r", 3434)
230+
if err != nil {
231+
t.Errorf("Actions.RerunFailedJobsByID returned error: %v", err)
232+
}
233+
if resp.StatusCode != http.StatusCreated {
234+
t.Errorf("Actions.RerunFailedJobsByID returned status: %d, want %d", resp.StatusCode, http.StatusCreated)
235+
}
236+
237+
const methodName = "RerunFailedJobsByID"
238+
testBadOptions(t, methodName, func() (err error) {
239+
_, err = client.Actions.RerunFailedJobsByID(ctx, "\n", "\n", 3434)
240+
return err
241+
})
242+
243+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
244+
return client.Actions.RerunFailedJobsByID(ctx, "o", "r", 3434)
245+
})
246+
}
247+
248+
func TestActionsService_RerunJobByID(t *testing.T) {
249+
client, mux, _, teardown := setup()
250+
defer teardown()
251+
252+
mux.HandleFunc("/repos/o/r/actions/jobs/3434/rerun", func(w http.ResponseWriter, r *http.Request) {
253+
testMethod(t, r, "POST")
254+
w.WriteHeader(http.StatusCreated)
255+
})
256+
257+
ctx := context.Background()
258+
resp, err := client.Actions.RerunJobByID(ctx, "o", "r", 3434)
259+
if err != nil {
260+
t.Errorf("Actions.RerunJobByID returned error: %v", err)
261+
}
262+
if resp.StatusCode != http.StatusCreated {
263+
t.Errorf("Actions.RerunJobByID returned status: %d, want %d", resp.StatusCode, http.StatusCreated)
264+
}
265+
266+
const methodName = "RerunJobByID"
267+
testBadOptions(t, methodName, func() (err error) {
268+
_, err = client.Actions.RerunJobByID(ctx, "\n", "\n", 3434)
269+
return err
270+
})
271+
272+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
273+
return client.Actions.RerunJobByID(ctx, "o", "r", 3434)
274+
})
275+
}
276+
219277
func TestActionsService_CancelWorkflowRunByID(t *testing.T) {
220278
client, mux, _, teardown := setup()
221279
defer teardown()

0 commit comments

Comments
 (0)