Skip to content

Commit 5f0e121

Browse files
committed
Add state chooser
1 parent 0c10654 commit 5f0e121

File tree

3 files changed

+136
-0
lines changed

3 files changed

+136
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,20 @@ public BuildFiltersBuilder withMetaData(final Map<String, String> metaData) {
205205
return this;
206206
}
207207

208+
/**
209+
* Utility helper to fluently select states from known valid states.
210+
* @return Utility helper to fluently select states from known valid states.
211+
*/
212+
public StateChooser withStateChooser() {
213+
return new StateChooser(this);
214+
}
215+
208216
/**
209217
* Filters the results by the given build state.
210218
* The finished state is a shortcut to automatically search for builds with passed, failed, blocked, canceled states.
211219
*
220+
* See also {@link this#withStateChooser()}.
221+
*
212222
* Valid states: running, scheduled, passed, failing, failed, blocked, canceled, canceling, skipped, not_run, finished
213223
* @param state Filters the results by the given build state.
214224
* @return BuildFiltersBuilder for method chaining.
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
public class StateChooser {
21+
private final BuildFiltersBuilder builder;
22+
23+
public StateChooser(final BuildFiltersBuilder builder) {
24+
this.builder = builder;
25+
}
26+
27+
public BuildFiltersBuilder blocked() {
28+
return builder.withState("blocked");
29+
}
30+
31+
public StateChooser blockedAnd() {
32+
blocked();
33+
return this;
34+
}
35+
36+
public BuildFiltersBuilder canceled() {
37+
return builder.withState("canceled");
38+
}
39+
40+
public StateChooser canceledAnd() {
41+
canceled();
42+
return this;
43+
}
44+
45+
public BuildFiltersBuilder canceling() {
46+
return builder.withState("canceling");
47+
}
48+
49+
public StateChooser cancelingAnd() {
50+
canceling();
51+
return this;
52+
}
53+
54+
public BuildFiltersBuilder failed() {
55+
return builder.withState("failed");
56+
}
57+
58+
public StateChooser failedAnd() {
59+
builder.withState("failed");
60+
return this;
61+
}
62+
63+
public BuildFiltersBuilder failing() {
64+
return builder.withState("failing");
65+
}
66+
67+
public StateChooser failingAnd() {
68+
failing();
69+
return this;
70+
}
71+
72+
public BuildFiltersBuilder finished() {
73+
return builder.withState("finished");
74+
}
75+
76+
public StateChooser finishedAnd() {
77+
finished();
78+
return this;
79+
}
80+
81+
public BuildFiltersBuilder notRun() {
82+
return builder.withState("not_run");
83+
}
84+
85+
public StateChooser notRunAnd() {
86+
notRun();
87+
return this;
88+
}
89+
90+
public BuildFiltersBuilder passed() {
91+
return builder.withState("passed");
92+
}
93+
94+
public StateChooser passedAnd() {
95+
passed();
96+
return this;
97+
}
98+
99+
public BuildFiltersBuilder running() {
100+
return builder.withState("running");
101+
}
102+
103+
public StateChooser runningAnd() {
104+
running();
105+
return this;
106+
}
107+
108+
public BuildFiltersBuilder scheduled() {
109+
return builder.withState("scheduled");
110+
}
111+
112+
public StateChooser scheduledAnd() {
113+
scheduled();
114+
return this;
115+
}
116+
117+
public BuildFiltersBuilder skipped() {
118+
return builder.withState("skipped");
119+
}
120+
121+
public StateChooser skippedAnd() {
122+
skipped();
123+
return this;
124+
}
125+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ void getMeta() {
149149
void listBuilds() {
150150
final BuildFilters filters = BuildFilters.newBuilder()
151151
.withPageOptions(1, 2)
152+
.withStateChooser().failed()
152153
.build();
153154
final ListBuildsResponse result = client.listBuilds(filters);
154155
logger.info("Result: {}", result);

0 commit comments

Comments
 (0)