Skip to content

Commit 3d3636e

Browse files
committed
Add workflow run query builder for specific workflow
1 parent 362faaf commit 3d3636e

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ public PagedIterable<GHWorkflowRun> listRuns() {
156156
return new GHWorkflowRunsIterable(owner, root().createRequest().withUrlPath(getApiRoute(), "runs"));
157157
}
158158

159+
/**
160+
* Workflow run query builder for this workflow.
161+
*
162+
* @return the GHWorkflowRunQueryBuilder instance for querying runs
163+
*/
164+
public GHWorkflowRunQueryBuilder queryRuns() {
165+
return new GHWorkflowRunQueryBuilder(this);
166+
167+
}
168+
159169
private String getApiRoute() {
160170
if (owner == null) {
161171
// Workflow runs returned from search to do not have an owner. Attempt to use url.

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* @see GHRepository#queryWorkflowRuns()
1212
*/
1313
public class GHWorkflowRunQueryBuilder extends GHQueryBuilder<GHWorkflowRun> {
14+
private final GHWorkflow ghWorkflow;
1415
private final GHRepository repo;
1516

1617
/**
@@ -22,6 +23,19 @@ public class GHWorkflowRunQueryBuilder extends GHQueryBuilder<GHWorkflowRun> {
2223
GHWorkflowRunQueryBuilder(GHRepository repo) {
2324
super(repo.root());
2425
this.repo = repo;
26+
this.ghWorkflow = null;
27+
}
28+
29+
/**
30+
* Instantiates a new GH workflow run query builder for a specific workflow.
31+
*
32+
* @param ghWorkflow
33+
* the ghWorkflow
34+
*/
35+
GHWorkflowRunQueryBuilder(GHWorkflow ghWorkflow) {
36+
super(ghWorkflow.getRepository().root());
37+
this.repo = ghWorkflow.getRepository();
38+
this.ghWorkflow = ghWorkflow;
2539
}
2640

2741
/**
@@ -133,7 +147,12 @@ public GHWorkflowRunQueryBuilder headSha(String headSha) {
133147
*/
134148
@Override
135149
public PagedIterable<GHWorkflowRun> list() {
136-
return new GHWorkflowRunsIterable(repo, req.withUrlPath(repo.getApiTailUrl("actions/runs")));
150+
if (ghWorkflow != null) {
151+
req.withUrlPath(repo.getApiTailUrl("actions/workflows"), String.valueOf(ghWorkflow.getId()), "runs");
152+
} else {
153+
req.withUrlPath(repo.getApiTailUrl("actions/runs"));
154+
}
155+
return new GHWorkflowRunsIterable(repo, req);
137156
}
138157

139158
/**

0 commit comments

Comments
 (0)