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);
}
}
Aggregations