Search in sources :

Example 1 with IssueServiceConfigurationRepresentation

use of net.nemerosa.ontrack.extension.issues.model.IssueServiceConfigurationRepresentation in project ontrack by nemerosa.

the class SVNChangeLogServiceImpl method getChangeLogIssues.

@Override
@Transactional
public SVNChangeLogIssues getChangeLogIssues(SVNChangeLog changeLog) {
    // Revisions must have been loaded first
    if (changeLog.getRevisions() == null) {
        changeLog.withRevisions(getChangeLogRevisions(changeLog));
    }
    // In a transaction
    try (Transaction ignored = transactionService.start()) {
        // Repository
        SVNRepository repository = changeLog.getRepository();
        // Index of issues, sorted by keys
        Map<String, SVNChangeLogIssue> issues = new TreeMap<>();
        // For all revisions in this revision log
        for (SVNChangeLogRevision changeLogRevision : changeLog.getRevisions().getList()) {
            long revision = changeLogRevision.getRevision();
            collectIssuesForRevision(repository, issues, revision);
        }
        // List of issues
        List<SVNChangeLogIssue> issuesList = new ArrayList<>(issues.values());
        // Validations
        validateIssues(issuesList, changeLog);
        // Issues link
        IssueServiceConfigurationRepresentation issueServiceConfiguration = null;
        String allIssuesLink = "";
        ConfiguredIssueService configuredIssueService = repository.getConfiguredIssueService();
        if (configuredIssueService != null) {
            issueServiceConfiguration = configuredIssueService.getIssueServiceConfigurationRepresentation();
            allIssuesLink = configuredIssueService.getLinkForAllIssues(issuesList.stream().map(SVNChangeLogIssue::getIssue).collect(Collectors.toList()));
        }
        // OK
        return new SVNChangeLogIssues(allIssuesLink, issueServiceConfiguration, issuesList);
    }
}
Also used : IssueServiceConfigurationRepresentation(net.nemerosa.ontrack.extension.issues.model.IssueServiceConfigurationRepresentation) ConfiguredIssueService(net.nemerosa.ontrack.extension.issues.model.ConfiguredIssueService) Transaction(net.nemerosa.ontrack.tx.Transaction) SVNRepository(net.nemerosa.ontrack.extension.svn.db.SVNRepository) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with IssueServiceConfigurationRepresentation

use of net.nemerosa.ontrack.extension.issues.model.IssueServiceConfigurationRepresentation 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);
    }
}
Also used : IssueServiceConfigurationRepresentation(net.nemerosa.ontrack.extension.issues.model.IssueServiceConfigurationRepresentation) ConfiguredIssueService(net.nemerosa.ontrack.extension.issues.model.ConfiguredIssueService) Issue(net.nemerosa.ontrack.extension.issues.model.Issue) IssueServiceNotConfiguredException(net.nemerosa.ontrack.extension.issues.model.IssueServiceNotConfiguredException) Transaction(net.nemerosa.ontrack.tx.Transaction)

Aggregations

ConfiguredIssueService (net.nemerosa.ontrack.extension.issues.model.ConfiguredIssueService)2 IssueServiceConfigurationRepresentation (net.nemerosa.ontrack.extension.issues.model.IssueServiceConfigurationRepresentation)2 Transaction (net.nemerosa.ontrack.tx.Transaction)2 Issue (net.nemerosa.ontrack.extension.issues.model.Issue)1 IssueServiceNotConfiguredException (net.nemerosa.ontrack.extension.issues.model.IssueServiceNotConfiguredException)1 SVNRepository (net.nemerosa.ontrack.extension.svn.db.SVNRepository)1 Transactional (org.springframework.transaction.annotation.Transactional)1