Search in sources :

Example 26 with User

use of sonia.scm.user.User 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)

Example 27 with User

use of sonia.scm.user.User in project scm-review-plugin by scm-manager.

the class MergeServiceTest method shouldEnrichCommitMessageWithReviewedBy.

@Test
void shouldEnrichCommitMessageWithReviewedBy() {
    mockUser("zaphod", "Zaphod Beeblebrox", "zaphod@hitchhiker.org");
    when(mergeCommandBuilder.isSupported(MergeStrategy.MERGE_COMMIT)).thenReturn(true);
    when(mergeCommandBuilder.executeMerge()).thenReturn(MergeCommandResult.success("1", "2", "123"));
    when(userDisplayManager.get("trillian")).thenReturn(of(DisplayUser.from(new User("trillian", "Tricia McMillan", "trillian@hitchhiker.org"))));
    when(userDisplayManager.get("dent")).thenReturn(of(DisplayUser.from(new User("dent", "Arthur Dent", "dent@hitchhiker.org"))));
    PullRequest pullRequest = mockPullRequest("squash", "master", "1");
    LinkedHashMap<String, Boolean> reviewers = new LinkedHashMap<>();
    reviewers.put("dent", true);
    reviewers.put("trillian", true);
    reviewers.put("zaphod", false);
    pullRequest.setReviewer(reviewers);
    MergeCommitDto mergeCommit = createMergeCommit(false);
    mergeCommit.setCommitMessage("42");
    service.merge(REPOSITORY.getNamespaceAndName(), "1", mergeCommit, MergeStrategy.MERGE_COMMIT, false);
    verify(mergeCommandBuilder).setMessage("42\n\n" + "Reviewed-by: Arthur Dent <dent@hitchhiker.org>\n" + "Reviewed-by: Tricia McMillan <trillian@hitchhiker.org>\n");
}
Also used : MergeCommitDto(com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Aggregations

User (sonia.scm.user.User)27 DisplayUser (sonia.scm.user.DisplayUser)23 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)15 Test (org.junit.Test)11 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)9 TestData.createPullRequest (com.cloudogu.scm.review.TestData.createPullRequest)8 Test (org.junit.jupiter.api.Test)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 CommitDefaults (com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults)6 SubjectAware (com.github.sdorra.shiro.SubjectAware)6 Changeset (sonia.scm.repository.Changeset)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)3 MockHttpResponse (org.jboss.resteasy.mock.MockHttpResponse)3 ChangesetPagingResult (sonia.scm.repository.ChangesetPagingResult)3 JsonMockHttpResponse (sonia.scm.web.JsonMockHttpResponse)3 DefaultPullRequestService (com.cloudogu.scm.review.pullrequest.service.DefaultPullRequestService)2 ReviewMark (com.cloudogu.scm.review.pullrequest.service.ReviewMark)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Person (sonia.scm.repository.Person)2