Search in sources :

Example 6 with Issue

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

the class GitLabIssueServiceExtensionTest method get_issue_from_display_key.

@Test
public void get_issue_from_display_key() {
    Issue issue = get_issue_test("#16", 16);
    assertNotNull(issue);
    assertEquals(issueWrapper, issue);
}
Also used : GitlabIssue(org.gitlab.api.models.GitlabIssue) Issue(net.nemerosa.ontrack.extension.issues.model.Issue) Test(org.junit.Test)

Example 7 with Issue

use of net.nemerosa.ontrack.extension.issues.model.Issue 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)

Example 8 with Issue

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

the class GitServiceImpl method getIssueInfo.

@Override
public OntrackGitIssueInfo getIssueInfo(ID branchId, String key) {
    Branch branch = structureService.getBranch(branchId);
    // Configuration
    GitBranchConfiguration branchConfiguration = getRequiredBranchConfiguration(branch);
    GitConfiguration configuration = branchConfiguration.getConfiguration();
    // Issue service
    ConfiguredIssueService configuredIssueService = configuration.getConfiguredIssueService().orElse(null);
    if (configuredIssueService == null) {
        throw new GitBranchIssueServiceNotConfiguredException(branchId);
    }
    // Gets the details about the issue
    Issue issue = configuredIssueService.getIssue(key);
    // Collects commits per branches
    List<OntrackGitIssueCommitInfo> commitInfos = collectIssueCommitInfos(branch.getProject(), issue);
    // OK
    return new OntrackGitIssueInfo(configuredIssueService.getIssueServiceConfigurationRepresentation(), issue, commitInfos);
}
Also used : ConfiguredIssueService(net.nemerosa.ontrack.extension.issues.model.ConfiguredIssueService) Issue(net.nemerosa.ontrack.extension.issues.model.Issue)

Example 9 with Issue

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

the class GitLabIssueServiceExtensionTest method get_issue_from_key.

@Test
public void get_issue_from_key() {
    Issue issue = get_issue_test("16", 16);
    assertNotNull(issue);
    assertEquals(issueWrapper, issue);
}
Also used : GitlabIssue(org.gitlab.api.models.GitlabIssue) Issue(net.nemerosa.ontrack.extension.issues.model.Issue) Test(org.junit.Test)

Example 10 with Issue

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

the class GitController method changeLog.

/**
 * Change log export
 */
@RequestMapping(value = "changelog/export", method = RequestMethod.GET)
public ResponseEntity<String> changeLog(IssueChangeLogExportRequest request) {
    // Gets the change log
    GitChangeLog changeLog = gitService.changeLog(request);
    // Gets the associated project
    Project project = changeLog.getProject();
    // Gets the configuration for the project
    GitConfiguration gitConfiguration = gitService.getProjectConfiguration(project).orElseThrow(() -> new GitProjectNotConfiguredException(project.getId()));
    // Gets the issue service
    Optional<ConfiguredIssueService> optConfiguredIssueService = gitConfiguration.getConfiguredIssueService();
    if (!optConfiguredIssueService.isPresent()) {
        return new ResponseEntity<>("The branch is not configured for issues", HttpStatus.NO_CONTENT);
    }
    ConfiguredIssueService configuredIssueService = optConfiguredIssueService.get();
    // Gets the issue change log
    GitChangeLogIssues changeLogIssues = gitService.getChangeLogIssues(changeLog);
    // List of issues
    List<Issue> issues = changeLogIssues.getList().stream().map(SCMChangeLogIssue::getIssue).collect(Collectors.toList());
    // Exports the change log using the given format
    ExportedIssues exportedChangeLogIssues = configuredIssueService.getIssueServiceExtension().exportIssues(configuredIssueService.getIssueServiceConfiguration(), issues, request);
    // Content type
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.set("Content-Type", exportedChangeLogIssues.getFormat() + "; charset=utf-8");
    // Body and headers
    return new ResponseEntity<>(exportedChangeLogIssues.getContent(), responseHeaders, HttpStatus.OK);
}
Also used : ExportedIssues(net.nemerosa.ontrack.extension.issues.export.ExportedIssues) Project(net.nemerosa.ontrack.model.structure.Project) HttpHeaders(org.springframework.http.HttpHeaders) ConfiguredIssueService(net.nemerosa.ontrack.extension.issues.model.ConfiguredIssueService) ResponseEntity(org.springframework.http.ResponseEntity) Issue(net.nemerosa.ontrack.extension.issues.model.Issue) SCMChangeLogIssue(net.nemerosa.ontrack.extension.scm.model.SCMChangeLogIssue)

Aggregations

Issue (net.nemerosa.ontrack.extension.issues.model.Issue)10 ConfiguredIssueService (net.nemerosa.ontrack.extension.issues.model.ConfiguredIssueService)5 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 ExportedIssues (net.nemerosa.ontrack.extension.issues.export.ExportedIssues)2 SCMChangeLogIssue (net.nemerosa.ontrack.extension.scm.model.SCMChangeLogIssue)2 Project (net.nemerosa.ontrack.model.structure.Project)2 Transaction (net.nemerosa.ontrack.tx.Transaction)2 GitlabIssue (org.gitlab.api.models.GitlabIssue)2 Test (org.junit.Test)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 Sets (com.google.common.collect.Sets)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 String.format (java.lang.String.format)1 URLEncoder (java.net.URLEncoder)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Matcher (java.util.regex.Matcher)1 IssueExportServiceFactory (net.nemerosa.ontrack.extension.issues.export.IssueExportServiceFactory)1