Skip to content

Commit 29407dc

Browse files
committed
add get pipeline end point
1 parent 86867ab commit 29407dc

File tree

12 files changed

+783
-6
lines changed

12 files changed

+783
-6
lines changed

src/main/java/org/sourcelab/buildkite/api/client/BuildkiteClient.java

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,35 @@
2929
import org.sourcelab.buildkite.api.client.request.DeleteAccessTokenRequest;
3030
import org.sourcelab.buildkite.api.client.request.GetAccessTokenRequest;
3131
import org.sourcelab.buildkite.api.client.request.GetMetaRequest;
32+
import org.sourcelab.buildkite.api.client.request.GetOrganizationRequest;
33+
import org.sourcelab.buildkite.api.client.request.GetPipelineRequest;
3234
import org.sourcelab.buildkite.api.client.request.GetUserRequest;
3335
import org.sourcelab.buildkite.api.client.request.ListBuildsRequest;
3436
import org.sourcelab.buildkite.api.client.request.ListEmojisRequest;
3537
import org.sourcelab.buildkite.api.client.request.ListOrganizationsRequest;
38+
import org.sourcelab.buildkite.api.client.request.ListPipelinesRequest;
3639
import org.sourcelab.buildkite.api.client.request.OrganizationFilters;
3740
import org.sourcelab.buildkite.api.client.request.OrganizationFiltersBuilder;
3841
import org.sourcelab.buildkite.api.client.request.PageOptions;
3942
import org.sourcelab.buildkite.api.client.request.PageableRequest;
4043
import org.sourcelab.buildkite.api.client.request.PingRequest;
44+
import org.sourcelab.buildkite.api.client.request.PipelineFiltersBuilder;
45+
import org.sourcelab.buildkite.api.client.request.PipelineFilters;
4146
import org.sourcelab.buildkite.api.client.request.Request;
4247
import org.sourcelab.buildkite.api.client.response.AccessTokenResponse;
4348
import org.sourcelab.buildkite.api.client.response.CurrentUserResponse;
4449
import org.sourcelab.buildkite.api.client.response.Emoji;
4550
import org.sourcelab.buildkite.api.client.response.ErrorResponse;
4651
import org.sourcelab.buildkite.api.client.response.ListBuildsResponse;
4752
import org.sourcelab.buildkite.api.client.response.ListOrganizationsResponse;
53+
import org.sourcelab.buildkite.api.client.response.ListPipelinesResponse;
4854
import org.sourcelab.buildkite.api.client.response.MetaResponse;
4955
import org.sourcelab.buildkite.api.client.response.Organization;
5056
import org.sourcelab.buildkite.api.client.response.PageableResponse;
5157
import org.sourcelab.buildkite.api.client.response.PagingLinks;
5258
import org.sourcelab.buildkite.api.client.response.PingResponse;
59+
import org.sourcelab.buildkite.api.client.response.Pipeline;
5360
import org.sourcelab.buildkite.api.client.response.parser.ErrorResponseParser;
54-
import org.sourcelab.buildkite.api.client.response.parser.ListOrganizationsResponseParser;
5561

5662
import java.io.IOException;
5763
import java.util.List;
@@ -168,10 +174,67 @@ public ListOrganizationsResponse listOrganizations(final OrganizationFilters fil
168174
*/
169175
public Optional<Organization> getOrganization(final String organizationSlugId) throws BuildkiteException {
170176
Objects.requireNonNull(organizationSlugId);
171-
final ListOrganizationsResponse response = listOrganizations(OrganizationFilters.newBuilder()
172-
.withOrganization(organizationSlugId)
177+
final Organization response = executeRequest(new GetOrganizationRequest(organizationSlugId));
178+
return Optional.ofNullable(response);
179+
}
180+
181+
/**
182+
* Retrieve all Pipeline accessible to the current user/API access token for the given Organization.
183+
* Results will be paged.
184+
*
185+
* @param filters Filter criteria.
186+
* @return All Pipelines accessible to the current user/API access token. Results
187+
* will be paged if the number of results exceeds 30.
188+
* @throws BuildkiteException if API returns an error response.
189+
*/
190+
public ListPipelinesResponse listPipelines(final PipelineFiltersBuilder filters) throws BuildkiteException {
191+
Objects.requireNonNull(filters);
192+
return listPipelines(filters.build());
193+
}
194+
195+
/**
196+
* Retrieve all Pipelines accessible to the current user/API access token for the given Organization.
197+
* Results will be paged.
198+
*
199+
* @param filters Filter criteria.
200+
* @return All Pipelines accessible to the current user/API access token. Results
201+
* will be paged if the number of results exceeds 30.
202+
* @throws BuildkiteException if API returns an error response.
203+
*/
204+
public ListPipelinesResponse listPipelines(final PipelineFilters filters) throws BuildkiteException {
205+
Objects.requireNonNull(filters);
206+
return executeRequest(new ListPipelinesRequest(filters));
207+
}
208+
209+
/**
210+
* Retrieve all Pipelines accessible to the current user/API access token for the given Organization.
211+
* Results will be paged.
212+
*
213+
* @param organizationSlugId Organization Slug Id to retrieve pipelines for.
214+
* @return All Pipelines accessible to the current user/API access token for the given Organization. Results
215+
* will be paged if the number of results exceeds 30.
216+
* @throws BuildkiteException if API returns an error response.
217+
*/
218+
public ListPipelinesResponse listPipelines(final String organizationSlugId) throws BuildkiteException {
219+
Objects.requireNonNull(organizationSlugId);
220+
return listPipelines(PipelineFilters.newBuilder()
221+
.withOrganization(organizationSlugId)
173222
);
174-
return response.getOrganizationBySlug(organizationSlugId);
223+
}
224+
225+
/**
226+
* Retrieve specific pipeline via its Organization and Pipeline Slug Ids.
227+
*
228+
* @param organizationSlugId Slug of the organization to retrieve.
229+
* @param pipelineSlugId Slug of the pipeline to retrieve.
230+
* @return Pipeline matching the slug, if found.
231+
* @throws BuildkiteException if API returns an error response.
232+
*/
233+
public Optional<Pipeline> getPipeline(final String organizationSlugId, final String pipelineSlugId) throws BuildkiteException {
234+
Objects.requireNonNull(organizationSlugId);
235+
Objects.requireNonNull(pipelineSlugId);
236+
final Pipeline pipeline = executeRequest(new GetPipelineRequest(organizationSlugId, pipelineSlugId));
237+
return Optional.ofNullable(pipeline);
175238
}
176239

177240
/**
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright 2023 SourceLab.org https://github.com/SourceLabOrg/Buildkite-Api-Client
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7+
* persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package org.sourcelab.buildkite.api.client.request;
19+
20+
import org.sourcelab.buildkite.api.client.response.Organization;
21+
import org.sourcelab.buildkite.api.client.response.parser.GetOrganizationResponseParser;
22+
import org.sourcelab.buildkite.api.client.response.parser.ResponseParser;
23+
24+
import java.util.Objects;
25+
26+
public class GetOrganizationRequest extends GetRequest<Organization> {
27+
private final String orgIdSlug;
28+
29+
/**
30+
* Constructor.
31+
* @param orgIdSlug Organization to retrieve.
32+
*/
33+
public GetOrganizationRequest(final String orgIdSlug) {
34+
Objects.requireNonNull(orgIdSlug);
35+
this.orgIdSlug = orgIdSlug;
36+
}
37+
38+
@Override
39+
public String getPath() {
40+
return "/v2/organizations/" + orgIdSlug;
41+
}
42+
43+
@Override
44+
public ResponseParser<Organization> getResponseParser() {
45+
return new GetOrganizationResponseParser();
46+
}
47+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright 2023 SourceLab.org https://github.com/SourceLabOrg/Buildkite-Api-Client
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7+
* persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package org.sourcelab.buildkite.api.client.request;
19+
20+
import org.sourcelab.buildkite.api.client.response.Organization;
21+
import org.sourcelab.buildkite.api.client.response.Pipeline;
22+
import org.sourcelab.buildkite.api.client.response.parser.GetPipelineResponseParser;
23+
import org.sourcelab.buildkite.api.client.response.parser.ResponseParser;
24+
25+
import java.util.Objects;
26+
27+
public class GetPipelineRequest extends GetRequest<Pipeline> {
28+
private final String orgIdSlug;
29+
private final String pipelineIdSlug;
30+
31+
/**
32+
* Constructor.
33+
*
34+
* @param orgIdSlug Organization to retrieve pipeline for.
35+
* @param pipelineIdSlug Pipeline to retrieve.
36+
*/
37+
public GetPipelineRequest(final String orgIdSlug, final String pipelineIdSlug) {
38+
this.pipelineIdSlug = Objects.requireNonNull(pipelineIdSlug);
39+
this.orgIdSlug = Objects.requireNonNull(orgIdSlug);;
40+
}
41+
42+
@Override
43+
public String getPath() {
44+
return "/v2/organizations/" + orgIdSlug + "/pipelines/" + pipelineIdSlug;
45+
}
46+
47+
@Override
48+
public ResponseParser<Pipeline> getResponseParser() {
49+
return new GetPipelineResponseParser();
50+
}
51+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Copyright 2023 SourceLab.org https://github.com/SourceLabOrg/Buildkite-Api-Client
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7+
* persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package org.sourcelab.buildkite.api.client.request;
19+
20+
import org.sourcelab.buildkite.api.client.response.ListOrganizationsResponse;
21+
import org.sourcelab.buildkite.api.client.response.ListPipelinesResponse;
22+
import org.sourcelab.buildkite.api.client.response.parser.ListOrganizationsResponseParser;
23+
import org.sourcelab.buildkite.api.client.response.parser.ListPipelinesResponseParser;
24+
import org.sourcelab.buildkite.api.client.response.parser.ResponseParser;
25+
26+
import java.util.Objects;
27+
28+
public class ListPipelinesRequest extends GetRequest<ListPipelinesResponse> implements PageableRequest<ListPipelinesResponse> {
29+
private final PipelineFilters filters;
30+
private PageOptions pageOptions;
31+
32+
/**
33+
* Constructor.
34+
* @param filters Search Criteria.
35+
*/
36+
public ListPipelinesRequest(final PipelineFilters filters) {
37+
Objects.requireNonNull(filters);
38+
this.filters = filters;
39+
this.pageOptions = filters.getPageOptions() == null ? PageOptions.getDefault() : filters.getPageOptions();
40+
}
41+
42+
@Override
43+
public String getPath() {
44+
// TODO need to urlencode these?
45+
if (filters.hasPipelineIdSlug()) {
46+
return "/v2/organizations/" + filters.getOrgIdSlug() + "/pipelines/" + filters.getPipelineIdSlug();
47+
}
48+
return "/v2/organizations/" + filters.getOrgIdSlug() + "/pipelines";
49+
}
50+
51+
@Override
52+
public RequestParameters getRequestParameters() {
53+
final RequestParametersBuilder builder = RequestParameters.newBuilder();
54+
55+
// Paging options
56+
builder.withParameter("per_page", pageOptions.getPerPage());
57+
builder.withParameter("page", pageOptions.getPage());
58+
59+
return builder.build();
60+
}
61+
62+
@Override
63+
public ResponseParser<ListPipelinesResponse> getResponseParser() {
64+
return new ListPipelinesResponseParser(this);
65+
}
66+
67+
@Override
68+
public void updatePageOptions(final PageOptions pageOptions) {
69+
this.pageOptions = Objects.requireNonNull(pageOptions);
70+
}
71+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Copyright 2023 SourceLab.org https://github.com/SourceLabOrg/Buildkite-Api-Client
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7+
* persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package org.sourcelab.buildkite.api.client.request;
19+
20+
/**
21+
* Optional Properties to filter Organizations.
22+
*/
23+
public class PipelineFilters implements Filters {
24+
private final PageOptions pageOptions;
25+
private final String orgIdSlug;
26+
private final String pipelineIdSlug;
27+
28+
/**
29+
* Builder for {@link PipelineFilters}.
30+
* @return Builder for {@link PipelineFilters}.
31+
*/
32+
public static PipelineFiltersBuilder newBuilder() {
33+
return new PipelineFiltersBuilder();
34+
}
35+
36+
/**
37+
* Constructor.
38+
* Use {@link BuildFiltersBuilder} to create instances.
39+
*/
40+
public PipelineFilters(
41+
final PageOptions pageOptions,
42+
final String orgIdSlug,
43+
final String pipelineIdSlug
44+
) {
45+
this.pageOptions = pageOptions == null ? PageOptions.getDefault() : pageOptions;
46+
this.orgIdSlug = orgIdSlug;
47+
this.pipelineIdSlug = pipelineIdSlug;
48+
}
49+
50+
public String getOrgIdSlug() {
51+
return orgIdSlug;
52+
}
53+
54+
public boolean hasOrgIdSlug() {
55+
return orgIdSlug != null;
56+
}
57+
58+
public String getPipelineIdSlug() {
59+
return pipelineIdSlug;
60+
}
61+
62+
public boolean hasPipelineIdSlug() {
63+
return pipelineIdSlug != null;
64+
}
65+
66+
public PageOptions getPageOptions() {
67+
return pageOptions;
68+
}
69+
70+
@Override
71+
public String toString() {
72+
return "PipelineFilters{"
73+
+ "pageOptions=" + pageOptions
74+
+ ", orgIdSlug='" + orgIdSlug + '\''
75+
+ ", pipelineIdSlug='" + pipelineIdSlug + '\''
76+
+ '}';
77+
}
78+
}

0 commit comments

Comments
 (0)