Skip to content

Commit aa19c96

Browse files
committed
add more end points
1 parent 3a89527 commit aa19c96

23 files changed

+1635
-115
lines changed

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

Lines changed: 142 additions & 33 deletions
Large diffs are not rendered by default.

src/main/java/org/sourcelab/buildkite/api/client/http/Client.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,23 @@
1919

2020
import org.sourcelab.buildkite.api.client.request.Request;
2121

22+
import java.io.Closeable;
23+
2224
/**
2325
* Abstraction around underlying Http Client library. Allows for replacing the
2426
* underlying library in the future if needed.
2527
*/
26-
public interface Client {
28+
public interface Client extends Closeable {
2729
/**
2830
* Execute the supplied request and return the server's response.
2931
* @param request The request to execute.
30-
* @return The servers response.
32+
* @return The API response.
33+
*/
34+
HttpResult executeRequest(final Request<?> request);
35+
36+
/**
37+
* Close the Client implementation and release any resources it
38+
* may have open.
3139
*/
32-
HttpResult executeRequest(final Request request);
40+
void close();
3341
}

src/main/java/org/sourcelab/buildkite/api/client/http/HttpComponentsClient.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,16 @@ public HttpResult executeRequest(final Request request) {
9898
default:
9999
throw new IllegalArgumentException("Invalid HttpType: " + request.getMethod());
100100
}
101-
} catch (IOException e) {
102-
throw new RuntimeException(e);
101+
} catch (final IOException ioException) {
102+
throw new HttpRequestException(ioException.getMessage(), ioException);
103103
}
104104
}
105105

106+
@Override
107+
public void close() {
108+
// Not required in this implementation.
109+
}
110+
106111
private HttpResult executePostRequest(final Request request, final CloseableHttpClient httpClient) {
107112
try {
108113
final HttpPost httpPost = new HttpPost(generateRequestUri(request));

src/main/java/org/sourcelab/buildkite/api/client/request/ListPipelinesRequest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ public ListPipelinesRequest(final PipelineFilters filters) {
3939

4040
@Override
4141
public String getPath() {
42-
// TODO need to urlencode these?
43-
if (filters.hasPipelineIdSlug()) {
44-
return "/v2/organizations/" + filters.getOrgIdSlug() + "/pipelines/" + filters.getPipelineIdSlug();
45-
}
4642
return "/v2/organizations/" + filters.getOrgIdSlug() + "/pipelines";
4743
}
4844

src/main/java/org/sourcelab/buildkite/api/client/request/PipelineFilters.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
public class PipelineFilters implements Filters {
2424
private final PageOptions pageOptions;
2525
private final String orgIdSlug;
26-
private final String pipelineIdSlug;
2726

2827
/**
2928
* Builder for {@link PipelineFilters}.
@@ -39,12 +38,10 @@ public static PipelineFiltersBuilder newBuilder() {
3938
*/
4039
public PipelineFilters(
4140
final PageOptions pageOptions,
42-
final String orgIdSlug,
43-
final String pipelineIdSlug
41+
final String orgIdSlug
4442
) {
4543
this.pageOptions = pageOptions == null ? PageOptions.getDefault() : pageOptions;
4644
this.orgIdSlug = orgIdSlug;
47-
this.pipelineIdSlug = pipelineIdSlug;
4845
}
4946

5047
public String getOrgIdSlug() {
@@ -55,14 +52,6 @@ public boolean hasOrgIdSlug() {
5552
return orgIdSlug != null;
5653
}
5754

58-
public String getPipelineIdSlug() {
59-
return pipelineIdSlug;
60-
}
61-
62-
public boolean hasPipelineIdSlug() {
63-
return pipelineIdSlug != null;
64-
}
65-
6655
public PageOptions getPageOptions() {
6756
return pageOptions;
6857
}
@@ -72,7 +61,6 @@ public String toString() {
7261
return "PipelineFilters{"
7362
+ "pageOptions=" + pageOptions
7463
+ ", orgIdSlug='" + orgIdSlug + '\''
75-
+ ", pipelineIdSlug='" + pipelineIdSlug + '\''
7664
+ '}';
7765
}
7866
}

src/main/java/org/sourcelab/buildkite/api/client/request/PipelineFiltersBuilder.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
public final class PipelineFiltersBuilder {
2626
private PageOptions pageOptions = null;
2727
private String orgIdSlug = null;
28-
private String pipelineIdSlug;
2928

3029
/**
3130
* Constructor.
@@ -87,38 +86,20 @@ public PipelineFiltersBuilder withOrganization(final String orgIdSlug) {
8786
return this;
8887
}
8988

90-
/**
91-
* Filter by the given Organization and Pipeline.
92-
* @param orgIdSlug Organization to filter by.
93-
* @param pipelineIdSlug Pipeline to filter by.
94-
* @return PipelineFIltersBuilder for method chaining.
95-
*/
96-
public PipelineFiltersBuilder withPipeline(final String orgIdSlug, final String pipelineIdSlug) {
97-
withOrganization(orgIdSlug);
98-
this.pipelineIdSlug = pipelineIdSlug;
99-
return this;
100-
}
101-
10289
/**
10390
* New OrganizationFilters instance using configured properties.
10491
* @return New OrganizationFilters instance using configured properties.
10592
* @throws BuilderValidationException if not valid or complete.
10693
*/
10794
public PipelineFilters build() {
10895
// Validation
109-
if (pipelineIdSlug != null) {
110-
if (orgIdSlug == null) {
111-
throw new BuilderValidationException("If Pipeline is provided, then Organization must be provided.");
112-
}
113-
}
11496
if (orgIdSlug == null) {
11597
throw new BuilderValidationException("Organization must be provided.");
11698
}
11799

118100
return new PipelineFilters(
119101
pageOptions,
120-
orgIdSlug,
121-
pipelineIdSlug
102+
orgIdSlug
122103
);
123104
}
124105
}

src/main/java/org/sourcelab/buildkite/api/client/request/RequestParameters.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ public RequestParameter getParameterByName(final String name) {
100100
return parameters.get(name);
101101
}
102102

103+
/**
104+
* Total number of request parameters contained.
105+
* @return Total number of request parameters contained.
106+
*/
107+
public int size() {
108+
return getParameters().size();
109+
}
110+
103111
@Override
104112
public String toString() {
105113
return "RequestParameters{"
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
* Options for Retrying a Job.
22+
*/
23+
public class RetryJobOptions {
24+
private final String organizationSlug;
25+
private final String pipelineSlug;
26+
private final long buildNumber;
27+
private final String jobId;
28+
29+
/**
30+
* Builder instance for {@link RetryJobOptions}.
31+
* @return Builder instance for {@link RetryJobOptions}.
32+
*/
33+
public static RetryJobOptionsBuilder newBuilder() {
34+
return new RetryJobOptionsBuilder();
35+
}
36+
37+
/**
38+
* Constructor.
39+
*/
40+
public RetryJobOptions(final String organizationSlug, final String pipelineIdSlug, final long buildNumber, final String jobId) {
41+
this.organizationSlug = organizationSlug;
42+
this.pipelineSlug = pipelineIdSlug;
43+
this.buildNumber = buildNumber;
44+
this.jobId = jobId;
45+
}
46+
47+
public String getOrganizationSlug() {
48+
return organizationSlug;
49+
}
50+
51+
public String getPipelineSlug() {
52+
return pipelineSlug;
53+
}
54+
55+
public long getBuildNumber() {
56+
return buildNumber;
57+
}
58+
59+
public String getJobId() {
60+
return jobId;
61+
}
62+
63+
@Override
64+
public String toString() {
65+
return "RetryJobOptions{"
66+
+ "orgIdSlug='" + organizationSlug + '\''
67+
+ ", pipelineIdSlug='" + pipelineSlug + '\''
68+
+ ", buildNumber=" + buildNumber
69+
+ ", jobId='" + jobId + '\''
70+
+ '}';
71+
}
72+
}
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.exception.BuilderValidationException;
21+
22+
public final class RetryJobOptionsBuilder {
23+
private String organizationSlug = null;
24+
private String pipelineSlug = null;
25+
private Long buildNumber = null;
26+
private String jobId = null;
27+
28+
public RetryJobOptionsBuilder() {
29+
}
30+
31+
public RetryJobOptionsBuilder withOrganizationSlug(final String organizationSlug) {
32+
this.organizationSlug = organizationSlug;
33+
return this;
34+
}
35+
36+
public RetryJobOptionsBuilder withPipelineSlug(final String pipelineSlug) {
37+
this.pipelineSlug = pipelineSlug;
38+
return this;
39+
}
40+
41+
public RetryJobOptionsBuilder withBuildNumber(long buildNumber) {
42+
this.buildNumber = buildNumber;
43+
return this;
44+
}
45+
46+
public RetryJobOptionsBuilder withJobId(final String jobId) {
47+
this.jobId = jobId;
48+
return this;
49+
}
50+
51+
/**
52+
* Create new {@link RetryJobOptions} instance.
53+
* @return Create new {@link RetryJobOptions} instance.
54+
*/
55+
public RetryJobOptions build() {
56+
// Validation
57+
if (organizationSlug == null) {
58+
throw new BuilderValidationException("Organization must be provided.");
59+
}
60+
if (pipelineSlug == null) {
61+
throw new BuilderValidationException("Pipeline must be provided.");
62+
}
63+
if (buildNumber == null) {
64+
throw new BuilderValidationException("BuildNumber must be provided.");
65+
}
66+
if (jobId == null) {
67+
throw new BuilderValidationException("JobId must be provided.");
68+
}
69+
return new RetryJobOptions(organizationSlug, pipelineSlug, buildNumber, jobId);
70+
}
71+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.Job;
21+
import org.sourcelab.buildkite.api.client.response.parser.GetJobResponseParser;
22+
import org.sourcelab.buildkite.api.client.response.parser.ResponseParser;
23+
24+
import java.util.Objects;
25+
26+
public class RetryJobRequest extends PutRequest<Job> {
27+
private final RetryJobOptions options;
28+
29+
/**
30+
* Constructor.
31+
*/
32+
public RetryJobRequest(final RetryJobOptions options) {
33+
this.options = Objects.requireNonNull(options);
34+
}
35+
36+
@Override
37+
public String getPath() {
38+
return "/v2/organizations/" + options.getOrganizationSlug()
39+
+ "/pipelines/" + options.getPipelineSlug()
40+
+ "/builds/" + options.getBuildNumber()
41+
+ "/jobs/" + options.getJobId() + "/retry";
42+
43+
}
44+
45+
@Override
46+
public ResponseParser<Job> getResponseParser() {
47+
return new GetJobResponseParser();
48+
}
49+
}

0 commit comments

Comments
 (0)