Search in sources :

Example 6 with RepositoryService

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)));
}
Also used : Repository(sonia.scm.repository.Repository) ChangesetPagingResult(sonia.scm.repository.ChangesetPagingResult) LogCommandBuilder(sonia.scm.repository.api.LogCommandBuilder) RepositoryService(sonia.scm.repository.api.RepositoryService)

Example 7 with RepositoryService

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);
}
Also used : RepositoryService(sonia.scm.repository.api.RepositoryService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with RepositoryService

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;
}
Also used : RepositoryService(sonia.scm.repository.api.RepositoryService)

Example 9 with 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);
    }
}
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)

Example 10 with RepositoryService

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);
            }
        }
    }
}
Also used : Mapping(org.mapstruct.Mapping) RepositoryPermissions(sonia.scm.repository.RepositoryPermissions) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) MappingTarget(org.mapstruct.MappingTarget) Embedded.embeddedBuilder(de.otto.edison.hal.Embedded.embeddedBuilder) Links(de.otto.edison.hal.Links) Mapper(org.mapstruct.Mapper) Comment(com.cloudogu.scm.review.comment.service.Comment) Map(java.util.Map) Link.link(de.otto.edison.hal.Link.link) PermissionCheck(com.cloudogu.scm.review.PermissionCheck) RepositoryService(sonia.scm.repository.api.RepositoryService) CurrentUserResolver.getCurrentUser(com.cloudogu.scm.review.CurrentUserResolver.getCurrentUser) PullRequestService(com.cloudogu.scm.review.pullrequest.service.PullRequestService) URI(java.net.URI) Predicate(java.util.function.Predicate) Set(java.util.Set) MergeStrategy(sonia.scm.repository.api.MergeStrategy) Collectors(java.util.stream.Collectors) List(java.util.List) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) CommentService(com.cloudogu.scm.review.comment.service.CommentService) CommentType(com.cloudogu.scm.review.comment.service.CommentType) UserDisplayManager(sonia.scm.user.UserDisplayManager) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) NamespaceAndName(sonia.scm.repository.NamespaceAndName) PullRequestStatus(com.cloudogu.scm.review.pullrequest.service.PullRequestStatus) Embedded(de.otto.edison.hal.Embedded) HashMap(java.util.HashMap) DisplayUser(sonia.scm.user.DisplayUser) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) EdisonHalAppender(sonia.scm.web.EdisonHalAppender) CurrentUserResolver(com.cloudogu.scm.review.CurrentUserResolver) RepositoryServiceFactory(sonia.scm.repository.api.RepositoryServiceFactory) Named(javax.inject.Named) Command(sonia.scm.repository.api.Command) BaseMapper(sonia.scm.api.v2.resources.BaseMapper) BranchLinkProvider(sonia.scm.api.v2.resources.BranchLinkProvider) AfterMapping(org.mapstruct.AfterMapping) Context(org.mapstruct.Context) ObjectFactory(org.mapstruct.ObjectFactory) Links.linkingTo(de.otto.edison.hal.Links.linkingTo) User(sonia.scm.user.User) Collectors.toList(java.util.stream.Collectors.toList) ReviewMark(com.cloudogu.scm.review.pullrequest.service.ReviewMark) Link(de.otto.edison.hal.Link) Link(de.otto.edison.hal.Link) 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