Skip to content

Commit cc83bf0

Browse files
jsorefoleg-nenashev
authored andcommitted
Introduce new Run#getBuildsOverThreshold() method for getting runs above the desired execution result (#4259)
* IntelliJ/Java: Duplicate code Refactored as Run.getBuildsOverThreshold * CheckForNull Co-Authored-By: Oleg Nenashev <o.v.nenashev@gmail.com> * getBuildsOverThreshold: get RunT using _this()
1 parent 987ca98 commit cc83bf0

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

core/src/main/java/hudson/model/Job.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -994,19 +994,8 @@ public RunT getLastCompletedBuild() {
994994
* if not enough builds satisfying the threshold have been found. Never null.
995995
*/
996996
public List<RunT> getLastBuildsOverThreshold(int numberOfBuilds, Result threshold) {
997-
998-
List<RunT> result = new ArrayList<>(numberOfBuilds);
999-
1000997
RunT r = getLastBuild();
1001-
while (r != null && result.size() < numberOfBuilds) {
1002-
if (!r.isBuilding() &&
1003-
(r.getResult() != null && r.getResult().isBetterOrEqualTo(threshold))) {
1004-
result.add(r);
1005-
}
1006-
r = r.getPreviousBuild();
1007-
}
1008-
1009-
return result;
998+
return r.getBuildsOverThreshold(numberOfBuilds, threshold);
1010999
}
10111000

10121001
/**

core/src/main/java/hudson/model/Run.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -953,17 +953,32 @@ protected void dropLinks() {
953953
* @since 1.383
954954
*/
955955
public @Nonnull List<RunT> getPreviousBuildsOverThreshold(int numberOfBuilds, @Nonnull Result threshold) {
956-
List<RunT> builds = new ArrayList<>(numberOfBuilds);
957-
958956
RunT r = getPreviousBuild();
957+
return r.getBuildsOverThreshold(numberOfBuilds, threshold);
958+
}
959+
960+
/**
961+
* Returns the last {@code numberOfBuilds} builds with a build result ≥ {@code threshold}.
962+
*
963+
* @param numberOfBuilds the desired number of builds
964+
* @param threshold the build result threshold
965+
* @return a list with the builds (youngest build first).
966+
* May be smaller than 'numberOfBuilds' or even empty
967+
* if not enough builds satisfying the threshold have been found. Never null.
968+
* @since TODO
969+
*/
970+
protected @Nonnull List<RunT> getBuildsOverThreshold(int numberOfBuilds, @Nonnull Result threshold) {
971+
List<RunT> builds = new ArrayList<>(numberOfBuilds);
972+
973+
RunT r = _this();
959974
while (r != null && builds.size() < numberOfBuilds) {
960-
if (!r.isBuilding() &&
975+
if (!r.isBuilding() &&
961976
(r.getResult() != null && r.getResult().isBetterOrEqualTo(threshold))) {
962977
builds.add(r);
963978
}
964979
r = r.getPreviousBuild();
965980
}
966-
981+
967982
return builds;
968983
}
969984

0 commit comments

Comments
 (0)