|
44 | 44 | */ |
45 | 45 | public class BuildkiteClientUtils { |
46 | 46 |
|
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 | | - |
82 | 47 | /** |
83 | 48 | * Helper method to retrieve all entries given a filter criteria. |
84 | 49 | * The results will be ordered from NEWEST to OLDEST. |
@@ -133,7 +98,7 @@ public static <REQUEST, OBJECT> List<OBJECT> retrieveAll( |
133 | 98 | hasMore = lookupResponse.getPagingLinks().hasNextUrl(); |
134 | 99 | } |
135 | 100 |
|
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 |
137 | 102 | // before returning. |
138 | 103 | final List<OBJECT> reversed = new ArrayList<>(entries); |
139 | 104 | return reversed; |
|
0 commit comments