Search in sources :

Example 1 with InternalRepositoryException

use of sonia.scm.repository.InternalRepositoryException in project scm-review-plugin by scm-manager.

the class MergeService method createDefaultSquashCommitMessage.

private String createDefaultSquashCommitMessage(NamespaceAndName namespaceAndName, PullRequest pullRequest) {
    try (RepositoryService repositoryService = serviceFactory.create(namespaceAndName)) {
        if (RepositoryPermissions.read(repositoryService.getRepository()).isPermitted() && repositoryService.isSupported(Command.LOG)) {
            try {
                StringBuilder builder = new StringBuilder();
                Set<Person> contributors = new HashSet<>();
                getChangesetsFromLogCommand(pullRequest, repositoryService).forEach(c -> {
                    contributors.add(c.getAuthor());
                    builder.append("- ").append(c.getDescription()).append("\n\n");
                });
                appendSquashContributors(builder, pullRequest, contributors);
                return MessageFormat.format(SQUASH_COMMIT_MESSAGE_TEMPLATE, pullRequest.getSource(), pullRequest.getTarget(), builder.toString());
            } catch (IOException e) {
                throw new InternalRepositoryException(entity("Branch", pullRequest.getSource()).in(repositoryService.getRepository()), "Could not read changesets from repository");
            }
        } else {
            return createDefaultMergeCommitMessage(pullRequest);
        }
    }
}
Also used : IOException(java.io.IOException) Person(sonia.scm.repository.Person) RepositoryService(sonia.scm.repository.api.RepositoryService) HashSet(java.util.HashSet) InternalRepositoryException(sonia.scm.repository.InternalRepositoryException)

Example 2 with InternalRepositoryException

use of sonia.scm.repository.InternalRepositoryException in project scm-review-plugin by scm-manager.

the class BranchResolver method resolve.

public Branch resolve(Repository repository, String branchName) {
    try (RepositoryService repositoryService = repositoryServiceFactory.create(repository)) {
        BranchesCommandBuilder branchesCommand = repositoryService.getBranchesCommand();
        List<Branch> allBranches = branchesCommand.getBranches().getBranches();
        return allBranches.stream().filter(b -> b.getName().equals(branchName)).findFirst().orElseThrow(() -> notFound(entity("branch", branchName).in(repository)));
    } catch (IOException e) {
        throw new InternalRepositoryException(repository, "could not read branches", e);
    }
}
Also used : BranchesCommandBuilder(sonia.scm.repository.api.BranchesCommandBuilder) Branch(sonia.scm.repository.Branch) IOException(java.io.IOException) RepositoryService(sonia.scm.repository.api.RepositoryService) InternalRepositoryException(sonia.scm.repository.InternalRepositoryException)

Aggregations

IOException (java.io.IOException)2 InternalRepositoryException (sonia.scm.repository.InternalRepositoryException)2 RepositoryService (sonia.scm.repository.api.RepositoryService)2 HashSet (java.util.HashSet)1 Branch (sonia.scm.repository.Branch)1 Person (sonia.scm.repository.Person)1 BranchesCommandBuilder (sonia.scm.repository.api.BranchesCommandBuilder)1