Search in sources :

Example 1 with BranchesCommandBuilder

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

the class BranchRevisionResolverTest method setUpBranches.

private void setUpBranches(String... names) throws IOException {
    when(repositoryService.getBranchesCommand()).thenReturn(branchesCommandBuilder);
    List<Branch> branches = Arrays.stream(names).map(name -> Branch.normalBranch(name, name)).collect(Collectors.toList());
    when(branchesCommandBuilder.getBranches()).thenReturn(new Branches(branches));
}
Also used : Branch(sonia.scm.repository.Branch) Arrays(java.util.Arrays) BranchesCommandBuilder(sonia.scm.repository.api.BranchesCommandBuilder) Mock(org.mockito.Mock) Mockito.lenient(org.mockito.Mockito.lenient) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Collections.singletonList(java.util.Collections.singletonList) ChangesetPagingResult(sonia.scm.repository.ChangesetPagingResult) LogCommandBuilder(sonia.scm.repository.api.LogCommandBuilder) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RepositoryServiceFactory(sonia.scm.repository.api.RepositoryServiceFactory) Assertions(org.assertj.core.api.Assertions) RepositoryService(sonia.scm.repository.api.RepositoryService) Branches(sonia.scm.repository.Branches) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) TestData(com.cloudogu.scm.review.TestData) Changeset(sonia.scm.repository.Changeset) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) List(java.util.List) NamespaceAndName(sonia.scm.repository.NamespaceAndName) Mockito.mock(org.mockito.Mockito.mock) Branch(sonia.scm.repository.Branch) Branches(sonia.scm.repository.Branches)

Example 2 with BranchesCommandBuilder

use of sonia.scm.repository.api.BranchesCommandBuilder 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 Branch (sonia.scm.repository.Branch)2 BranchesCommandBuilder (sonia.scm.repository.api.BranchesCommandBuilder)2 RepositoryService (sonia.scm.repository.api.RepositoryService)2 TestData (com.cloudogu.scm.review.TestData)1 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)1 Arrays (java.util.Arrays)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Assertions (org.assertj.core.api.Assertions)1 Test (org.junit.jupiter.api.Test)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 InjectMocks (org.mockito.InjectMocks)1 Mock (org.mockito.Mock)1 Mockito.lenient (org.mockito.Mockito.lenient)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.when (org.mockito.Mockito.when)1 MockitoExtension (org.mockito.junit.jupiter.MockitoExtension)1