Skip to content

Commit 53e81ba

Browse files
authored
Merge pull request #2210 from ayagmar/feat/rerun-failed-jobs
Add support for rerunning failed workflow jobs
2 parents 4be498e + 810d74e commit 53e81ba

12 files changed

Lines changed: 272 additions & 1 deletion

src/main/java/org/kohsuke/github/GHWorkflowRun.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,41 @@ public PagedIterable<GHWorkflowJob> listJobs() {
598598
* the io exception
599599
*/
600600
public void rerun() throws IOException {
601-
root().createRequest().method("POST").withUrlPath(getApiRoute(), "rerun").send();
601+
rerun(false);
602+
}
603+
604+
/**
605+
* Rerun the workflow run.
606+
*
607+
* @param enableDebugLogging
608+
* whether to enable debug logging for the rerun
609+
* @throws IOException
610+
* the io exception
611+
*/
612+
public void rerun(boolean enableDebugLogging) throws IOException {
613+
rerun("rerun", enableDebugLogging);
614+
}
615+
616+
/**
617+
* Rerun failed jobs and their dependent jobs for this workflow run.
618+
*
619+
* @throws IOException
620+
* the io exception
621+
*/
622+
public void rerunFailedJobs() throws IOException {
623+
rerunFailedJobs(false);
624+
}
625+
626+
/**
627+
* Rerun failed jobs and their dependent jobs for this workflow run.
628+
*
629+
* @param enableDebugLogging
630+
* whether to enable debug logging for the rerun
631+
* @throws IOException
632+
* the io exception
633+
*/
634+
public void rerunFailedJobs(boolean enableDebugLogging) throws IOException {
635+
rerun("rerun-failed-jobs", enableDebugLogging);
602636
}
603637

604638
private String getApiRoute() {
@@ -611,6 +645,14 @@ private String getApiRoute() {
611645
return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/actions/runs/" + getId();
612646
}
613647

648+
private void rerun(String endpoint, boolean enableDebugLogging) throws IOException {
649+
Requester requester = root().createRequest().method("POST").withUrlPath(getApiRoute(), endpoint);
650+
if (enableDebugLogging) {
651+
requester.with("enable_debug_logging", true);
652+
}
653+
requester.send();
654+
}
655+
614656
/**
615657
* Wrap up.
616658
*

src/test/java/org/kohsuke/github/GHWorkflowRunTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,24 @@ public void testManualRunAndBasicInformation() throws IOException {
648648
assertThat(workflowRun.getTriggeringActor(), hasProperty("login", equalTo("octocat_trigger")));
649649
}
650650

651+
/**
652+
* Test rerun variants.
653+
*
654+
* @throws IOException
655+
* Signals that an I/O exception has occurred.
656+
*/
657+
@Test
658+
public void testRerunVariants() throws IOException {
659+
GHWorkflowRun workflowRun = repo.getWorkflowRun(686036126L);
660+
661+
assertThat(workflowRun.getId(), is(686036126L));
662+
663+
workflowRun.rerunFailedJobs();
664+
workflowRun.rerunFailedJobs(true);
665+
workflowRun.rerun(true);
666+
workflowRun.rerun();
667+
}
668+
651669
/**
652670
* Test search on branch.
653671
*
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"login": "ayagmar"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"id": 348674220,
3+
"name": "GHWorkflowRunTest",
4+
"full_name": "hub4j-test-org/GHWorkflowRunTest",
5+
"url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest",
6+
"owner": {
7+
"login": "hub4j-test-org"
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"id": 686036126,
3+
"name": "Slow workflow",
4+
"url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/686036126",
5+
"html_url": "https://github.com/hub4j-test-org/GHWorkflowRunTest/actions/runs/686036126",
6+
"status": "completed",
7+
"conclusion": "failure",
8+
"workflow_id": 6820849,
9+
"run_attempt": 1
10+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"id": "3e7dbf87-7930-4d75-aa8d-d65b76de98dc",
3+
"name": "user",
4+
"request": {
5+
"url": "/user",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github+json"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "1-user.json",
16+
"headers": {
17+
"Content-Type": "application/json; charset=utf-8"
18+
}
19+
},
20+
"uuid": "3e7dbf87-7930-4d75-aa8d-d65b76de98dc",
21+
"persistent": true,
22+
"insertionIndex": 1
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"id": "fd7591c0-77eb-4e52-9b4b-0dc73777a5a0",
3+
"name": "repos_hub4j-test-org_ghworkflowruntest",
4+
"request": {
5+
"url": "/repos/hub4j-test-org/GHWorkflowRunTest",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github+json"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "2-r_h_ghworkflowruntest.json",
16+
"headers": {
17+
"Content-Type": "application/json; charset=utf-8"
18+
}
19+
},
20+
"uuid": "fd7591c0-77eb-4e52-9b4b-0dc73777a5a0",
21+
"persistent": true,
22+
"insertionIndex": 2
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"id": "77e5d70a-1cf7-44bf-b170-c458d7060d65",
3+
"name": "repos_hub4j-test-org_ghworkflowruntest_actions_runs_686036126",
4+
"request": {
5+
"url": "/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/686036126",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github+json"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "3-r_h_g_actions_runs_686036126.json",
16+
"headers": {
17+
"Content-Type": "application/json; charset=utf-8"
18+
}
19+
},
20+
"uuid": "77e5d70a-1cf7-44bf-b170-c458d7060d65",
21+
"persistent": true,
22+
"insertionIndex": 3
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"id": "16330f88-a67e-41e6-b636-58db8d3e8f0c",
3+
"name": "repos_hub4j-test-org_ghworkflowruntest_actions_runs_686036126_rerun_failed_jobs",
4+
"request": {
5+
"url": "/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/686036126/rerun-failed-jobs",
6+
"method": "POST",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github+json"
10+
}
11+
},
12+
"bodyPatterns": [
13+
{
14+
"equalToJson": "{}",
15+
"ignoreArrayOrder": true,
16+
"ignoreExtraElements": false
17+
}
18+
]
19+
},
20+
"response": {
21+
"status": 201,
22+
"body": "{}",
23+
"headers": {
24+
"Content-Type": "application/json; charset=utf-8"
25+
}
26+
},
27+
"uuid": "16330f88-a67e-41e6-b636-58db8d3e8f0c",
28+
"persistent": true,
29+
"insertionIndex": 4
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"id": "8b165443-a354-489f-8fee-73801637dbfd",
3+
"name": "repos_hub4j-test-org_ghworkflowruntest_actions_runs_686036126_rerun_failed_jobs_debug",
4+
"request": {
5+
"url": "/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/686036126/rerun-failed-jobs",
6+
"method": "POST",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github+json"
10+
}
11+
},
12+
"bodyPatterns": [
13+
{
14+
"equalToJson": "{\"enable_debug_logging\":true}",
15+
"ignoreArrayOrder": true,
16+
"ignoreExtraElements": false
17+
}
18+
]
19+
},
20+
"response": {
21+
"status": 201,
22+
"body": "{}",
23+
"headers": {
24+
"Content-Type": "application/json; charset=utf-8"
25+
}
26+
},
27+
"uuid": "8b165443-a354-489f-8fee-73801637dbfd",
28+
"persistent": true,
29+
"insertionIndex": 5
30+
}

0 commit comments

Comments
 (0)