use of net.nemerosa.ontrack.tx.Transaction in project ontrack by nemerosa.
the class SVNChangeLogServiceImpl method getChangeLogFiles.
@Override
@Transactional
public SVNChangeLogFiles getChangeLogFiles(SVNChangeLog changeLog) {
// Revisions must have been loaded first
if (changeLog.getRevisions() == null) {
changeLog.withRevisions(getChangeLogRevisions(changeLog));
}
// In a transaction
try (Transaction ignored = transactionService.start()) {
// Index of files, indexed by path
Map<String, SVNChangeLogFile> files = new TreeMap<>();
// For each revision
// Takes into account only the unmerged revisions
changeLog.getRevisions().getList().stream().filter(changeLogRevision -> changeLogRevision.getLevel() == 0).forEach(changeLogRevision -> {
long revision = changeLogRevision.getRevision();
collectFilesForRevision(changeLog.getRepository(), files, revision);
});
// List of files
return new SVNChangeLogFiles(new ArrayList<>(files.values()));
}
}
use of net.nemerosa.ontrack.tx.Transaction in project ontrack by nemerosa.
the class SVNChangeLogServiceImpl method changeLog.
@Override
@Transactional
public SVNChangeLog 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 branches, for each build
Branch branchFrom = buildFrom.getBranch();
Branch branchTo = buildTo.getBranch();
// Checks the branch is the same
if (branchFrom.id() != branchTo.id()) {
throw new SVNChangeLogDifferentBranchException();
}
SVNRepository svnRepository = getSVNRepository(branchFrom);
return new SVNChangeLog(UUID.randomUUID().toString(), branchFrom.getProject(), svnRepository, getSCMBuildView(svnRepository, buildFrom.getId()), getSCMBuildView(svnRepository, buildTo.getId()));
}
}
use of net.nemerosa.ontrack.tx.Transaction in project ontrack by nemerosa.
the class BuildSVNInformationExtension method getInformation.
@Override
public Optional<EntityInformation> getInformation(ProjectEntity entity) {
if (entity instanceof Build) {
Build build = (Build) entity;
// Gets the branch SVN information
Property<SVNBranchConfigurationProperty> branchConfigurationProperty = propertyService.getProperty(build.getBranch(), SVNBranchConfigurationPropertyType.class);
Property<SVNProjectConfigurationProperty> projectConfigurationProperty = propertyService.getProperty(build.getBranch().getProject(), SVNProjectConfigurationPropertyType.class);
if (branchConfigurationProperty.isEmpty() || projectConfigurationProperty.isEmpty()) {
return Optional.empty();
} else {
// Loads the repository
SVNRepository repository = svnService.getRepository(projectConfigurationProperty.getValue().getConfiguration().getName());
// Gets the build history
try (Transaction ignored = transactionService.start()) {
return Optional.of(new EntityInformation(this, svnChangeLogService.getBuildSVNHistory(repository, build)));
}
}
} else {
return Optional.empty();
}
}
use of net.nemerosa.ontrack.tx.Transaction in project ontrack by nemerosa.
the class GitServiceImpl method getChangeLogIssues.
@Override
public GitChangeLogIssues getChangeLogIssues(GitChangeLog changeLog) {
// Commits must have been loaded first
if (changeLog.getCommits() == null) {
changeLog.withCommits(getChangeLogCommits(changeLog));
}
// In a transaction
try (Transaction ignored = transactionService.start()) {
// Configuration
GitConfiguration configuration = getRequiredProjectConfiguration(changeLog.getProject());
// Issue service
ConfiguredIssueService configuredIssueService = configuration.getConfiguredIssueService().orElse(null);
if (configuredIssueService == null) {
throw new IssueServiceNotConfiguredException();
}
// Index of issues, sorted by keys
Map<String, GitChangeLogIssue> issues = new TreeMap<>();
// For all commits in this commit log
for (GitUICommit gitUICommit : changeLog.getCommits().getLog().getCommits()) {
Set<String> keys = configuredIssueService.extractIssueKeysFromMessage(gitUICommit.getCommit().getFullMessage());
for (String key : keys) {
GitChangeLogIssue existingIssue = issues.get(key);
if (existingIssue != null) {
existingIssue.add(gitUICommit);
} else {
Issue issue = configuredIssueService.getIssue(key);
if (issue != null) {
existingIssue = GitChangeLogIssue.of(issue, gitUICommit);
issues.put(key, existingIssue);
}
}
}
}
// List of issues
List<GitChangeLogIssue> issuesList = new ArrayList<>(issues.values());
// Issues link
IssueServiceConfigurationRepresentation issueServiceConfiguration = configuredIssueService.getIssueServiceConfigurationRepresentation();
// OK
return new GitChangeLogIssues(issueServiceConfiguration, issuesList);
}
}
use of net.nemerosa.ontrack.tx.Transaction 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