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");
}
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");
}
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");
}
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")));
}
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);
}
Aggregations