Search in sources :

Example 1 with IssueServiceNotConfiguredException

use of net.nemerosa.ontrack.extension.issues.model.IssueServiceNotConfiguredException 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)1 Issue (net.nemerosa.ontrack.extension.issues.model.Issue)1 IssueServiceConfigurationRepresentation (net.nemerosa.ontrack.extension.issues.model.IssueServiceConfigurationRepresentation)1 IssueServiceNotConfiguredException (net.nemerosa.ontrack.extension.issues.model.IssueServiceNotConfiguredException)1 Transaction (net.nemerosa.ontrack.tx.Transaction)1