Search in sources :

Example 1 with TRevision

use of net.nemerosa.ontrack.extension.svn.db.TRevision in project ontrack by nemerosa.

the class SVNInfoServiceImpl method getIssueInfo.

@Override
public OntrackSVNIssueInfo getIssueInfo(String configurationName, String issueKey) {
    // Repository
    SVNRepository repository = svnService.getRepository(configurationName);
    // Issue service
    ConfiguredIssueService configuredIssueService = repository.getConfiguredIssueService();
    if (configuredIssueService == null) {
        // No issue service configured
        return OntrackSVNIssueInfo.empty(repository.getConfiguration());
    }
    // Gets the details about the issue
    Issue issue = configuredIssueService.getIssue(issueKey);
    // For each configured branch
    Map<String, BranchRevision> branchRevisions = new HashMap<>();
    svnService.forEachConfiguredBranch(config -> Objects.equals(configurationName, config.getConfiguration().getName()), (branch, branchConfig) -> {
        String branchPath = branchConfig.getCuredBranchPath();
        // List of linked issues
        Collection<String> linkedIssues = configuredIssueService.getLinkedIssues(branch.getProject(), issue).stream().map(Issue::getKey).collect(Collectors.toList());
        // Gets the last raw revision on this branch
        issueRevisionDao.findLastRevisionByIssuesAndBranch(repository.getId(), linkedIssues, branchPath).ifPresent(revision -> branchRevisions.put(branchPath, new BranchRevision(branchPath, revision, false)));
    });
    // Until all revisions are complete in respect of their merges...
    while (!BranchRevision.areComplete(branchRevisions.values())) {
        // Gets the incomplete revisions
        Collection<BranchRevision> incompleteRevisions = branchRevisions.values().stream().filter(br -> !br.isComplete()).collect(Collectors.toList());
        // For each of them, gets the list of revisions it was merged to
        incompleteRevisions.forEach(br -> {
            List<Long> merges = revisionDao.getMergesForRevision(repository.getId(), br.getRevision());
            // Marks the current revision as complete
            branchRevisions.put(br.getPath(), br.complete());
            // Gets the revision info for each merged revision
            List<TRevision> revisions = merges.stream().map(r -> revisionDao.get(repository.getId(), r)).collect(Collectors.toList());
            // For each revision path, compares with current stored revision
            revisions.forEach(t -> {
                String branch = t.getBranch();
                // Existing branch revision?
                BranchRevision existingBranchRevision = branchRevisions.get(branch);
                if (existingBranchRevision == null || t.getRevision() > existingBranchRevision.getRevision()) {
                    branchRevisions.put(branch, new BranchRevision(branch, t.getRevision(), true));
                }
            });
        });
    }
    // We now have the last revision for this issue on each branch...
    List<OntrackSVNIssueRevisionInfo> issueRevisionInfos = new ArrayList<>();
    branchRevisions.values().forEach(br -> {
        // Loads the revision info
        SVNRevisionInfo basicInfo = svnService.getRevisionInfo(repository, br.getRevision());
        SVNChangeLogRevision changeLogRevision = svnService.createChangeLogRevision(repository, basicInfo);
        // Info to collect
        OntrackSVNIssueRevisionInfo issueRevisionInfo = OntrackSVNIssueRevisionInfo.of(changeLogRevision);
        // Gets the branch from the branch path
        AtomicReference<Branch> rBranch = new AtomicReference<>();
        svnService.forEachConfiguredBranch(config -> Objects.equals(configurationName, config.getConfiguration().getName()), (candidate, branchConfig) -> {
            String branchPath = branchConfig.getCuredBranchPath();
            if (Objects.equals(br.getPath(), branchPath)) {
                rBranch.set(candidate);
            }
        });
        Branch branch = rBranch.get();
        if (branch != null) {
            // Collects branch info
            SCMIssueCommitBranchInfo branchInfo = SCMIssueCommitBranchInfo.of(branch);
            // Gets the first copy event on this path after this revision
            SVNLocation firstCopy = svnService.getFirstCopyAfter(repository, basicInfo.toLocation());
            // Identifies a possible build given the path/revision and the first copy
            Optional<Build> buildAfterCommit = lookupBuild(basicInfo.toLocation(), firstCopy, branch);
            branchInfo = scmService.getBranchInfo(buildAfterCommit, branchInfo);
            // OK
            issueRevisionInfo.add(branchInfo);
        }
        // OK
        issueRevisionInfos.add(issueRevisionInfo);
    });
    // Gets the list of revisions & their basic info (order from latest to oldest)
    List<SVNChangeLogRevision> revisions = svnService.getRevisionsForIssueKey(repository, issueKey).stream().map(revision -> svnService.createChangeLogRevision(repository, svnService.getRevisionInfo(repository, revision))).collect(Collectors.toList());
    // OK
    return new OntrackSVNIssueInfo(repository.getConfiguration(), repository.getConfiguredIssueService().getIssueServiceConfigurationRepresentation(), issue, issueRevisionInfos, revisions);
}
Also used : java.util(java.util) SCMUtilsService(net.nemerosa.ontrack.extension.scm.service.SCMUtilsService) SVNBranchConfigurationProperty(net.nemerosa.ontrack.extension.svn.property.SVNBranchConfigurationProperty) SVNProjectConfigurationPropertyType(net.nemerosa.ontrack.extension.svn.property.SVNProjectConfigurationPropertyType) SVNProjectConfigurationProperty(net.nemerosa.ontrack.extension.svn.property.SVNProjectConfigurationProperty) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfiguredBuildSvnRevisionLink(net.nemerosa.ontrack.extension.svn.support.ConfiguredBuildSvnRevisionLink) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors(java.util.stream.Collectors) Issue(net.nemerosa.ontrack.extension.issues.model.Issue) ConfiguredIssueService(net.nemerosa.ontrack.extension.issues.model.ConfiguredIssueService) TRevision(net.nemerosa.ontrack.extension.svn.db.TRevision) SCMIssueCommitBranchInfo(net.nemerosa.ontrack.extension.scm.model.SCMIssueCommitBranchInfo) SVNRepository(net.nemerosa.ontrack.extension.svn.db.SVNRepository) Service(org.springframework.stereotype.Service) net.nemerosa.ontrack.model.structure(net.nemerosa.ontrack.model.structure) SVNIssueRevisionDao(net.nemerosa.ontrack.extension.svn.db.SVNIssueRevisionDao) SVNRevisionDao(net.nemerosa.ontrack.extension.svn.db.SVNRevisionDao) net.nemerosa.ontrack.extension.svn.model(net.nemerosa.ontrack.extension.svn.model) SVNBranchConfigurationPropertyType(net.nemerosa.ontrack.extension.svn.property.SVNBranchConfigurationPropertyType) Issue(net.nemerosa.ontrack.extension.issues.model.Issue) TRevision(net.nemerosa.ontrack.extension.svn.db.TRevision) SVNRepository(net.nemerosa.ontrack.extension.svn.db.SVNRepository) ConfiguredIssueService(net.nemerosa.ontrack.extension.issues.model.ConfiguredIssueService) AtomicReference(java.util.concurrent.atomic.AtomicReference) SCMIssueCommitBranchInfo(net.nemerosa.ontrack.extension.scm.model.SCMIssueCommitBranchInfo)

Aggregations

java.util (java.util)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Collectors (java.util.stream.Collectors)1 ConfiguredIssueService (net.nemerosa.ontrack.extension.issues.model.ConfiguredIssueService)1 Issue (net.nemerosa.ontrack.extension.issues.model.Issue)1 SCMIssueCommitBranchInfo (net.nemerosa.ontrack.extension.scm.model.SCMIssueCommitBranchInfo)1 SCMUtilsService (net.nemerosa.ontrack.extension.scm.service.SCMUtilsService)1 SVNIssueRevisionDao (net.nemerosa.ontrack.extension.svn.db.SVNIssueRevisionDao)1 SVNRepository (net.nemerosa.ontrack.extension.svn.db.SVNRepository)1 SVNRevisionDao (net.nemerosa.ontrack.extension.svn.db.SVNRevisionDao)1 TRevision (net.nemerosa.ontrack.extension.svn.db.TRevision)1 net.nemerosa.ontrack.extension.svn.model (net.nemerosa.ontrack.extension.svn.model)1 SVNBranchConfigurationProperty (net.nemerosa.ontrack.extension.svn.property.SVNBranchConfigurationProperty)1 SVNBranchConfigurationPropertyType (net.nemerosa.ontrack.extension.svn.property.SVNBranchConfigurationPropertyType)1 SVNProjectConfigurationProperty (net.nemerosa.ontrack.extension.svn.property.SVNProjectConfigurationProperty)1 SVNProjectConfigurationPropertyType (net.nemerosa.ontrack.extension.svn.property.SVNProjectConfigurationPropertyType)1 ConfiguredBuildSvnRevisionLink (net.nemerosa.ontrack.extension.svn.support.ConfiguredBuildSvnRevisionLink)1 net.nemerosa.ontrack.model.structure (net.nemerosa.ontrack.model.structure)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1