Skip to content

Commit 3a89527

Browse files
committed
cleanup
1 parent d82cdab commit 3a89527

File tree

2 files changed

+1
-54
lines changed

2 files changed

+1
-54
lines changed

src/main/java/org/sourcelab/buildkite/api/client/util/BuildkiteClientUtils.java

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,41 +44,6 @@
4444
*/
4545
public class BuildkiteClientUtils {
4646

47-
/**
48-
* Helper method to retrieve the N **newest** builds given the supplied search criteria.
49-
* The results will be ordered from NEWEST to OLDEST.
50-
*
51-
* @param numberOfBuilds How many builds to retrieve, (artificially) limited to max of 100.
52-
* @param filters Search criteria.
53-
* @param client The BuildkiteClient to execute the requests against.
54-
* @return List of Builds sorted from NEWEST to OLDEST.
55-
*/
56-
public static List<Build> retrieveNewestBuilds(final int numberOfBuilds, final BuildFilters filters, final BuildkiteClient client) {
57-
// Create request
58-
final ListBuildsRequest request = new ListBuildsRequest(filters);
59-
request.updatePageOptions(new PageOptions(1, 1));
60-
61-
// Retrieve first entry only, to determine how many total entries there are.
62-
final ListBuildsResponse lookupResponse = client.executeRequest(request);
63-
final long totalNumberOfEntries = lookupResponse.getPagingLinks().getTotalNumberOfEntries();
64-
65-
/**
66-
* Assumption is that we can only pull at max, the last 100 entries as that is the maximum that
67-
* the API can return in a single request.
68-
* This method could be updated pretty easily to support larger numbers, submit a PR :)
69-
*/
70-
final long pageNumber = totalNumberOfEntries / numberOfBuilds;
71-
request.updatePageOptions(new PageOptions(pageNumber, numberOfBuilds));
72-
73-
// Execute the request for the correct page of results.
74-
final ListBuildsResponse response = client.executeRequest(request);
75-
76-
// But the results are still sorted in oldest to newest, we want newest to oldest, so reverse the order
77-
// before returning.
78-
final List<Build> reversed = new ArrayList<>(response.getBuilds());
79-
return reversed;
80-
}
81-
8247
/**
8348
* Helper method to retrieve all entries given a filter criteria.
8449
* The results will be ordered from NEWEST to OLDEST.
@@ -133,7 +98,7 @@ public static <REQUEST, OBJECT> List<OBJECT> retrieveAll(
13398
hasMore = lookupResponse.getPagingLinks().hasNextUrl();
13499
}
135100

136-
// But the results are still sorted in oldest to newest, we want newest to oldest, so reverse the order
101+
// But the results are still sorted in newest to oldest, presumably, we want oldest to newest, so reverse the order
137102
// before returning.
138103
final List<OBJECT> reversed = new ArrayList<>(entries);
139104
return reversed;

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -180,24 +180,6 @@ void listBuilds() {
180180
assertNotNull(resultPage2, "Page 2 result should be not null.");
181181
}
182182

183-
/**
184-
* Sanity test BuildkiteClientUtils.retrieveNewestBuilds().
185-
*/
186-
@Test
187-
void retrieveNewestBuilds() {
188-
final BuildFilters filters = BuildFilters.newBuilder()
189-
.withPageOptions(1, 1)
190-
//.withStateChooser().passed()
191-
.withCreator(userId)
192-
.withPipeline(orgIdSlug, pipelineIdSlug)
193-
.build();
194-
195-
// Get the latest 10 results.
196-
final List<Build> builds = BuildkiteClientUtils.retrieveNewestBuilds(10, filters, client);
197-
logger.info("Found: {}", builds);
198-
builds.forEach((build) -> logger.info("Build {} {} ", build.getNumber(), build.getCreatedAt()));
199-
}
200-
201183
/**
202184
* Sanity test BuildkiteClientUtils.retrieveAll().
203185
*/

0 commit comments

Comments
 (0)