Search in sources :

Example 1 with Changeset

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

the class MergeService method extractCoAuthorsFromSquashedCommitMessages.

private void extractCoAuthorsFromSquashedCommitMessages(List<Changeset> changesets, String author, Set<String> appendedCoAuthors, StringBuilder builder) {
    Pattern delimiter = Pattern.compile("[\\n]");
    for (Changeset changeset : changesets) {
        if (changeset.getDescription() != null) {
            try (Scanner scanner = new Scanner(changeset.getDescription())) {
                scanner.useDelimiter(delimiter);
                while (scanner.hasNext()) {
                    String line = scanner.next();
                    if (shouldExtractLineFromSquashedCommit(appendedCoAuthors, line, author)) {
                        appendedCoAuthors.add(line);
                        builder.append(line).append("\n");
                    }
                }
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Scanner(java.util.Scanner) Changeset(sonia.scm.repository.Changeset)

Example 2 with Changeset

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

the class ModificationCollectorTest method shouldCollectModification.

@Test
void shouldCollectModification() throws IOException {
    Changeset one = changeset("21").added("a.txt").removed("b.txt").build();
    Changeset two = changeset("42").modified("c.txt", "d.txt").build();
    Set<String> modifications = collector.collect(repository, ImmutableList.of(one, two));
    assertThat(modifications).containsExactlyInAnyOrder("a.txt", "b.txt", "c.txt", "d.txt");
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Changeset(sonia.scm.repository.Changeset) Test(org.junit.jupiter.api.Test)

Example 3 with Changeset

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

the class ProcessChangedFilesHookTest method prepareEvent.

private PostReceiveRepositoryHookEvent prepareEvent(Comment... comments) {
    lenient().when(commentCollector.collectNonOutdated(repository, pullRequest)).thenReturn(Stream.of(comments));
    List<String> branches = ImmutableList.of(pullRequest.getSource(), pullRequest.getTarget());
    PostReceiveRepositoryHookEvent event = createRepositoryHookEvent(branches);
    lenient().when(pullRequestCollector.collectAffectedPullRequests(repository, branches)).thenReturn(ImmutableList.of(pullRequest));
    List<Changeset> changesets = ImmutableList.of(new Changeset(), new Changeset());
    lenient().when(event.getContext().getChangesetProvider().getChangesets()).thenReturn(changesets);
    return event;
}
Also used : Changeset(sonia.scm.repository.Changeset) PostReceiveRepositoryHookEvent(sonia.scm.repository.PostReceiveRepositoryHookEvent)

Example 4 with Changeset

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

the class BranchRevisionResolverTest method mockSingleChangeset.

private void mockSingleChangeset(String branch) throws IOException {
    when(repositoryService.getLogCommand()).thenReturn(logCommandBuilder);
    LogCommandBuilder subLogCommandBuilder = mock(LogCommandBuilder.class);
    lenient().when(logCommandBuilder.setBranch(branch)).thenReturn(subLogCommandBuilder);
    lenient().when(subLogCommandBuilder.setPagingStart(0)).thenReturn(subLogCommandBuilder);
    lenient().when(subLogCommandBuilder.setPagingLimit(1)).thenReturn(subLogCommandBuilder);
    Changeset changeset = new Changeset();
    changeset.setId(branch + "Id");
    lenient().when(subLogCommandBuilder.getChangesets()).thenReturn(new ChangesetPagingResult(1, singletonList(changeset)));
}
Also used : ChangesetPagingResult(sonia.scm.repository.ChangesetPagingResult) LogCommandBuilder(sonia.scm.repository.api.LogCommandBuilder) Changeset(sonia.scm.repository.Changeset)

Example 5 with Changeset

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

the class PullRequestRootResourceTest method shouldCreateNewValidPullRequest.

@Test
@SubjectAware(username = "slarti")
public void shouldCreateNewValidPullRequest() throws URISyntaxException, IOException {
    mockPrincipal();
    mockChangesets("sourceBranch", "targetBranch", new Changeset());
    byte[] pullRequestJson = loadJson("com/cloudogu/scm/review/pullRequest.json");
    MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name").content(pullRequestJson).contentType(PullRequestMediaType.PULL_REQUEST);
    dispatcher.invoke(request, response);
    assertEquals(HttpServletResponse.SC_CREATED, response.getStatus());
    assertThat(response.getOutputHeaders().getFirst("Location")).hasToString("/v2/pull-requests/space/name/1");
    PullRequest pullRequest = pullRequestStoreCaptor.getValue();
    assertThat(pullRequest.getAuthor()).isEqualTo("user1");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) 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)

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