Search in sources :

Example 6 with CommitDefaults

use of com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults in project scm-review-plugin by scm-manager.

the class MergeResourceTest method shouldCreateSquashCommitMessage.

@Test
void shouldCreateSquashCommitMessage() throws IOException, URISyntaxException {
    when(mergeService.createCommitDefaults(any(), any(), eq(SQUASH))).thenReturn(new CommitDefaults("successful", DisplayUser.from(new User("Arthur Dent"))));
    MockHttpRequest request = createHttpGetRequest(MERGE_URL + "/commit-message/?strategy=SQUASH");
    MockHttpResponse response = new MockHttpResponse();
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).isEqualTo("successful");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) CommitDefaults(com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) JsonMockHttpResponse(sonia.scm.web.JsonMockHttpResponse) Test(org.junit.jupiter.api.Test)

Example 7 with CommitDefaults

use of com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults 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 8 with CommitDefaults

use of com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults 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

CommitDefaults (com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults)8 Test (org.junit.jupiter.api.Test)8 DisplayUser (sonia.scm.user.DisplayUser)6 User (sonia.scm.user.User)6 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)5 JsonMockHttpResponse (sonia.scm.web.JsonMockHttpResponse)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 MockHttpResponse (org.jboss.resteasy.mock.MockHttpResponse)2 Changeset (sonia.scm.repository.Changeset)2 ChangesetPagingResult (sonia.scm.repository.ChangesetPagingResult)2 Person (sonia.scm.repository.Person)2