Search in sources :

Example 1 with MergeCommitDto

use of com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto in project scm-review-plugin by scm-manager.

the class MergeServiceTest method createMergeCommit.

private MergeCommitDto createMergeCommit(boolean deleteBranch) {
    MergeCommitDto mergeCommit = new MergeCommitDto();
    mergeCommit.setShouldDeleteSourceBranch(deleteBranch);
    mergeCommit.setOverrideMessage("override");
    return mergeCommit;
}
Also used : MergeCommitDto(com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto)

Example 2 with MergeCommitDto

use of com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto in project scm-review-plugin by scm-manager.

the class MergeServiceTest method shouldNotMergeWithObstaclesIfNotEmergency.

@Test
void shouldNotMergeWithObstaclesIfNotEmergency() {
    PullRequest pullRequest = mockPullRequest("squash", "master", "1");
    mockMergeGuard(pullRequest, true);
    MergeCommitDto mergeCommit = createMergeCommit(false);
    NamespaceAndName namespaceAndName = REPOSITORY.getNamespaceAndName();
    assertThrows(MergeNotAllowedException.class, () -> service.merge(namespaceAndName, "1", mergeCommit, MergeStrategy.SQUASH, false));
}
Also used : MergeCommitDto(com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto) NamespaceAndName(sonia.scm.repository.NamespaceAndName) Test(org.junit.jupiter.api.Test)

Example 3 with MergeCommitDto

use of com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto in project scm-review-plugin by scm-manager.

the class MergeServiceTest method shouldNotEnrichCommitMessageWithMergerAsCoAuthor.

@Test
void shouldNotEnrichCommitMessageWithMergerAsCoAuthor() throws IOException {
    mockUser("arthur", "Arthur Dent", "dent@hitchhiker.org");
    when(mergeCommandBuilder.isSupported(MergeStrategy.SQUASH)).thenReturn(true);
    when(mergeCommandBuilder.executeMerge()).thenReturn(MergeCommandResult.success("1", "2", "123"));
    ImmutableList<Changeset> changesets = ImmutableList.of(new Changeset("1", 1L, new Person("Arthur Dent", "dent@hitchhiker.org"), "42\n\nCo-authored-by: Tricia McMillan <trillian@hitchhiker.org>"), new Changeset("2", 2L, new Person("Arthur Dent", "dent@hitchhiker.org"), "42\n\nCo-authored-by: Arthur Dent <dent@hitchhiker.org>"));
    when(logCommandBuilder.getChangesets()).thenReturn(new ChangesetPagingResult(1, changesets));
    PullRequest pullRequest = mockPullRequest("squash", "master", "1");
    pullRequest.setAuthor("Arthur Dent");
    MergeCommitDto mergeCommit = createMergeCommit(false);
    mergeCommit.setCommitMessage("42");
    service.merge(REPOSITORY.getNamespaceAndName(), "1", mergeCommit, MergeStrategy.SQUASH, false);
    verify(mergeCommandBuilder).setMessage("42\n\n" + "Co-authored-by: Tricia McMillan <trillian@hitchhiker.org>\n");
}
Also used : MergeCommitDto(com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto) ChangesetPagingResult(sonia.scm.repository.ChangesetPagingResult) Changeset(sonia.scm.repository.Changeset) Person(sonia.scm.repository.Person) Test(org.junit.jupiter.api.Test)

Example 4 with MergeCommitDto

use of com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto in project scm-review-plugin by scm-manager.

the class MergeServiceTest method shouldEnrichCommitMessageWithCoAuthoredBy.

@Test
void shouldEnrichCommitMessageWithCoAuthoredBy() throws IOException {
    mockUser("zaphod", "Zaphod Beeblebrox", "zaphod@hitchhiker.org");
    when(mergeCommandBuilder.isSupported(MergeStrategy.SQUASH)).thenReturn(true);
    when(mergeCommandBuilder.executeMerge()).thenReturn(MergeCommandResult.success("1", "2", "123"));
    ImmutableList<Changeset> changesets = ImmutableList.of(new Changeset("1", 1L, new Person("Arthur Dent", "dent@hitchhiker.org")), new Changeset("2", 2L, new Person("Tricia McMillan", "trillian@hitchhiker.org")));
    when(logCommandBuilder.getChangesets()).thenReturn(new ChangesetPagingResult(1, changesets));
    mockPullRequest("squash", "master", "1");
    MergeCommitDto mergeCommit = createMergeCommit(false);
    mergeCommit.setCommitMessage("42");
    service.merge(REPOSITORY.getNamespaceAndName(), "1", mergeCommit, MergeStrategy.SQUASH, false);
    verify(mergeCommandBuilder).setMessage("42\n\n" + "Co-authored-by: Arthur Dent <dent@hitchhiker.org>\n" + "Co-authored-by: Tricia McMillan <trillian@hitchhiker.org>\n");
}
Also used : MergeCommitDto(com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto) ChangesetPagingResult(sonia.scm.repository.ChangesetPagingResult) Changeset(sonia.scm.repository.Changeset) Person(sonia.scm.repository.Person) Test(org.junit.jupiter.api.Test)

Example 5 with MergeCommitDto

use of com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto in project scm-review-plugin by scm-manager.

the class MergeServiceTest method shouldThrowExceptionIfStrategyNotSupported.

@Test
void shouldThrowExceptionIfStrategyNotSupported() {
    when(mergeCommandBuilder.isSupported(MergeStrategy.SQUASH)).thenReturn(false);
    mockPullRequest("squash", "master", "1");
    MergeCommitDto mergeCommit = createMergeCommit(false);
    NamespaceAndName namespaceAndName = REPOSITORY.getNamespaceAndName();
    assertThrows(MergeStrategyNotSupportedException.class, () -> service.merge(namespaceAndName, "1", mergeCommit, MergeStrategy.SQUASH, false));
}
Also used : MergeCommitDto(com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto) NamespaceAndName(sonia.scm.repository.NamespaceAndName) Test(org.junit.jupiter.api.Test)

Aggregations

MergeCommitDto (com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto)18 Test (org.junit.jupiter.api.Test)17 NamespaceAndName (sonia.scm.repository.NamespaceAndName)6 Changeset (sonia.scm.repository.Changeset)4 ChangesetPagingResult (sonia.scm.repository.ChangesetPagingResult)4 Person (sonia.scm.repository.Person)4 LinkedHashMap (java.util.LinkedHashMap)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Repository (sonia.scm.repository.Repository)2 HashMap (java.util.HashMap)1 BranchCommandBuilder (sonia.scm.repository.api.BranchCommandBuilder)1 DisplayUser (sonia.scm.user.DisplayUser)1 User (sonia.scm.user.User)1