Search in sources :

Example 6 with ChangesetPagingResult

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

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

the class MergeServiceTest method shouldNotEnrichCommitMessageWithMergerAsReviewer.

@Test
void shouldNotEnrichCommitMessageWithMergerAsReviewer() 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("Zaphod Beeblebrox", "zaphod@hitchhiker.org"), "42\n\nCo-authored-by: Tricia McMillan <trillian@hitchhiker.org>"), new Changeset("2", 2L, new Person("Tricia McMillan", "trillian@hitchhiker.org"), "42\n\n"));
    when(logCommandBuilder.getChangesets()).thenReturn(new ChangesetPagingResult(1, changesets));
    PullRequest pullRequest = mockPullRequest("squash", "master", "1");
    pullRequest.setAuthor("Arthur Dent");
    HashMap<String, Boolean> reviewers = new HashMap<>();
    reviewers.put("dent", true);
    pullRequest.setReviewer(reviewers);
    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: Zaphod Beeblebrox <zaphod@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) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Changeset(sonia.scm.repository.Changeset) Person(sonia.scm.repository.Person) Test(org.junit.jupiter.api.Test)

Example 8 with ChangesetPagingResult

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

the class MergeServiceTest method shouldEnrichCommitMessageWithCoAuthorsOfSquashedCommits.

@Test
void shouldEnrichCommitMessageWithCoAuthorsOfSquashedCommits() 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"), "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("Zaphod Beetlebrox");
    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 9 with ChangesetPagingResult

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

the class MergeServiceTest method shouldCreateCommitMessageForSquashWithFallbackForMissingAuthorFromPullRequest.

@Test
void shouldCreateCommitMessageForSquashWithFallbackForMissingAuthorFromPullRequest() throws IOException {
    User user = mockUser("trillian", "Tricia McMillan", "tricia@hitchhiker.com");
    when(subject.isPermitted("repository:read:" + REPOSITORY.getId())).thenReturn(true);
    when(repositoryService.isSupported(Command.LOG)).thenReturn(true);
    PullRequest pullRequest = createPullRequest();
    pullRequest.setAuthor("trillian");
    when(userDisplayManager.get("trillian")).thenReturn(Optional.of(DisplayUser.from(user)));
    when(pullRequestService.get(REPOSITORY.getNamespace(), REPOSITORY.getName(), "1")).thenReturn(pullRequest);
    Person author = new Person("Philip", "phil@groundhog.com");
    when(userDisplayManager.get("Philip")).thenReturn(Optional.of(DisplayUser.from(new User("Philip", "Philip Groundhog", "phil@groundhog.com"))));
    ChangesetPagingResult changesets = new ChangesetPagingResult(3, asList(new Changeset("1", 1L, author, "first commit"), new Changeset("2", 2L, author, "second commit\nwith multiple lines"), new Changeset("3", 3L, author, "third commit")));
    when(logCommandBuilder.getChangesets()).thenReturn(changesets);
    CommitDefaults commitDefaults = service.createCommitDefaults(REPOSITORY.getNamespaceAndName(), "1", MergeStrategy.SQUASH);
    assertThat(commitDefaults.getCommitMessage()).isEqualTo("Squash commits of branch squash:\n" + "\n" + "- first commit\n" + "\n" + "- second commit\n" + "with multiple lines\n" + "\n" + "- third commit\n" + "\n\n" + "Author: Tricia McMillan <tricia@hitchhiker.com>" + "\nCo-authored-by: Philip Groundhog <phil@groundhog.com>");
    assertThat(commitDefaults.getCommitAuthor()).usingRecursiveComparison().isEqualTo(DisplayUser.from(new User("trillian", "Tricia McMillan", "tricia@hitchhiker.com")));
}
Also used : ChangesetPagingResult(sonia.scm.repository.ChangesetPagingResult) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) CommitDefaults(com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults) Person(sonia.scm.repository.Person) Changeset(sonia.scm.repository.Changeset) Test(org.junit.jupiter.api.Test)

Example 10 with ChangesetPagingResult

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

the class MergeServiceTest method shouldCreateCommitMessageForSquashWithAuthorFromPullRequest.

@Test
void shouldCreateCommitMessageForSquashWithAuthorFromPullRequest() throws IOException {
    User user = mockUser("Phil", "Phil Groundhog", "phil@groundhog.com");
    when(email.getMailOrFallback(user)).thenReturn("phil@groundhog.com");
    DisplayUser currentUser = DisplayUser.from(new User("zaphod", "Zaphod Beeblebrox", "zaphod@hitchhiker.com"));
    when(userDisplayManager.get("zaphod")).thenReturn(of(currentUser));
    when(subject.isPermitted("repository:read:" + REPOSITORY.getId())).thenReturn(true);
    when(repositoryService.isSupported(Command.LOG)).thenReturn(true);
    PullRequest pullRequest = createPullRequest();
    pullRequest.setAuthor("zaphod");
    when(pullRequestService.get(REPOSITORY.getNamespace(), REPOSITORY.getName(), "1")).thenReturn(pullRequest);
    when(userDisplayManager.get("zaphod")).thenReturn(Optional.of(currentUser));
    Person author = new Person("Zaphod Beeblebrox", "zaphod@hitchhiker.com");
    ChangesetPagingResult changesets = new ChangesetPagingResult(3, asList(new Changeset("1", 1L, author, "first commit"), new Changeset("2", 2L, author, "second commit\nwith multiple lines"), new Changeset("3", 3L, new Person("Arthur", "dent@hitchhiker.com"), "third commit")));
    when(logCommandBuilder.getChangesets()).thenReturn(changesets);
    CommitDefaults commitDefaults = service.createCommitDefaults(REPOSITORY.getNamespaceAndName(), "1", MergeStrategy.SQUASH);
    assertThat(commitDefaults.getCommitMessage()).isEqualTo("Squash commits of branch squash:\n" + "\n" + "- first commit\n" + "\n" + "- second commit\n" + "with multiple lines\n" + "\n" + "- third commit\n" + "\n" + "\n" + "Author: Zaphod Beeblebrox <zaphod@hitchhiker.com>" + "\nCommitted-by: Phil Groundhog <phil@groundhog.com>" + "\nCo-authored-by: Arthur <dent@hitchhiker.com>");
    assertThat(commitDefaults.getCommitAuthor()).usingRecursiveComparison().isEqualTo(currentUser);
}
Also used : ChangesetPagingResult(sonia.scm.repository.ChangesetPagingResult) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) DisplayUser(sonia.scm.user.DisplayUser) CommitDefaults(com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults) Person(sonia.scm.repository.Person) Changeset(sonia.scm.repository.Changeset) Test(org.junit.jupiter.api.Test)

Aggregations

ChangesetPagingResult (sonia.scm.repository.ChangesetPagingResult)10 Changeset (sonia.scm.repository.Changeset)7 Test (org.junit.jupiter.api.Test)6 Person (sonia.scm.repository.Person)6 MergeCommitDto (com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto)4 LogCommandBuilder (sonia.scm.repository.api.LogCommandBuilder)3 CommitDefaults (com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults)2 DisplayUser (sonia.scm.user.DisplayUser)2 User (sonia.scm.user.User)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Repository (sonia.scm.repository.Repository)1 RepositoryService (sonia.scm.repository.api.RepositoryService)1