use of net.nemerosa.ontrack.model.exceptions.BuildNotFoundException in project ontrack by nemerosa.
the class GitChangeLogBranchGraphQLFieldContributor method gitChangeLogFetcher.
private DataFetcher gitChangeLogFetcher() {
return fetcher(Branch.class, (DataFetchingEnvironment environment, Branch branch) -> {
String from = GraphqlUtils.getStringArgument(environment, "from").orElseThrow(() -> new IllegalStateException("From argument is required."));
String to = GraphqlUtils.getStringArgument(environment, "to").orElseThrow(() -> new IllegalStateException("To argument is required."));
Build fromBuild = structureService.findBuildByName(branch.getProject().getName(), branch.getName(), from).orElseThrow(() -> new BuildNotFoundException(branch.getProject().getName(), branch.getName(), from));
Build toBuild = structureService.findBuildByName(branch.getProject().getName(), branch.getName(), to).orElseThrow(() -> new BuildNotFoundException(branch.getProject().getName(), branch.getName(), to));
return gitService.changeLog(new BuildDiffRequest(fromBuild.getId(), toBuild.getId()));
});
}
use of net.nemerosa.ontrack.model.exceptions.BuildNotFoundException in project ontrack by nemerosa.
the class CoreBuildFilterJdbcRepository method between.
@Override
public List<Build> between(Branch branch, String from, String to) {
StringBuilder sql = new StringBuilder("SELECT ID FROM BUILDS WHERE " + "BRANCHID = :branchId ");
MapSqlParameterSource params = params("branchId", branch.id());
Integer fromId;
Integer toId = null;
// From build
fromId = structureRepository.getBuildByName(branch.getProject().getName(), branch.getName(), from).orElseThrow(() -> new BuildNotFoundException(branch.getProject().getName(), branch.getName(), from)).id();
// To build
if (StringUtils.isNotBlank(to)) {
toId = structureRepository.getBuildByName(branch.getProject().getName(), branch.getName(), to).orElseThrow(() -> new BuildNotFoundException(branch.getProject().getName(), branch.getName(), to)).id();
}
if (toId != null) {
if (toId < fromId) {
int i = toId;
toId = fromId;
fromId = i;
}
}
sql.append(" AND ID >= :fromId");
params.addValue("fromId", fromId);
if (toId != null) {
sql.append(" AND ID <= :toId");
params.addValue("toId", toId);
}
// Ordering
sql.append(" ORDER BY ID DESC");
// Query
return loadBuilds(sql.toString(), params);
}
Aggregations