Search in sources :

Example 1 with RepositoryService

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

the class BranchRevisionResolver method getRevisions.

public RevisionResult getRevisions(NamespaceAndName namespaceAndName, PullRequest pullRequest) {
    try (RepositoryService repositoryService = repositoryServiceFactory.create(namespaceAndName)) {
        RevisionResolver resolver = new RevisionResolver(repositoryService);
        String sourceRevision = resolver.resolve(pullRequest.getSource());
        String targetRevision = resolver.resolve(pullRequest.getTarget());
        return new RevisionResult(sourceRevision, targetRevision);
    }
}
Also used : RepositoryService(sonia.scm.repository.api.RepositoryService)

Example 2 with RepositoryService

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

the class MergeService method checkMerge.

public MergeCheckResult checkMerge(NamespaceAndName namespaceAndName, String pullRequestId) {
    try (RepositoryService repositoryService = serviceFactory.create(namespaceAndName)) {
        PullRequest pullRequest = pullRequestService.get(repositoryService.getRepository(), pullRequestId);
        boolean isMergeable = dryRun(repositoryService, pullRequest).map(MergeDryRunCommandResult::isMergeable).orElse(false);
        Collection<MergeObstacle> obstacles = getObstacles(repositoryService.getRepository(), pullRequest);
        return new MergeCheckResult(!isMergeable, obstacles);
    }
}
Also used : RepositoryService(sonia.scm.repository.api.RepositoryService)

Example 3 with RepositoryService

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

the class MergeService method merge.

public void merge(NamespaceAndName namespaceAndName, String pullRequestId, MergeCommitDto mergeCommitDto, MergeStrategy strategy, boolean emergency) {
    try (RepositoryService repositoryService = serviceFactory.create(namespaceAndName)) {
        PullRequest pullRequest = pullRequestService.get(repositoryService.getRepository(), pullRequestId);
        Collection<MergeObstacle> obstacles = verifyNoObstacles(emergency, repositoryService.getRepository(), pullRequest);
        assertPullRequestIsOpen(repositoryService.getRepository(), pullRequest);
        internalMergeSwitch.runInternalMerge(() -> {
            MergeCommandBuilder mergeCommand = repositoryService.getMergeCommand();
            isAllowedToMerge(repositoryService.getRepository(), mergeCommand, strategy, emergency);
            prepareMergeCommand(repositoryService, mergeCommand, pullRequest, mergeCommitDto, strategy);
            MergeCommandResult mergeCommandResult = mergeCommand.executeMerge();
            if (!mergeCommandResult.isSuccess()) {
                throw new MergeConflictException(namespaceAndName, pullRequest.getSource(), pullRequest.getTarget(), mergeCommandResult);
            }
            pullRequestService.setRevisions(repositoryService.getRepository(), pullRequest.getId(), mergeCommandResult.getTargetRevision(), mergeCommandResult.getRevisionToMerge());
            if (emergency) {
                pullRequestService.setEmergencyMerged(repositoryService.getRepository(), pullRequest.getId(), mergeCommitDto.getOverrideMessage(), getIgnoredMergeObstacles(obstacles));
            } else {
                pullRequestService.setMerged(repositoryService.getRepository(), pullRequest.getId());
            }
            if (repositoryService.isSupported(Command.BRANCH) && mergeCommitDto.isShouldDeleteSourceBranch()) {
                String deletedSourceBranch = pullRequest.getSource();
                Repository repository = repositoryService.getRepository();
                repositoryService.getBranchCommand().delete(deletedSourceBranch);
                rejectPullRequestsForDeletedBranch(repository, pullRequest, deletedSourceBranch);
            }
        });
    }
}
Also used : Repository(sonia.scm.repository.Repository) MergeCommandBuilder(sonia.scm.repository.api.MergeCommandBuilder) MergeCommandResult(sonia.scm.repository.api.MergeCommandResult) RepositoryService(sonia.scm.repository.api.RepositoryService)

Example 4 with RepositoryService

use of sonia.scm.repository.api.RepositoryService 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 5 with RepositoryService

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

the class MergeService method conflicts.

public MergeConflictResult conflicts(NamespaceAndName namespaceAndName, String pullRequestId) {
    try (RepositoryService repositoryService = serviceFactory.create(namespaceAndName)) {
        PullRequest pullRequest = pullRequestService.get(repositoryService.getRepository(), pullRequestId);
        RepositoryPermissions.push(repositoryService.getRepository()).check();
        MergeCommandBuilder mergeCommandBuilder = prepareDryRun(repositoryService, pullRequest.getSource(), pullRequest.getTarget());
        return mergeCommandBuilder.conflicts();
    }
}
Also used : MergeCommandBuilder(sonia.scm.repository.api.MergeCommandBuilder) RepositoryService(sonia.scm.repository.api.RepositoryService)

Aggregations

RepositoryService (sonia.scm.repository.api.RepositoryService)10 IOException (java.io.IOException)2 Repository (sonia.scm.repository.Repository)2 MergeCommandBuilder (sonia.scm.repository.api.MergeCommandBuilder)2 CurrentUserResolver (com.cloudogu.scm.review.CurrentUserResolver)1 CurrentUserResolver.getCurrentUser (com.cloudogu.scm.review.CurrentUserResolver.getCurrentUser)1 PermissionCheck (com.cloudogu.scm.review.PermissionCheck)1 PullRequestResourceLinks (com.cloudogu.scm.review.PullRequestResourceLinks)1 Comment (com.cloudogu.scm.review.comment.service.Comment)1 CommentService (com.cloudogu.scm.review.comment.service.CommentService)1 CommentType (com.cloudogu.scm.review.comment.service.CommentType)1 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)1 PullRequestService (com.cloudogu.scm.review.pullrequest.service.PullRequestService)1 PullRequestStatus (com.cloudogu.scm.review.pullrequest.service.PullRequestStatus)1 ReviewMark (com.cloudogu.scm.review.pullrequest.service.ReviewMark)1 Strings (com.google.common.base.Strings)1 Embedded (de.otto.edison.hal.Embedded)1 Embedded.embeddedBuilder (de.otto.edison.hal.Embedded.embeddedBuilder)1 Link (de.otto.edison.hal.Link)1 Link.link (de.otto.edison.hal.Link.link)1