use of net.nemerosa.ontrack.extension.api.model.BuildDiffRequestDifferenceProjectException in project ontrack by nemerosa.
the class GitServiceImpl method changeLog.
@Override
@Transactional
public GitChangeLog changeLog(BuildDiffRequest request) {
try (Transaction ignored = transactionService.start()) {
// Gets the two builds
Build buildFrom = structureService.getBuild(request.getFrom());
Build buildTo = structureService.getBuild(request.getTo());
// Ordering of builds
if (buildFrom.id() > buildTo.id()) {
Build t = buildFrom;
buildFrom = buildTo;
buildTo = t;
}
// Gets the two associated projects
Project project = buildFrom.getBranch().getProject();
Project otherProject = buildTo.getBranch().getProject();
// Checks the project
if (project.id() != otherProject.id()) {
throw new BuildDiffRequestDifferenceProjectException();
}
// Project Git configuration
Optional<GitConfiguration> oProjectConfiguration = getProjectConfiguration(project);
if (oProjectConfiguration.isPresent()) {
// Forces Git sync before
boolean syncError;
GitConfiguration gitConfiguration = oProjectConfiguration.get();
try {
syncAndWait(gitConfiguration);
syncError = false;
} catch (GitRepositorySyncException ex) {
applicationLogService.log(ApplicationLogEntry.error(ex, NameDescription.nd("git-sync", "Git synchronisation issue"), gitConfiguration.getRemote()).withDetail("project", project.getName()).withDetail("git-name", gitConfiguration.getName()).withDetail("git-remote", gitConfiguration.getRemote()));
syncError = true;
}
// Change log computation
return new GitChangeLog(UUID.randomUUID().toString(), project, getSCMBuildView(buildFrom.getId()), getSCMBuildView(buildTo.getId()), syncError);
} else {
throw new GitProjectNotConfiguredException(project.getId());
}
}
}
Aggregations