Skip to content

Commit cf35a7e

Browse files
committed
Added WorkflowJobsClient
The WorkflowJobsClient provides the following: * listWorkflowJobs - get workflow jobs for a given workflow run * getWorkflowJob - get a workflow job by ID listWorkflowJobs support filtering via query parameters.
1 parent c1f9c52 commit cf35a7e

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

src/main/java/com/spotify/github/v3/clients/ActionsClient.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,13 @@ static ActionsClient create(final GitHubClient github, final String owner, final
4343
public WorkflowsClient createWorkflowsClient() {
4444
return WorkflowsClient.create(github, owner, repo);
4545
}
46+
47+
/**
48+
* Workflow Jobs API client
49+
*
50+
* @return WorkflowJobs API client
51+
*/
52+
public WorkflowJobsClient createWorkflowJobsClient() {
53+
return WorkflowJobsClient.create(github, owner, repo);
54+
}
4655
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*-
2+
* -\-\-
3+
* github-api
4+
* --
5+
* Copyright (C) 2016 - 2020 Spotify AB
6+
* --
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* -/-/-
19+
*/
20+
21+
package com.spotify.github.v3.clients;
22+
23+
import com.google.common.base.Strings;
24+
import com.google.common.collect.ImmutableMap;
25+
import com.spotify.github.v3.actions.workflowjobs.ListWorkflowJobsQueryParams;
26+
import com.spotify.github.v3.actions.workflowjobs.WorkflowJobResponse;
27+
import com.spotify.github.v3.actions.workflowjobs.WorkflowJobsResponseList;
28+
29+
import javax.annotation.Nullable;
30+
import javax.ws.rs.core.HttpHeaders;
31+
import java.util.Map;
32+
import java.util.concurrent.CompletableFuture;
33+
34+
/**
35+
* Workflow Runs API client
36+
*/
37+
public class WorkflowJobsClient {
38+
private static final String LIST_WORKFLOW_RUN_JOBS_URI = "/repos/%s/%s/actions/runs/%s/jobs";
39+
private static final String GET_WORKFLOW_JOB_URI = "/repos/%s/%s/actions/jobs/%s";
40+
41+
private final GitHubClient github;
42+
private final String owner;
43+
private final String repo;
44+
45+
private final Map<String, String> extraHeaders =
46+
ImmutableMap.of(HttpHeaders.ACCEPT, "application/vnd.github+json");
47+
48+
public WorkflowJobsClient(final GitHubClient github, final String owner, final String repo) {
49+
this.github = github;
50+
this.owner = owner;
51+
this.repo = repo;
52+
}
53+
54+
static WorkflowJobsClient create(final GitHubClient github, final String owner, final String repo) {
55+
return new WorkflowJobsClient(github, owner, repo);
56+
}
57+
58+
/**
59+
* List all workflow run jobs for a repository.
60+
*
61+
* @param queryParams optional parameters to add to the query. Can be null.
62+
* @return a list of workflow run jobs for the repository
63+
*/
64+
public CompletableFuture<WorkflowJobsResponseList> listWorkflowJobs(final long runId, @Nullable final ListWorkflowJobsQueryParams queryParams) {
65+
final String serial = (queryParams == null ? "" : queryParams.serialize());
66+
final String path = String.format(LIST_WORKFLOW_RUN_JOBS_URI, owner, repo, runId) + (Strings.isNullOrEmpty(serial) ? "" : "?" + serial);
67+
return github.request(path, WorkflowJobsResponseList.class, extraHeaders);
68+
}
69+
70+
/**
71+
* Gets a workflow job by id.
72+
*
73+
* @param jobId the workflow job id to be retrieved
74+
* @return a WorkflowRunResponse
75+
*/
76+
public CompletableFuture<WorkflowJobResponse> getWorkflowJob(final long jobId, @Nullable final ListWorkflowJobsQueryParams queryParams) {
77+
final String serial = (queryParams == null ? "" : queryParams.serialize());
78+
final String path = String.format(GET_WORKFLOW_JOB_URI, owner, repo, jobId) + (Strings.isNullOrEmpty(serial) ? "" : "?" + serial);
79+
return github.request(path, WorkflowJobResponse.class, extraHeaders);
80+
}
81+
}

0 commit comments

Comments
 (0)