Skip to content

Commit 8828137

Browse files
committed
Add additional fields and additional utility
1 parent 7c9ad3e commit 8828137

File tree

10 files changed

+450
-70
lines changed

10 files changed

+450
-70
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 java.util.Collection;
21+
import java.util.HashSet;
22+
import java.util.Set;
23+
24+
/**
25+
* Options for Retrying multiple Jobs.
26+
*/
27+
public class RetryMultipleJobsOptions {
28+
private final String organizationSlug;
29+
private final String pipelineSlug;
30+
private final long buildNumber;
31+
private final Set<String> jobIds;
32+
33+
/**
34+
* Builder instance for {@link RetryMultipleJobsOptions}.
35+
* @return Builder instance for {@link RetryMultipleJobsOptions}.
36+
*/
37+
public static RetryMultipleJobsOptionsBuilder newBuilder() {
38+
return new RetryMultipleJobsOptionsBuilder();
39+
}
40+
41+
/**
42+
* Constructor.
43+
*/
44+
public RetryMultipleJobsOptions(final String organizationSlug, final String pipelineIdSlug, final long buildNumber, final Collection<String> jobIds) {
45+
this.organizationSlug = organizationSlug;
46+
this.pipelineSlug = pipelineIdSlug;
47+
this.buildNumber = buildNumber;
48+
this.jobIds = new HashSet<>(jobIds);
49+
}
50+
51+
public String getOrganizationSlug() {
52+
return organizationSlug;
53+
}
54+
55+
public String getPipelineSlug() {
56+
return pipelineSlug;
57+
}
58+
59+
public long getBuildNumber() {
60+
return buildNumber;
61+
}
62+
63+
public Set<String> getJobIds() {
64+
return jobIds;
65+
}
66+
67+
@Override
68+
public String toString() {
69+
return "RetryMultipleJobsOptions{"
70+
+ "\n\torganizationSlug='" + organizationSlug + '\''
71+
+ "\n\tpipelineSlug='" + pipelineSlug + '\''
72+
+ "\n\tbuildNumber=" + buildNumber
73+
+ "\n\tjobIds=" + jobIds
74+
+ "\n}";
75+
}
76+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
import java.util.Collection;
23+
import java.util.HashSet;
24+
import java.util.Set;
25+
26+
public final class RetryMultipleJobsOptionsBuilder {
27+
private String organizationSlug = null;
28+
private String pipelineSlug = null;
29+
private Long buildNumber = null;
30+
private Set<String> jobIds = new HashSet<>(;
31+
32+
public RetryMultipleJobsOptionsBuilder() {
33+
}
34+
35+
public RetryMultipleJobsOptionsBuilder withOrganizationSlug(final String organizationSlug) {
36+
this.organizationSlug = organizationSlug;
37+
return this;
38+
}
39+
40+
public RetryMultipleJobsOptionsBuilder withPipelineSlug(final String pipelineSlug) {
41+
this.pipelineSlug = pipelineSlug;
42+
return this;
43+
}
44+
45+
public RetryMultipleJobsOptionsBuilder withBuildNumber(long buildNumber) {
46+
this.buildNumber = buildNumber;
47+
return this;
48+
}
49+
50+
public RetryMultipleJobsOptionsBuilder withJobId(final String jobId) {
51+
this.jobIds.add(jobId);
52+
return this;
53+
}
54+
55+
public RetryMultipleJobsOptionsBuilder withJobIds(final Collection<String> jobIds) {
56+
this.jobIds.addAll(jobIds);
57+
return this;
58+
}
59+
60+
/**
61+
* Create new {@link RetryMultipleJobsOptions} instance.
62+
* @return Create new {@link RetryMultipleJobsOptions} instance.
63+
*/
64+
public RetryMultipleJobsOptions build() {
65+
// Validation
66+
if (organizationSlug == null) {
67+
throw new BuilderValidationException("Organization must be provided.");
68+
}
69+
if (pipelineSlug == null) {
70+
throw new BuilderValidationException("Pipeline must be provided.");
71+
}
72+
if (buildNumber == null) {
73+
throw new BuilderValidationException("BuildNumber must be provided.");
74+
}
75+
if (jobIds.isEmpty()) {
76+
throw new BuilderValidationException("At least one JobId must be provided.");
77+
}
78+
return new RetryMultipleJobsOptions(organizationSlug, pipelineSlug, buildNumber, jobIds);
79+
}
80+
}

src/main/java/org/sourcelab/buildkite/api/client/response/Build.java

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class Build {
4747
private final Pipeline pipeline;
4848
private final List<Job> jobs;
4949
private final RebuiltFrom rebuiltFrom;
50+
private final PullRequest pullRequest;
5051

5152
/**
5253
* Constructor.
@@ -72,7 +73,8 @@ public Build(
7273
@JsonProperty("creator") final Creator creator,
7374
@JsonProperty("pipeline") final Pipeline pipeline,
7475
@JsonProperty("jobs") final List<Job> jobs,
75-
@JsonProperty("rebuilt_from") final RebuiltFrom rebuiltFrom
76+
@JsonProperty("rebuilt_from") final RebuiltFrom rebuiltFrom,
77+
@JsonProperty("pull_request") final PullRequest pullRequest
7678
) {
7779
this.id = id;
7880
this.graphqlId = graphqlId;
@@ -94,6 +96,7 @@ public Build(
9496
this.pipeline = pipeline;
9597
this.jobs = jobs;
9698
this.rebuiltFrom = rebuiltFrom;
99+
this.pullRequest = pullRequest;
97100
}
98101

99102
public String getId() {
@@ -176,30 +179,35 @@ public RebuiltFrom getRebuiltFrom() {
176179
return rebuiltFrom;
177180
}
178181

182+
public PullRequest getPullRequest() {
183+
return pullRequest;
184+
}
185+
179186
@Override
180187
public String toString() {
181188
return "Build{"
182-
+ "id='" + id + '\''
183-
+ ", graphqlId='" + graphqlId + '\''
184-
+ ", url='" + url + '\''
185-
+ ", webUrl='" + webUrl + '\''
186-
+ ", number=" + number
187-
+ ", state='" + state + '\''
188-
+ ", blocked=" + blocked
189-
+ ", message='" + message + '\''
190-
+ ", commit='" + commit + '\''
191-
+ ", branch='" + branch + '\''
192-
+ ", source='" + source + '\''
193-
+ ", createdAt=" + createdAt
194-
+ ", scheduledAt=" + scheduledAt
195-
+ ", startedAt=" + startedAt
196-
+ ", finishedAt=" + finishedAt
197-
+ ", author=" + author
198-
+ ", creator=" + creator
199-
+ ", pipeline=" + pipeline
200-
+ ", jobs=" + jobs
201-
+ ", rebuiltFrom=" + rebuiltFrom
202-
+ '}';
189+
+ "\n\tid='" + id + '\''
190+
+ "\n\tgraphqlId='" + graphqlId + '\''
191+
+ "\n\turl='" + url + '\''
192+
+ "\n\twebUrl='" + webUrl + '\''
193+
+ "\n\tnumber=" + number
194+
+ "\n\tstate='" + state + '\''
195+
+ "\n\tblocked=" + blocked
196+
+ "\n\tmessage='" + message + '\''
197+
+ "\n\tcommit='" + commit + '\''
198+
+ "\n\tbranch='" + branch + '\''
199+
+ "\n\tsource='" + source + '\''
200+
+ "\n\tcreatedAt=" + createdAt
201+
+ "\n\tscheduledAt=" + scheduledAt
202+
+ "\n\tstartedAt=" + startedAt
203+
+ "\n\tfinishedAt=" + finishedAt
204+
+ "\n\tauthor=" + author
205+
+ "\n\tcreator=" + creator
206+
+ "\n\tpipeline=" + pipeline
207+
+ "\n\tjobs=" + jobs
208+
+ "\n\trebuiltFrom=" + rebuiltFrom
209+
+ "\n\tpullRequest=" + pullRequest
210+
+ "\n}";
203211
}
204212

205213
// TODO

src/main/java/org/sourcelab/buildkite/api/client/response/Job.java

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public class Job {
5151
private final long retriesCount;
5252
private final String retryType;
5353

54+
// Parallel Builds
55+
private final Integer parallelGroupIndex;
56+
private final Integer parallelGroupTotal;
57+
5458
// TODO
5559
// "agent_query_rules": ["*"],
5660

@@ -81,7 +85,9 @@ public Job(
8185
@JsonProperty("retried") final Boolean retried,
8286
@JsonProperty("retriedInJobId") final String retriedInJobId,
8387
@JsonProperty("retriesCount") final Long retriesCount,
84-
@JsonProperty("retryType") final String retryType
88+
@JsonProperty("retryType") final String retryType,
89+
@JsonProperty("parallel_group_index") final Integer parallelGroupIndex,
90+
@JsonProperty("parallel_group_total") final Integer parallelGroupTotal
8591
) {
8692
this.id = id;
8793
this.graphqlId = graphqlId;
@@ -106,6 +112,8 @@ public Job(
106112
this.retriedInJobId = retriedInJobId;
107113
this.retriesCount = retriesCount == null ? 0 : retriesCount;
108114
this.retryType = retryType;
115+
this.parallelGroupIndex = parallelGroupIndex;
116+
this.parallelGroupTotal = parallelGroupTotal;
109117
}
110118

111119
public String getId() {
@@ -200,32 +208,42 @@ public String getRetryType() {
200208
return retryType;
201209
}
202210

211+
public Integer getParallelGroupIndex() {
212+
return parallelGroupIndex;
213+
}
214+
215+
public Integer getParallelGroupTotal() {
216+
return parallelGroupTotal;
217+
}
218+
203219
@Override
204220
public String toString() {
205221
return "Job{"
206-
+ "id='" + id + '\''
207-
+ ", graphqlId='" + graphqlId + '\''
208-
+ ", type='" + type + '\''
209-
+ ", name='" + name + '\''
210-
+ ", stepKey='" + stepKey + '\''
211-
+ ", state='" + state + '\''
212-
+ ", webUrl='" + webUrl + '\''
213-
+ ", logUrl='" + logUrl + '\''
214-
+ ", rawLogUrl='" + rawLogUrl + '\''
215-
+ ", command='" + command + '\''
216-
+ ", softFailed=" + softFailed
217-
+ ", exitStatus=" + exitStatus
218-
+ ", artifactPaths='" + artifactPaths + '\''
219-
+ ", agent=" + agent
220-
+ ", createdAt=" + createdAt
221-
+ ", scheduledAt=" + scheduledAt
222-
+ ", runnableAt=" + runnableAt
223-
+ ", startedAt=" + startedAt
224-
+ ", finishedAt=" + finishedAt
225-
+ ", retried=" + retried
226-
+ ", retriedInJobId='" + retriedInJobId + '\''
227-
+ ", retriesCount=" + retriesCount
228-
+ ", retryType='" + retryType + '\''
229-
+ '}';
222+
+ "\n\tid='" + id + '\''
223+
+ "\n\tgraphqlId='" + graphqlId + '\''
224+
+ "\n\ttype='" + type + '\''
225+
+ "\n\tname='" + name + '\''
226+
+ "\n\tstepKey='" + stepKey + '\''
227+
+ "\n\tstate='" + state + '\''
228+
+ "\n\twebUrl='" + webUrl + '\''
229+
+ "\n\tlogUrl='" + logUrl + '\''
230+
+ "\n\trawLogUrl='" + rawLogUrl + '\''
231+
+ "\n\tcommand='" + command + '\''
232+
+ "\n\tsoftFailed=" + softFailed
233+
+ "\n\texitStatus=" + exitStatus
234+
+ "\n\tartifactPaths='" + artifactPaths + '\''
235+
+ "\n\tagent=" + agent
236+
+ "\n\tcreatedAt=" + createdAt
237+
+ "\n\tscheduledAt=" + scheduledAt
238+
+ "\n\trunnableAt=" + runnableAt
239+
+ "\n\tstartedAt=" + startedAt
240+
+ "\n\tfinishedAt=" + finishedAt
241+
+ "\n\tretried=" + retried
242+
+ "\n\tretriedInJobId='" + retriedInJobId + '\''
243+
+ "\n\tretriesCount=" + retriesCount
244+
+ "\n\tretryType='" + retryType + '\''
245+
+ "\n\tparallelGroupIndex=" + parallelGroupIndex
246+
+ "\n\tparallelGroupTotal=" + parallelGroupTotal
247+
+ "\n}";
230248
}
231249
}

0 commit comments

Comments
 (0)