Search in sources :

Example 1 with GitRepositorySyncException

use of net.nemerosa.ontrack.git.exceptions.GitRepositorySyncException 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());
        }
    }
}
Also used : GitRepositorySyncException(net.nemerosa.ontrack.git.exceptions.GitRepositorySyncException) BuildDiffRequestDifferenceProjectException(net.nemerosa.ontrack.extension.api.model.BuildDiffRequestDifferenceProjectException) Transaction(net.nemerosa.ontrack.tx.Transaction) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

BuildDiffRequestDifferenceProjectException (net.nemerosa.ontrack.extension.api.model.BuildDiffRequestDifferenceProjectException)1 GitRepositorySyncException (net.nemerosa.ontrack.git.exceptions.GitRepositorySyncException)1 Transaction (net.nemerosa.ontrack.tx.Transaction)1 Transactional (org.springframework.transaction.annotation.Transactional)1