Search in sources :

Example 11 with Changeset

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

the class ModificationCollectorTest method shouldCloseRepositoryServiceEvenOnError.

@Test
void shouldCloseRepositoryServiceEvenOnError() throws IOException {
    when(repositoryService.getModificationsCommand()).thenThrow(new IllegalStateException("fail"));
    Changeset one = changeset("21").added("a.txt").removed("b.txt").build();
    try {
        collector.collect(repository, ImmutableList.of(one));
    } catch (IllegalStateException ex) {
    // we only want to verify, if the repository service was closed
    }
    verify(repositoryService).close();
}
Also used : Changeset(sonia.scm.repository.Changeset) Test(org.junit.jupiter.api.Test)

Example 12 with Changeset

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

the class PullRequestRootResourceTest method shouldReturnAlreadyExistsResult.

@Test
@SubjectAware(username = "dent")
public void shouldReturnAlreadyExistsResult() throws URISyntaxException, IOException {
    mockLoggedInUser(new User("dent"));
    mockLogCommandForPullRequestCheck(ImmutableList.of(new Changeset()));
    PullRequest pullRequest = createPullRequest();
    when(store.getAll()).thenReturn(ImmutableList.of(pullRequest));
    MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/check?source=develop&target=master");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).contains("\"status\":\"PR_ALREADY_EXISTS\"");
    assertThat(response.getContentAsString()).contains("\"_links\":{\"self\":{\"href\":\"/v2/pull-requests/ns/repo/check?source=develop&target=master\"}}");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) TestData.createPullRequest(com.cloudogu.scm.review.TestData.createPullRequest) Changeset(sonia.scm.repository.Changeset) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 13 with Changeset

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

the class PullRequestRootResourceTest method shouldReturnBranchesNotDifferResultIfSameBranches.

@Test
@SubjectAware(username = "dent")
public void shouldReturnBranchesNotDifferResultIfSameBranches() throws URISyntaxException, IOException {
    mockLoggedInUser(new User("dent"));
    mockLogCommandForPullRequestCheck(ImmutableList.of(new Changeset()));
    MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/check?source=master&target=master");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).contains("\"status\":\"BRANCHES_NOT_DIFFER\"");
    assertThat(response.getContentAsString()).contains("\"_links\":{\"self\":{\"href\":\"/v2/pull-requests/ns/repo/check?source=master&target=master\"}}");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) Changeset(sonia.scm.repository.Changeset) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 14 with Changeset

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

use of sonia.scm.repository.Changeset 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)

Aggregations

Changeset (sonia.scm.repository.Changeset)17 Test (org.junit.jupiter.api.Test)9 ChangesetPagingResult (sonia.scm.repository.ChangesetPagingResult)7 Person (sonia.scm.repository.Person)6 DisplayUser (sonia.scm.user.DisplayUser)5 User (sonia.scm.user.User)5 TestData.createPullRequest (com.cloudogu.scm.review.TestData.createPullRequest)4 MergeCommitDto (com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto)4 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)4 SubjectAware (com.github.sdorra.shiro.SubjectAware)4 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)4 Test (org.junit.Test)4 CommitDefaults (com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Scanner (java.util.Scanner)1 Pattern (java.util.regex.Pattern)1 PostReceiveRepositoryHookEvent (sonia.scm.repository.PostReceiveRepositoryHookEvent)1 LogCommandBuilder (sonia.scm.repository.api.LogCommandBuilder)1