use of org.jboss.pnc.dto.BuildRef in project pnc by project-ncl.
the class BuildEndpointTest method shouldSortResults.
@Test
public void shouldSortResults() throws Exception {
BuildClient bc = new BuildClient(RestClientConfiguration.asAnonymous());
String sort = "=asc=submitTime";
List<Long> notSorted = bc.getAll(null, null).getAll().stream().map(BuildRef::getSubmitTime).map(Instant::getEpochSecond).collect(Collectors.toList());
List<Long> sorted = bc.getAll(null, null, Optional.of(sort), Optional.empty()).getAll().stream().map(BuildRef::getSubmitTime).map(Instant::getEpochSecond).collect(Collectors.toList());
assertThat(notSorted).isNotEqualTo(sorted);
assertThat(sorted).isSorted();
}
use of org.jboss.pnc.dto.BuildRef in project pnc by project-ncl.
the class BuildConfigurationProviderImpl method populateBuildConfigWithLatestBuild.
private BuildConfigurationWithLatestBuild populateBuildConfigWithLatestBuild(BuildConfiguration buildConfig, List<BuildRecord> latestBuilds, List<BuildTask> runningBuilds) {
Integer bcId = mapper.getIdMapper().toEntity(buildConfig.getId());
Optional<BuildTask> latestBuildTask = runningBuilds.stream().filter(Objects::nonNull).filter(bt -> bt.getBuildConfigurationAudited().getId().equals(bcId)).max(Comparator.comparing(BuildTask::getSubmitTime));
Optional<BuildRecord> latestBuildRecord = latestBuilds.stream().filter(br -> br.getBuildConfigurationId().equals(bcId)).findFirst();
BuildRef latestBuild = latestBuildTask.map((bt -> (BuildRef) buildMapper.fromBuildTask(bt))).orElse(latestBuildRecord.map(buildMapper::toRef).orElse(null));
String latestBuildUsername = latestBuildTask.map(bt -> bt.getUser().getUsername()).orElse(latestBuildRecord.map(br -> br.getUser().getUsername()).orElse(null));
return BuildConfigurationWithLatestBuild.builderWithLatestBuild().buildConfig(buildConfig).latestBuild(latestBuild).latestBuildUsername(latestBuildUsername).build();
}
use of org.jboss.pnc.dto.BuildRef in project bacon by project-ncl.
the class BuildInfoCollector method getBuildsFromGroupBuild.
/**
* Get all the builds done in a build group. If the build finished with 'NO_REBUILD_REQUIRED', get the 'original'
* successful build and return it instead If the build was successful, we don't grab the logs since they can be
* quite long.
*
* @param groupBuild the group build to get the builds
* @return The information on the group build and the builds performed
*/
public GroupBuildInfo getBuildsFromGroupBuild(GroupBuild groupBuild) {
Map<String, PncBuild> result = new HashMap<>();
BuildsFilterParameters filter = new BuildsFilterParameters();
filter.setLatest(false);
filter.setRunning(false);
try {
Collection<Build> builds = groupBuildClient.getBuilds(groupBuild.getId(), filter).getAll();
for (Build build : builds) {
PncBuild pncBuild;
if (build.getStatus() == BuildStatus.NO_REBUILD_REQUIRED) {
BuildRef buildRef = build.getNoRebuildCause();
Build realBuild = buildClient.getSpecific(buildRef.getId());
pncBuild = new PncBuild(realBuild);
} else {
pncBuild = new PncBuild(build);
}
pncBuild.addBuiltArtifacts(toList(buildClient.getBuiltArtifacts(pncBuild.getId())));
result.put(pncBuild.getName(), pncBuild);
}
return new GroupBuildInfo(groupBuild, result);
} catch (RemoteResourceException e) {
throw new RuntimeException("Failed to get group build info for " + groupBuild.getId(), e);
}
}
Aggregations