Search in sources :

Example 6 with Changeset

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

the class PullRequestRootResourceTest method initRepoWithPRs.

private void initRepoWithPRs(String namespace, String name) throws IOException {
    mockChangesets("develop", "master", new Changeset());
    when(repository.getNamespace()).thenReturn(namespace);
    when(repository.getName()).thenReturn(name);
    PullRequest openedPR1 = createPullRequest("opened_1", PullRequestStatus.OPEN);
    PullRequest openedPR2 = createPullRequest("opened_2", PullRequestStatus.OPEN);
    PullRequest mergedPR1 = createPullRequest("merged_1", PullRequestStatus.MERGED);
    PullRequest mergedPR2 = createPullRequest("merged_2", PullRequestStatus.MERGED);
    PullRequest rejectedPR1 = createPullRequest("rejected_1", REJECTED);
    PullRequest rejectedPR2 = createPullRequest("rejected_2", REJECTED);
    openedPR2.setAuthor("author");
    mergedPR2.setAuthor("author");
    openedPR1.setReviewer(singletonMap("reviewer", false));
    mergedPR1.setReviewer(singletonMap("reviewer", true));
    when(store.getAll()).thenReturn(Lists.newArrayList(openedPR1, openedPR2, rejectedPR1, rejectedPR2, mergedPR1, mergedPR2));
    when(commentService.getAll(any(), any(), any())).thenReturn(Collections.emptyList());
}
Also used : PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) TestData.createPullRequest(com.cloudogu.scm.review.TestData.createPullRequest) Changeset(sonia.scm.repository.Changeset)

Example 7 with Changeset

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

the class PullRequestRootResourceTest method shouldReturnPullRequestIsValidResult.

@Test
@SubjectAware(username = "dent")
public void shouldReturnPullRequestIsValidResult() 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=feature&target=master");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).contains("\"status\":\"PR_VALID\"");
    assertThat(response.getContentAsString()).contains("\"_links\":{\"self\":{\"href\":\"/v2/pull-requests/ns/repo/check?source=feature&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 8 with Changeset

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

the class MergeServiceTest method shouldNotEnrichCommitMessageWithMergerAsCoAuthor.

@Test
void shouldNotEnrichCommitMessageWithMergerAsCoAuthor() 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("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("Arthur Dent");
    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: 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 Changeset

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

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

the class ModificationCollectorTest method shouldCloseRepositorySerice.

@Test
void shouldCloseRepositorySerice() throws IOException {
    Changeset one = changeset("21").added("a.txt").removed("b.txt").build();
    collector.collect(repository, ImmutableList.of(one));
    verify(repositoryService).close();
}
Also used : Changeset(sonia.scm.repository.Changeset) 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