Search in sources :

Example 1 with Branches

use of sonia.scm.repository.Branches 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 Branches

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

the class PullRequestInformationHook method checkIfMultipleBranchesExist.

private boolean checkIfMultipleBranchesExist(RepositoryService repositoryService) {
    try {
        Branches branches = repositoryService.getBranchesCommand().getBranches();
        int branchCount = branches.getBranches().size();
        return branchCount > 1;
    } catch (IOException ex) {
        LOG.warn("could not read branches for repository {}, assuming only one branch exists", repositoryService.getRepository());
        return false;
    }
}
Also used : Branches(sonia.scm.repository.Branches) IOException(java.io.IOException)

Example 3 with Branches

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

the class PullRequestInformationHookTest method init.

@Before
public void init() throws IOException {
    hook = new PullRequestInformationHook(pullRequestService, serviceFactory, messageSenderFactory);
    when(event.getContext()).thenReturn(context);
    when(event.getRepository()).thenReturn(REPOSITORY);
    when(context.getBranchProvider()).thenReturn(branchProvider);
    when(context.getMessageProvider()).thenReturn(messageProvider);
    when(context.isFeatureSupported(MESSAGE_PROVIDER)).thenReturn(true);
    when(branchProvider.getCreatedOrModified()).thenReturn(Collections.emptyList());
    when(serviceFactory.create(REPOSITORY)).thenReturn(service);
    when(service.isSupported(Command.MERGE)).thenReturn(true);
    when(configuration.getBaseUrl()).thenReturn("http://example.com");
    when(pullRequestService.getAll("space", "X")).thenReturn(asList(OPEN_PULL_REQUEST, MERGED_PULL_REQUEST));
    doNothing().when(messageProvider).sendMessage(messageCaptor.capture());
    when(service.getBranchesCommand()).thenReturn(branchesCommand);
    Branches branches = new Branches(Branch.defaultBranch("main", "", 0L), Branch.normalBranch("x", "", 0L));
    when(branchesCommand.getBranches()).thenReturn(branches);
}
Also used : Branches(sonia.scm.repository.Branches) Before(org.junit.Before)

Example 4 with Branches

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

the class PullRequestInformationHookTest method shouldSendMessageWithoutCreateLinks.

@Test
@SubjectAware(username = "dent")
public void shouldSendMessageWithoutCreateLinks() throws Exception {
    when(branchProvider.getCreatedOrModified()).thenReturn(singletonList("branch_1"));
    when(service.getBranchesCommand()).thenReturn(branchesCommand);
    Branches branches = new Branches(Branch.defaultBranch("main", "", 0L));
    when(branchesCommand.getBranches()).thenReturn(branches);
    hook.checkForInformation(event);
    List<String> sentMessages = messageCaptor.getAllValues();
    assertThat(sentMessages).filteredOn(s -> s.length() > 0).isEmpty();
}
Also used : Branch(sonia.scm.repository.Branch) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BranchesCommandBuilder(sonia.scm.repository.api.BranchesCommandBuilder) ShiroRule(com.github.sdorra.shiro.ShiroRule) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) HookContext(sonia.scm.repository.api.HookContext) Captor(org.mockito.Captor) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Collections.singletonList(java.util.Collections.singletonList) ArgumentCaptor(org.mockito.ArgumentCaptor) Arrays.asList(java.util.Arrays.asList) RepositoryServiceFactory(sonia.scm.repository.api.RepositoryServiceFactory) RepositoryService(sonia.scm.repository.api.RepositoryService) PullRequestService(com.cloudogu.scm.review.pullrequest.service.PullRequestService) Branches(sonia.scm.repository.Branches) HookMessageProvider(sonia.scm.repository.api.HookMessageProvider) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) ScmConfiguration(sonia.scm.config.ScmConfiguration) Command(sonia.scm.repository.api.Command) MESSAGE_PROVIDER(sonia.scm.repository.api.HookFeature.MESSAGE_PROVIDER) Test(org.junit.Test) IOException(java.io.IOException) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) Mockito.never(org.mockito.Mockito.never) SubjectAware(com.github.sdorra.shiro.SubjectAware) Rule(org.junit.Rule) HookBranchProvider(sonia.scm.repository.api.HookBranchProvider) PostReceiveRepositoryHookEvent(sonia.scm.repository.PostReceiveRepositoryHookEvent) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) PullRequestStatus(com.cloudogu.scm.review.pullrequest.service.PullRequestStatus) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Branches(sonia.scm.repository.Branches) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 5 with Branches

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

the class MergeServiceTest method mocksForPullRequestUpdate.

private void mocksForPullRequestUpdate(String branchName) throws IOException {
    lenient().when(repositoryService.isSupported(Command.BRANCH)).thenReturn(true);
    lenient().when(repositoryService.isSupported(Command.BRANCHES)).thenReturn(true);
    when(mergeCommandBuilder.isSupported(MergeStrategy.MERGE_COMMIT)).thenReturn(true);
    when(mergeCommandBuilder.executeMerge()).thenReturn(MergeCommandResult.success("1", "2", "123"));
    when(repositoryService.getBranchCommand()).thenReturn(branchCommandBuilder);
    Branches branches = new Branches();
    branches.setBranches(ImmutableList.of(Branch.normalBranch(branchName, "123")));
    when(branchesCommandBuilder.getBranches()).thenReturn(branches);
}
Also used : Branches(sonia.scm.repository.Branches)

Aggregations

Branches (sonia.scm.repository.Branches)5 IOException (java.io.IOException)3 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Before (org.junit.Before)2 InjectMocks (org.mockito.InjectMocks)2 Mock (org.mockito.Mock)2 Mockito.verify (org.mockito.Mockito.verify)2 Mockito.when (org.mockito.Mockito.when)2 Branch (sonia.scm.repository.Branch)2 BranchesCommandBuilder (sonia.scm.repository.api.BranchesCommandBuilder)2 RepositoryService (sonia.scm.repository.api.RepositoryService)2 RepositoryServiceFactory (sonia.scm.repository.api.RepositoryServiceFactory)2 TestData (com.cloudogu.scm.review.TestData)1 PullRequestService (com.cloudogu.scm.review.pullrequest.service.PullRequestService)1 PullRequestStatus (com.cloudogu.scm.review.pullrequest.service.PullRequestStatus)1 ShiroRule (com.github.sdorra.shiro.ShiroRule)1 SubjectAware (com.github.sdorra.shiro.SubjectAware)1 Arrays (java.util.Arrays)1