Skip to content

Commit f0b204b

Browse files
committed
add missing fields
1 parent aa19c96 commit f0b204b

File tree

6 files changed

+162
-23
lines changed

6 files changed

+162
-23
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class Build {
4646
private final Creator creator;
4747
private final Pipeline pipeline;
4848
private final List<Job> jobs;
49+
private final RebuiltFrom rebuiltFrom;
4950

5051
/**
5152
* Constructor.
@@ -70,7 +71,8 @@ public Build(
7071
@JsonProperty("author") final Author author,
7172
@JsonProperty("creator") final Creator creator,
7273
@JsonProperty("pipeline") final Pipeline pipeline,
73-
@JsonProperty("jobs") final List<Job> jobs
74+
@JsonProperty("jobs") final List<Job> jobs,
75+
@JsonProperty("rebuilt_from") final RebuiltFrom rebuiltFrom
7476
) {
7577
this.id = id;
7678
this.graphqlId = graphqlId;
@@ -91,6 +93,7 @@ public Build(
9193
this.creator = creator;
9294
this.pipeline = pipeline;
9395
this.jobs = jobs;
96+
this.rebuiltFrom = rebuiltFrom;
9497
}
9598

9699
public String getId() {
@@ -169,6 +172,10 @@ public List<Job> getJobs() {
169172
return jobs;
170173
}
171174

175+
public RebuiltFrom getRebuiltFrom() {
176+
return rebuiltFrom;
177+
}
178+
172179
@Override
173180
public String toString() {
174181
return "Build{"
@@ -191,6 +198,7 @@ public String toString() {
191198
+ ", creator=" + creator
192199
+ ", pipeline=" + pipeline
193200
+ ", jobs=" + jobs
201+
+ ", rebuiltFrom=" + rebuiltFrom
194202
+ '}';
195203
}
196204

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

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
import com.fasterxml.jackson.annotation.JsonProperty;
2121

2222
import java.time.ZonedDateTime;
23+
import java.util.ArrayList;
24+
import java.util.Collections;
25+
import java.util.List;
2326

2427
public class Pipeline {
2528
// TODO Fields
@@ -51,31 +54,33 @@ public class Pipeline {
5154
private final long waitingJobsCount;
5255

5356
private final Provider provider;
57+
private final List<Step> steps;
5458

5559
/**
5660
* Constructor.
5761
*/
5862
public Pipeline(
59-
@JsonProperty("id") final String id,
60-
@JsonProperty("graphql_id") final String graphqlId,
61-
@JsonProperty("url") final String url,
62-
@JsonProperty("name") final String name,
63-
@JsonProperty("description") final String description,
64-
@JsonProperty("slug") final String slug,
65-
@JsonProperty("repository") final String repository,
66-
@JsonProperty("cluster_id") final String clusterId,
67-
@JsonProperty("skip_queued_branch_builds") final Boolean skipQueuedBranchBuilds,
68-
@JsonProperty("cancel_running_branch_builds") final Boolean cancelRunningBranchBuilds,
69-
@JsonProperty("allow_rebuilds") final Boolean allowRebuilds,
70-
@JsonProperty("builds_url") final String buildsUrl,
71-
@JsonProperty("badge_url") final String badgeUrl,
72-
@JsonProperty("created_at") final ZonedDateTime createdAt,
73-
@JsonProperty("scheduled_builds_count") final Long scheduledBuildsCount,
74-
@JsonProperty("running_builds_count") final Long runningBuildsCount,
75-
@JsonProperty("scheduled_jobs_count") final Long scheduledJobsCount,
76-
@JsonProperty("running_jobs_count") final Long runningJobsCount,
77-
@JsonProperty("waiting_jobs_count") final Long waitingJobsCount,
78-
@JsonProperty("provider") final Provider provider
63+
@JsonProperty("id") final String id,
64+
@JsonProperty("graphql_id") final String graphqlId,
65+
@JsonProperty("url") final String url,
66+
@JsonProperty("name") final String name,
67+
@JsonProperty("description") final String description,
68+
@JsonProperty("slug") final String slug,
69+
@JsonProperty("repository") final String repository,
70+
@JsonProperty("cluster_id") final String clusterId,
71+
@JsonProperty("skip_queued_branch_builds") final Boolean skipQueuedBranchBuilds,
72+
@JsonProperty("cancel_running_branch_builds") final Boolean cancelRunningBranchBuilds,
73+
@JsonProperty("allow_rebuilds") final Boolean allowRebuilds,
74+
@JsonProperty("builds_url") final String buildsUrl,
75+
@JsonProperty("badge_url") final String badgeUrl,
76+
@JsonProperty("created_at") final ZonedDateTime createdAt,
77+
@JsonProperty("scheduled_builds_count") final Long scheduledBuildsCount,
78+
@JsonProperty("running_builds_count") final Long runningBuildsCount,
79+
@JsonProperty("scheduled_jobs_count") final Long scheduledJobsCount,
80+
@JsonProperty("running_jobs_count") final Long runningJobsCount,
81+
@JsonProperty("waiting_jobs_count") final Long waitingJobsCount,
82+
@JsonProperty("provider") final Provider provider,
83+
@JsonProperty("steps") final List<Step> steps
7984
) {
8085
this.id = id;
8186
this.graphqlId = graphqlId;
@@ -97,6 +102,12 @@ public Pipeline(
97102
this.runningJobsCount = runningJobsCount == null ? 0 : runningJobsCount;
98103
this.waitingJobsCount = waitingJobsCount == null ? 0 : waitingJobsCount;
99104
this.provider = provider;
105+
106+
final List<Step> stepList = new ArrayList<>();
107+
if (steps != null) {
108+
stepList.addAll(steps);
109+
}
110+
this.steps = Collections.unmodifiableList(stepList);
100111
}
101112

102113
public String getId() {
@@ -179,6 +190,10 @@ public boolean isAllowRebuilds() {
179190
return allowRebuilds;
180191
}
181192

193+
public List<Step> getSteps() {
194+
return steps;
195+
}
196+
182197
@Override
183198
public String toString() {
184199
return "Pipeline{"
@@ -202,6 +217,7 @@ public String toString() {
202217
+ ", runningJobsCount=" + runningJobsCount
203218
+ ", waitingJobsCount=" + waitingJobsCount
204219
+ ", provider=" + provider
220+
+ ", steps=" + steps
205221
+ '}';
206222
}
207223
}

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@
2020
import com.fasterxml.jackson.annotation.JsonCreator;
2121
import com.fasterxml.jackson.annotation.JsonProperty;
2222

23+
import java.util.Collections;
24+
import java.util.HashMap;
25+
import java.util.Map;
26+
2327
public class Provider {
2428
private final String id;
2529
private final String webhookUrl;
30+
private final Map<String, String> settings;
2631

2732
/**
2833
* Constructor.
@@ -32,10 +37,17 @@ public class Provider {
3237
@JsonCreator
3338
public Provider(
3439
@JsonProperty("id") final String id,
35-
@JsonProperty("webhook_url") final String webhookUrl
40+
@JsonProperty("webhook_url") final String webhookUrl,
41+
@JsonProperty("settings") final Map<String, String> settings
3642
) {
3743
this.id = id;
3844
this.webhookUrl = webhookUrl;
45+
46+
final Map<String, String> settingsMap = new HashMap<>();
47+
if (settings != null) {
48+
settingsMap.putAll(settings);
49+
}
50+
this.settings = Collections.unmodifiableMap(settingsMap);
3951
}
4052

4153
public String getId() {
@@ -46,11 +58,16 @@ public String getWebhookUrl() {
4658
return webhookUrl;
4759
}
4860

61+
public Map<String, String> getSettings() {
62+
return settings;
63+
}
64+
4965
@Override
5066
public String toString() {
5167
return "Provider{"
5268
+ "id='" + id + '\''
5369
+ ", webhookUrl='" + webhookUrl + '\''
70+
+ ", settings=" + settings
5471
+ '}';
5572
}
5673
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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.response;
19+
20+
import com.fasterxml.jackson.annotation.JsonCreator;
21+
import com.fasterxml.jackson.annotation.JsonProperty;
22+
23+
public class RebuiltFrom {
24+
private final String id;
25+
private final long number;
26+
private final String url;
27+
28+
/**
29+
* Constructor.
30+
*/
31+
@JsonCreator
32+
public RebuiltFrom(
33+
@JsonProperty("id") final String id,
34+
@JsonProperty("number") final long number,
35+
@JsonProperty("url") final String url
36+
) {
37+
this.id = id;
38+
this.number = number;
39+
this.url = url;
40+
}
41+
42+
public String getId() {
43+
return id;
44+
}
45+
46+
public long getNumber() {
47+
return number;
48+
}
49+
50+
public String getUrl() {
51+
return url;
52+
}
53+
54+
@Override
55+
public String toString() {
56+
return "RebuiltFrom{"
57+
+ "id='" + id + '\''
58+
+ ", number=" + number
59+
+ ", url='" + url + '\''
60+
+ '}';
61+
}
62+
}

src/test/java/org/sourcelab/buildkite/api/client/BuildkiteClientTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ void listBuilds() {
337337
assertEquals("Run Tests", build.getPipeline().getName());
338338
assertNotNull(build.getPipeline().getProvider());
339339
assertEquals("github", build.getPipeline().getProvider().getId());
340+
assertNotNull(build.getRebuiltFrom());
341+
assertEquals("build-id", build.getRebuiltFrom().getId());
342+
assertEquals(46, build.getRebuiltFrom().getNumber());
343+
assertEquals("https://api.buildkite.com/v2/organizations/orgSlug/pipelines/pipelineSlug/builds/46", build.getRebuiltFrom().getUrl());
340344

341345
build = response.getBuilds().get(1);
342346
assertEquals("01858542", build.getId());
@@ -355,6 +359,7 @@ void listBuilds() {
355359
assertEquals("Run Tests", build.getPipeline().getName());
356360
assertNotNull(build.getPipeline().getProvider());
357361
assertEquals("github", build.getPipeline().getProvider().getId());
362+
assertNull(build.getRebuiltFrom());
358363
}
359364

360365
/**
@@ -580,8 +585,35 @@ void listPipelines() {
580585
pipeline = response.getPipelines().get(1);
581586
assertEquals("pipeline-id-2", pipeline.getId());
582587
assertEquals("pipeline-name-2", pipeline.getName());
588+
589+
// Spot check provider
583590
assertNotNull(pipeline.getProvider());
584591
assertEquals("github", pipeline.getProvider().getId());
592+
assertEquals("https://webhook.buildkite.com/deliver/webook-hash2", pipeline.getProvider().getWebhookUrl());
593+
assertNotNull(pipeline.getProvider().getSettings());
594+
assertEquals(20, pipeline.getProvider().getSettings().size());
595+
assertEquals("true", pipeline.getProvider().getSettings().get("build_pull_requests"));
596+
assertEquals("code", pipeline.getProvider().getSettings().get("trigger_mode"));
597+
598+
// Spot Check Steps
599+
assertNotNull(pipeline.getSteps());
600+
assertEquals(4, pipeline.getSteps().size());
601+
assertEquals("script", pipeline.getSteps().get(0).getType());
602+
assertEquals("Compile & Verify", pipeline.getSteps().get(0).getName());
603+
assertEquals("mvn clean compile", pipeline.getSteps().get(0).getCommand());
604+
605+
assertEquals("script", pipeline.getSteps().get(1).getType());
606+
assertEquals("Run tests", pipeline.getSteps().get(1).getName());
607+
assertEquals("mvn test", pipeline.getSteps().get(1).getCommand());
608+
609+
assertEquals("waiter", pipeline.getSteps().get(2).getType());
610+
assertEquals(null, pipeline.getSteps().get(2).getName());
611+
assertEquals(null, pipeline.getSteps().get(2).getCommand());
612+
613+
assertEquals("script", pipeline.getSteps().get(3).getType());
614+
assertEquals("Annotate", pipeline.getSteps().get(3).getName());
615+
assertEquals(null, pipeline.getSteps().get(3).getCommand());
616+
assertFalse(pipeline.getSteps().get(3).getEnv().isEmpty());
585617
}
586618

587619
/**

src/test/resources/mockResponses/listBuilds.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232
"finished_at": null,
3333
"meta_data": {},
3434
"pull_request": null,
35-
"rebuilt_from": null,
35+
"rebuilt_from": {
36+
"id": "build-id",
37+
"number": 46,
38+
"url": "https://api.buildkite.com/v2/organizations/orgSlug/pipelines/pipelineSlug/builds/46"
39+
},
3640
"pipeline": {
3741
"id": "pipeline-id",
3842
"graphql_id": "pipeline-graphql-id",

0 commit comments

Comments
 (0)