From e0ce530425e3d2331a9622a3b18afd7d7ad3347e Mon Sep 17 00:00:00 2001 From: ayagmar <62888618+ayagmar@users.noreply.github.com> Date: Sun, 22 Mar 2026 18:09:47 +0100 Subject: [PATCH 1/2] feat(actions): support rerun failed jobs --- .../org/kohsuke/github/GHWorkflowRun.java | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHWorkflowRun.java b/src/main/java/org/kohsuke/github/GHWorkflowRun.java index e5a2456ec8..2489158626 100644 --- a/src/main/java/org/kohsuke/github/GHWorkflowRun.java +++ b/src/main/java/org/kohsuke/github/GHWorkflowRun.java @@ -598,7 +598,41 @@ public PagedIterable listJobs() { * the io exception */ public void rerun() throws IOException { - root().createRequest().method("POST").withUrlPath(getApiRoute(), "rerun").send(); + rerun(false); + } + + /** + * Rerun the workflow run. + * + * @param enableDebugLogging + * whether to enable debug logging for the rerun + * @throws IOException + * the io exception + */ + public void rerun(boolean enableDebugLogging) throws IOException { + rerun("rerun", enableDebugLogging); + } + + /** + * Rerun failed jobs and their dependent jobs for this workflow run. + * + * @throws IOException + * the io exception + */ + public void rerunFailedJobs() throws IOException { + rerunFailedJobs(false); + } + + /** + * Rerun failed jobs and their dependent jobs for this workflow run. + * + * @param enableDebugLogging + * whether to enable debug logging for the rerun + * @throws IOException + * the io exception + */ + public void rerunFailedJobs(boolean enableDebugLogging) throws IOException { + rerun("rerun-failed-jobs", enableDebugLogging); } private String getApiRoute() { @@ -611,6 +645,14 @@ private String getApiRoute() { return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/actions/runs/" + getId(); } + private void rerun(String endpoint, boolean enableDebugLogging) throws IOException { + Requester requester = root().createRequest().method("POST").withUrlPath(getApiRoute(), endpoint); + if (enableDebugLogging) { + requester.with("enable_debug_logging", true); + } + requester.send(); + } + /** * Wrap up. * From 810d74e2eff4129b5303d7717978fb779036959b Mon Sep 17 00:00:00 2001 From: ayagmar <62888618+ayagmar@users.noreply.github.com> Date: Sun, 22 Mar 2026 18:09:47 +0100 Subject: [PATCH 2/2] test(actions): cover workflow rerun variants --- .../org/kohsuke/github/GHWorkflowRunTest.java | 18 +++++++++++ .../testRerunVariants/__files/1-user.json | 3 ++ .../__files/2-r_h_ghworkflowruntest.json | 9 ++++++ .../3-r_h_g_actions_runs_686036126.json | 10 +++++++ .../testRerunVariants/mappings/1-user.json | 23 ++++++++++++++ .../mappings/2-r_h_ghworkflowruntest.json | 23 ++++++++++++++ .../3-r_h_g_actions_runs_686036126.json | 23 ++++++++++++++ ...ions_runs_686036126_rerun-failed-jobs.json | 30 +++++++++++++++++++ ...ions_runs_686036126_rerun-failed-jobs.json | 30 +++++++++++++++++++ .../6-r_h_g_actions_runs_686036126_rerun.json | 30 +++++++++++++++++++ .../7-r_h_g_actions_runs_686036126_rerun.json | 30 +++++++++++++++++++ 11 files changed, 229 insertions(+) create mode 100644 src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/__files/1-user.json create mode 100644 src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/__files/2-r_h_ghworkflowruntest.json create mode 100644 src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/__files/3-r_h_g_actions_runs_686036126.json create mode 100644 src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/1-user.json create mode 100644 src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/2-r_h_ghworkflowruntest.json create mode 100644 src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/3-r_h_g_actions_runs_686036126.json create mode 100644 src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/4-r_h_g_actions_runs_686036126_rerun-failed-jobs.json create mode 100644 src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/5-r_h_g_actions_runs_686036126_rerun-failed-jobs.json create mode 100644 src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/6-r_h_g_actions_runs_686036126_rerun.json create mode 100644 src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/7-r_h_g_actions_runs_686036126_rerun.json diff --git a/src/test/java/org/kohsuke/github/GHWorkflowRunTest.java b/src/test/java/org/kohsuke/github/GHWorkflowRunTest.java index f2eda74276..21c51c23fc 100644 --- a/src/test/java/org/kohsuke/github/GHWorkflowRunTest.java +++ b/src/test/java/org/kohsuke/github/GHWorkflowRunTest.java @@ -648,6 +648,24 @@ public void testManualRunAndBasicInformation() throws IOException { assertThat(workflowRun.getTriggeringActor(), hasProperty("login", equalTo("octocat_trigger"))); } + /** + * Test rerun variants. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testRerunVariants() throws IOException { + GHWorkflowRun workflowRun = repo.getWorkflowRun(686036126L); + + assertThat(workflowRun.getId(), is(686036126L)); + + workflowRun.rerunFailedJobs(); + workflowRun.rerunFailedJobs(true); + workflowRun.rerun(true); + workflowRun.rerun(); + } + /** * Test search on branch. * diff --git a/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/__files/1-user.json b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/__files/1-user.json new file mode 100644 index 0000000000..c2803cc815 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/__files/1-user.json @@ -0,0 +1,3 @@ +{ + "login": "ayagmar" +} diff --git a/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/__files/2-r_h_ghworkflowruntest.json b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/__files/2-r_h_ghworkflowruntest.json new file mode 100644 index 0000000000..f56c73309a --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/__files/2-r_h_ghworkflowruntest.json @@ -0,0 +1,9 @@ +{ + "id": 348674220, + "name": "GHWorkflowRunTest", + "full_name": "hub4j-test-org/GHWorkflowRunTest", + "url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest", + "owner": { + "login": "hub4j-test-org" + } +} diff --git a/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/__files/3-r_h_g_actions_runs_686036126.json b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/__files/3-r_h_g_actions_runs_686036126.json new file mode 100644 index 0000000000..10cc6c479b --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/__files/3-r_h_g_actions_runs_686036126.json @@ -0,0 +1,10 @@ +{ + "id": 686036126, + "name": "Slow workflow", + "url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/686036126", + "html_url": "https://github.com/hub4j-test-org/GHWorkflowRunTest/actions/runs/686036126", + "status": "completed", + "conclusion": "failure", + "workflow_id": 6820849, + "run_attempt": 1 +} diff --git a/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/1-user.json b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/1-user.json new file mode 100644 index 0000000000..5bef72a999 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/1-user.json @@ -0,0 +1,23 @@ +{ + "id": "3e7dbf87-7930-4d75-aa8d-d65b76de98dc", + "name": "user", + "request": { + "url": "/user", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-user.json", + "headers": { + "Content-Type": "application/json; charset=utf-8" + } + }, + "uuid": "3e7dbf87-7930-4d75-aa8d-d65b76de98dc", + "persistent": true, + "insertionIndex": 1 +} diff --git a/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/2-r_h_ghworkflowruntest.json b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/2-r_h_ghworkflowruntest.json new file mode 100644 index 0000000000..210b9ce9dd --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/2-r_h_ghworkflowruntest.json @@ -0,0 +1,23 @@ +{ + "id": "fd7591c0-77eb-4e52-9b4b-0dc73777a5a0", + "name": "repos_hub4j-test-org_ghworkflowruntest", + "request": { + "url": "/repos/hub4j-test-org/GHWorkflowRunTest", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-r_h_ghworkflowruntest.json", + "headers": { + "Content-Type": "application/json; charset=utf-8" + } + }, + "uuid": "fd7591c0-77eb-4e52-9b4b-0dc73777a5a0", + "persistent": true, + "insertionIndex": 2 +} diff --git a/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/3-r_h_g_actions_runs_686036126.json b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/3-r_h_g_actions_runs_686036126.json new file mode 100644 index 0000000000..1b6cb31687 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/3-r_h_g_actions_runs_686036126.json @@ -0,0 +1,23 @@ +{ + "id": "77e5d70a-1cf7-44bf-b170-c458d7060d65", + "name": "repos_hub4j-test-org_ghworkflowruntest_actions_runs_686036126", + "request": { + "url": "/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/686036126", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "3-r_h_g_actions_runs_686036126.json", + "headers": { + "Content-Type": "application/json; charset=utf-8" + } + }, + "uuid": "77e5d70a-1cf7-44bf-b170-c458d7060d65", + "persistent": true, + "insertionIndex": 3 +} diff --git a/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/4-r_h_g_actions_runs_686036126_rerun-failed-jobs.json b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/4-r_h_g_actions_runs_686036126_rerun-failed-jobs.json new file mode 100644 index 0000000000..84e6f34f54 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/4-r_h_g_actions_runs_686036126_rerun-failed-jobs.json @@ -0,0 +1,30 @@ +{ + "id": "16330f88-a67e-41e6-b636-58db8d3e8f0c", + "name": "repos_hub4j-test-org_ghworkflowruntest_actions_runs_686036126_rerun_failed_jobs", + "request": { + "url": "/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/686036126/rerun-failed-jobs", + "method": "POST", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + }, + "bodyPatterns": [ + { + "equalToJson": "{}", + "ignoreArrayOrder": true, + "ignoreExtraElements": false + } + ] + }, + "response": { + "status": 201, + "body": "{}", + "headers": { + "Content-Type": "application/json; charset=utf-8" + } + }, + "uuid": "16330f88-a67e-41e6-b636-58db8d3e8f0c", + "persistent": true, + "insertionIndex": 4 +} diff --git a/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/5-r_h_g_actions_runs_686036126_rerun-failed-jobs.json b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/5-r_h_g_actions_runs_686036126_rerun-failed-jobs.json new file mode 100644 index 0000000000..6c4135fa72 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/5-r_h_g_actions_runs_686036126_rerun-failed-jobs.json @@ -0,0 +1,30 @@ +{ + "id": "8b165443-a354-489f-8fee-73801637dbfd", + "name": "repos_hub4j-test-org_ghworkflowruntest_actions_runs_686036126_rerun_failed_jobs_debug", + "request": { + "url": "/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/686036126/rerun-failed-jobs", + "method": "POST", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + }, + "bodyPatterns": [ + { + "equalToJson": "{\"enable_debug_logging\":true}", + "ignoreArrayOrder": true, + "ignoreExtraElements": false + } + ] + }, + "response": { + "status": 201, + "body": "{}", + "headers": { + "Content-Type": "application/json; charset=utf-8" + } + }, + "uuid": "8b165443-a354-489f-8fee-73801637dbfd", + "persistent": true, + "insertionIndex": 5 +} diff --git a/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/6-r_h_g_actions_runs_686036126_rerun.json b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/6-r_h_g_actions_runs_686036126_rerun.json new file mode 100644 index 0000000000..9a498ec76a --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/6-r_h_g_actions_runs_686036126_rerun.json @@ -0,0 +1,30 @@ +{ + "id": "d5f0000f-e754-447c-84fd-804df2dbed78", + "name": "repos_hub4j-test-org_ghworkflowruntest_actions_runs_686036126_rerun_debug", + "request": { + "url": "/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/686036126/rerun", + "method": "POST", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + }, + "bodyPatterns": [ + { + "equalToJson": "{\"enable_debug_logging\":true}", + "ignoreArrayOrder": true, + "ignoreExtraElements": false + } + ] + }, + "response": { + "status": 201, + "body": "{}", + "headers": { + "Content-Type": "application/json; charset=utf-8" + } + }, + "uuid": "d5f0000f-e754-447c-84fd-804df2dbed78", + "persistent": true, + "insertionIndex": 6 +} diff --git a/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/7-r_h_g_actions_runs_686036126_rerun.json b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/7-r_h_g_actions_runs_686036126_rerun.json new file mode 100644 index 0000000000..9775910ab4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testRerunVariants/mappings/7-r_h_g_actions_runs_686036126_rerun.json @@ -0,0 +1,30 @@ +{ + "id": "4d1bb285-92fe-49d8-a4bf-72a08ca8a7d6", + "name": "repos_hub4j-test-org_ghworkflowruntest_actions_runs_686036126_rerun", + "request": { + "url": "/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/686036126/rerun", + "method": "POST", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + }, + "bodyPatterns": [ + { + "equalToJson": "{}", + "ignoreArrayOrder": true, + "ignoreExtraElements": false + } + ] + }, + "response": { + "status": 201, + "body": "{}", + "headers": { + "Content-Type": "application/json; charset=utf-8" + } + }, + "uuid": "4d1bb285-92fe-49d8-a4bf-72a08ca8a7d6", + "persistent": true, + "insertionIndex": 7 +}