Search in sources :

Example 1 with MergeCommandBuilder

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

use of sonia.scm.repository.api.MergeCommandBuilder 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)

Example 3 with MergeCommandBuilder

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

the class MergeService method prepareDryRun.

private MergeCommandBuilder prepareDryRun(RepositoryService repositoryService, String sourceBranch, String targetBranch) {
    MergeCommandBuilder mergeCommand = repositoryService.getMergeCommand();
    mergeCommand.setBranchToMerge(sourceBranch);
    mergeCommand.setTargetBranch(targetBranch);
    return mergeCommand;
}
Also used : MergeCommandBuilder(sonia.scm.repository.api.MergeCommandBuilder)

Aggregations

MergeCommandBuilder (sonia.scm.repository.api.MergeCommandBuilder)3 RepositoryService (sonia.scm.repository.api.RepositoryService)2 Repository (sonia.scm.repository.Repository)1 MergeCommandResult (sonia.scm.repository.api.MergeCommandResult)1