use of sonia.scm.repository.api.RepositoryService in project scm-review-plugin by scm-manager.
the class DefaultPullRequestServiceTest method mockChangesets.
private void mockChangesets(Changeset... changesets) throws IOException {
RepositoryService service = mock(RepositoryService.class);
lenient().when(repositoryService.create(any(Repository.class))).thenReturn(service);
LogCommandBuilder logCommandBuilder = mock(LogCommandBuilder.class, Mockito.RETURNS_SELF);
lenient().when(service.getLogCommand()).thenReturn(logCommandBuilder);
lenient().when(logCommandBuilder.getChangesets()).thenReturn(new ChangesetPagingResult(changesets.length, asList(changesets)));
}
use of sonia.scm.repository.api.RepositoryService in project scm-review-plugin by scm-manager.
the class OpenPullRequestProviderTest method mockPrSupport.
@BeforeEach
void mockPrSupport() {
RepositoryService repositoryServiceWithPr = mockedRepositoryService(true);
when(serviceFactory.create(PR_REPOSITORY)).thenReturn(repositoryServiceWithPr);
RepositoryService repositoryServiceWithoutPr = mockedRepositoryService(false);
when(serviceFactory.create(NO_PR_REPOSITORY)).thenReturn(repositoryServiceWithoutPr);
}
use of sonia.scm.repository.api.RepositoryService in project scm-review-plugin by scm-manager.
the class OpenPullRequestProviderTest method mockedRepositoryService.
private RepositoryService mockedRepositoryService(boolean prSupported) {
RepositoryService repositoryService = mock(RepositoryService.class);
when(repositoryService.isSupported(Command.MERGE)).thenReturn(prSupported);
return repositoryService;
}
use of sonia.scm.repository.api.RepositoryService 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);
}
}
use of sonia.scm.repository.api.RepositoryService in project scm-review-plugin by scm-manager.
the class PullRequestMapper method appendMergeStrategyLinks.
private void appendMergeStrategyLinks(Links.Builder linksBuilder, Repository repository, PullRequest pullRequest) {
try (RepositoryService service = serviceFactory.create(repository)) {
if (service.isSupported(Command.MERGE)) {
List<Link> mergeStrategyLinks = service.getMergeCommand().getSupportedMergeStrategies().stream().map(strategy -> createMergeStrategyLink(repository.getNamespaceAndName(), pullRequest, strategy)).collect(toList());
linksBuilder.array(mergeStrategyLinks);
if (PermissionCheck.mayPerformEmergencyMerge(repository)) {
List<Link> emergencyMergeStrategyLinks = service.getMergeCommand().getSupportedMergeStrategies().stream().map(strategy -> createEmergencyMergeStrategyLink(repository.getNamespaceAndName(), pullRequest, strategy)).collect(toList());
linksBuilder.array(emergencyMergeStrategyLinks);
}
}
}
}
Aggregations