Skip to content

Commit 258acf7

Browse files
committed
Small adjustments to the API exposed to get jobs
1 parent b509076 commit 258acf7

File tree

30 files changed

+723
-798
lines changed

30 files changed

+723
-798
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,21 @@ public void deleteLogs() throws IOException {
314314
}
315315

316316
/**
317-
* Retrieves the jobs of this workflow run.
317+
* Returns this list of jobs of this workflow run for the last execution.
318318
*
319-
* @return the jobs query builder
319+
* @return list of jobs from the last execution
320320
*/
321-
public GHWorkflowRunJobQueryBuilder queryJobs() {
322-
return new GHWorkflowRunJobQueryBuilder(this);
321+
public PagedIterable<GHWorkflowRunJob> listJobs() {
322+
return new GHWorkflowRunJobQueryBuilder(this).latest().list();
323+
}
324+
325+
/**
326+
* Returns this list of jobs from all the executions of this workflow run.
327+
*
328+
* @return list of jobs from all the executions
329+
*/
330+
public PagedIterable<GHWorkflowRunJob> listAllJobs() {
331+
return new GHWorkflowRunJobQueryBuilder(this).all().list();
323332
}
324333

325334
private String getApiRoute() {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import static org.hamcrest.Matchers.containsString;
2424
import static org.hamcrest.Matchers.greaterThan;
25+
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
2526
import static org.hamcrest.Matchers.hasItems;
2627
import static org.hamcrest.Matchers.is;
2728

@@ -338,9 +339,7 @@ public void testJobs() throws IOException {
338339
latestPreexistingWorkflowRunId).orElseThrow(
339340
() -> new IllegalStateException("We must have a valid workflow run starting from here"));
340341

341-
List<GHWorkflowRunJob> jobs = workflowRun.queryJobs()
342-
.latest()
343-
.list()
342+
List<GHWorkflowRunJob> jobs = workflowRun.listJobs()
344343
.toList()
345344
.stream()
346345
.sorted((j1, j2) -> j1.getName().compareTo(j2.getName()))
@@ -361,6 +360,10 @@ public void testJobs() throws IOException {
361360
// while we have a job around, test GHRepository#getWorkflowRunJob(id)
362361
GHWorkflowRunJob job1ById = repo.getWorkflowRunJob(job1.getId());
363362
checkJobProperties(workflowRun.getId(), job1ById, "job1");
363+
364+
// Also test listAllJobs() works correctly
365+
List<GHWorkflowRunJob> allJobs = workflowRun.listAllJobs().withPageSize(10).iterator().nextPage();
366+
assertThat(allJobs.size(), greaterThanOrEqualTo(2));
364367
}
365368

366369
private void await(Function<GHRepository, Boolean> condition) throws IOException {

src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testJobs/__files/repos_hub4j-test-org_ghworkflowruntest_actions_jobs__2269946728-10.json renamed to src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testJobs/__files/repos_hub4j-test-org_ghworkflowruntest_actions_jobs__2270858630-10.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
{
2-
"id": 2269946728,
3-
"run_id": 719290617,
4-
"run_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/719290617",
5-
"node_id": "MDg6Q2hlY2tSdW4yMjY5OTQ2NzI4",
2+
"id": 2270858630,
3+
"run_id": 719643947,
4+
"run_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/719643947",
5+
"node_id": "MDg6Q2hlY2tSdW4yMjcwODU4NjMw",
66
"head_sha": "c7bd3b8db871bbde8629275631ea645622ae89d7",
7-
"url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/jobs/2269946728",
8-
"html_url": "https://github.com/hub4j-test-org/GHWorkflowRunTest/runs/2269946728",
7+
"url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/jobs/2270858630",
8+
"html_url": "https://github.com/hub4j-test-org/GHWorkflowRunTest/runs/2270858630",
99
"status": "completed",
1010
"conclusion": "success",
11-
"started_at": "2021-04-05T13:14:37Z",
12-
"completed_at": "2021-04-05T13:14:38Z",
11+
"started_at": "2021-04-05T15:42:57Z",
12+
"completed_at": "2021-04-05T15:42:59Z",
1313
"name": "job1",
1414
"steps": [
1515
{
1616
"name": "Set up job",
1717
"status": "completed",
1818
"conclusion": "success",
1919
"number": 1,
20-
"started_at": "2021-04-05T15:14:37.000+02:00",
21-
"completed_at": "2021-04-05T15:14:37.000+02:00"
20+
"started_at": "2021-04-05T17:42:57.000+02:00",
21+
"completed_at": "2021-04-05T17:42:58.000+02:00"
2222
},
2323
{
2424
"name": "Run a one-line script",
2525
"status": "completed",
2626
"conclusion": "success",
2727
"number": 2,
28-
"started_at": "2021-04-05T15:14:37.000+02:00",
29-
"completed_at": "2021-04-05T15:14:38.000+02:00"
28+
"started_at": "2021-04-05T17:42:58.000+02:00",
29+
"completed_at": "2021-04-05T17:42:59.000+02:00"
3030
},
3131
{
3232
"name": "Complete job",
3333
"status": "completed",
3434
"conclusion": "success",
3535
"number": 3,
36-
"started_at": "2021-04-05T15:14:38.000+02:00",
37-
"completed_at": "2021-04-05T15:14:38.000+02:00"
36+
"started_at": "2021-04-05T17:42:59.000+02:00",
37+
"completed_at": "2021-04-05T17:42:59.000+02:00"
3838
}
3939
],
40-
"check_run_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/check-runs/2269946728"
40+
"check_run_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/check-runs/2270858630"
4141
}

src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testJobs/__files/repos_hub4j-test-org_ghworkflowruntest_actions_runs-4.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
{
2-
"total_count": 111,
2+
"total_count": 114,
33
"workflow_runs": [
44
{
5-
"id": 719256201,
5+
"id": 719641767,
66
"name": "Multi jobs workflow",
7-
"node_id": "MDExOldvcmtmbG93UnVuNzE5MjU2MjAx",
7+
"node_id": "MDExOldvcmtmbG93UnVuNzE5NjQxNzY3",
88
"head_branch": "main",
99
"head_sha": "c7bd3b8db871bbde8629275631ea645622ae89d7",
10-
"run_number": 11,
10+
"run_number": 14,
1111
"event": "workflow_dispatch",
1212
"status": "completed",
1313
"conclusion": "success",
1414
"workflow_id": 7518893,
15-
"check_suite_id": 2421886985,
16-
"check_suite_node_id": "MDEwOkNoZWNrU3VpdGUyNDIxODg2OTg1",
17-
"url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/719256201",
18-
"html_url": "https://github.com/hub4j-test-org/GHWorkflowRunTest/actions/runs/719256201",
15+
"check_suite_id": 2422908957,
16+
"check_suite_node_id": "MDEwOkNoZWNrU3VpdGUyNDIyOTA4OTU3",
17+
"url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/719641767",
18+
"html_url": "https://github.com/hub4j-test-org/GHWorkflowRunTest/actions/runs/719641767",
1919
"pull_requests": [],
20-
"created_at": "2021-04-05T13:00:01Z",
21-
"updated_at": "2021-04-05T13:00:17Z",
22-
"jobs_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/719256201/jobs",
23-
"logs_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/719256201/logs",
24-
"check_suite_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/check-suites/2421886985",
25-
"artifacts_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/719256201/artifacts",
26-
"cancel_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/719256201/cancel",
27-
"rerun_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/719256201/rerun",
20+
"created_at": "2021-04-05T15:41:54Z",
21+
"updated_at": "2021-04-05T15:42:11Z",
22+
"jobs_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/719641767/jobs",
23+
"logs_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/719641767/logs",
24+
"check_suite_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/check-suites/2422908957",
25+
"artifacts_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/719641767/artifacts",
26+
"cancel_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/719641767/cancel",
27+
"rerun_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/719641767/rerun",
2828
"workflow_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/workflows/7518893",
2929
"head_commit": {
3030
"id": "c7bd3b8db871bbde8629275631ea645622ae89d7",

0 commit comments

Comments
 (0)