Search in sources :

Example 6 with Location

use of com.cloudogu.scm.review.comment.service.Location in project scm-review-plugin by scm-manager.

the class CommentLocationUpdateStepTest method shouldUpdateLocation.

@Test
void shouldUpdateLocation(@TempDir Path temp) throws Exception {
    Path store = createStore(temp);
    doAnswer(ic -> {
        BiConsumer<String, Path> consumer = ic.getArgument(0);
        consumer.accept("repo", temp);
        return null;
    }).when(resolverInstance).forAllLocations(any());
    Path one = copyResource(store, "1");
    Path two = copyResource(store, "2");
    updateStep.doUpdate();
    PullRequestComments commentsOfOne = JAXB.unmarshal(one.toFile(), PullRequestComments.class);
    assertThat(commentsOfOne.getComments()).hasSize(4).extracting(Comment::getLocation).containsOnly(null, null, new Location("README.md", "@@ -1,3 +1,41 @@", null, 25), new Location("README.md", "@@ -1,3 +1,41 @@", null, 39));
    PullRequestComments commentsOfTwo = JAXB.unmarshal(two.toFile(), PullRequestComments.class);
    assertThat(commentsOfTwo.getComments()).hasSize(3).extracting(Comment::getLocation).containsOnly(new Location("README.md", "@@ -1,3 +1,41 @@", null, 39), new Location("README.md", "@@ -1,3 +1,41 @@", 39, null), new Location("README.md", "@@ -1,3 +1,41 @@", 39, 39));
}
Also used : Path(java.nio.file.Path) PullRequestComments(com.cloudogu.scm.review.comment.service.PullRequestComments) Location(com.cloudogu.scm.review.comment.service.Location) Test(org.junit.jupiter.api.Test)

Example 7 with Location

use of com.cloudogu.scm.review.comment.service.Location in project scm-review-plugin by scm-manager.

the class RemoveReviewMarksOnChangedCommentsHook method checkForLocation.

private <C extends BasicComment, T extends BasicCommentEvent<C>> void checkForLocation(T event, Function<C, Location> locationExtractor) {
    if (event.getEventType() == HandlerEventType.DELETE) {
        return;
    }
    Location location = locationExtractor.apply(event.getItem());
    if (location == null) {
        return;
    }
    Collection<ReviewMark> reviewMarksToBeRemoved = event.getPullRequest().getReviewMarks().stream().filter(mark -> mark.getFile().equals(location.getFile())).collect(Collectors.toList());
    pullRequestService.removeReviewMarks(event.getRepository(), event.getPullRequest().getId(), reviewMarksToBeRemoved);
}
Also used : EagerSingleton(sonia.scm.EagerSingleton) Collection(java.util.Collection) BasicComment(com.cloudogu.scm.review.comment.service.BasicComment) Subscribe(com.github.legman.Subscribe) Extension(sonia.scm.plugin.Extension) ReplyEvent(com.cloudogu.scm.review.comment.service.ReplyEvent) Repository(sonia.scm.repository.Repository) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) BasicCommentEvent(com.cloudogu.scm.review.comment.service.BasicCommentEvent) CommentEvent(com.cloudogu.scm.review.comment.service.CommentEvent) Inject(javax.inject.Inject) Objects(java.util.Objects) HandlerEventType(sonia.scm.HandlerEventType) Reply(com.cloudogu.scm.review.comment.service.Reply) Comment(com.cloudogu.scm.review.comment.service.Comment) CommentService(com.cloudogu.scm.review.comment.service.CommentService) Location(com.cloudogu.scm.review.comment.service.Location) Location(com.cloudogu.scm.review.comment.service.Location)

Example 8 with Location

use of com.cloudogu.scm.review.comment.service.Location in project scm-review-plugin by scm-manager.

the class MentionMapperTest method shouldParseUserIdsToDisplayNames.

@Test
void shouldParseUserIdsToDisplayNames() {
    setupExistingUserMock("dent", "Arthur Dent", "dent@hitchhiker.org");
    setupExistingUserMock("_anonymous", "SCM Anonymous", "anonymous@hitchhiker.org");
    BasicComment unparsedComment = Comment.createComment("1", "new comment @[dent] @[_anonymous]", "author", new Location());
    unparsedComment.setMentionUserIds(ImmutableSet.of("dent", "_anonymous"));
    BasicComment parsedComment = mentionMapper.parseMentionsUserIdsToDisplayNames(unparsedComment);
    assertThat(parsedComment.getComment()).isEqualTo("new comment @Arthur Dent @SCM Anonymous");
}
Also used : BasicComment(com.cloudogu.scm.review.comment.service.BasicComment) Location(com.cloudogu.scm.review.comment.service.Location) Test(org.junit.jupiter.api.Test)

Example 9 with Location

use of com.cloudogu.scm.review.comment.service.Location in project scm-review-plugin by scm-manager.

the class RemoveReviewMarksOnChangedCommentsHookTest method shouldNotRemoveMarksOnNewCommentWithDifferentLocation.

@Test
void shouldNotRemoveMarksOnNewCommentWithDifferentLocation() {
    comment.setLocation(new Location("some/other/file"));
    pullRequest.setReviewMarks(of(new ReviewMark("some/file", "dent")));
    CommentEvent event = new CommentEvent(repository, pullRequest, comment, null, HandlerEventType.CREATE);
    hook.handleCommentEvents(event);
    verify(pullRequestService, atMost(1)).removeReviewMarks(repository, pullRequest.getId(), emptyList());
}
Also used : CommentEvent(com.cloudogu.scm.review.comment.service.CommentEvent) Location(com.cloudogu.scm.review.comment.service.Location) Test(org.junit.jupiter.api.Test)

Example 10 with Location

use of com.cloudogu.scm.review.comment.service.Location in project scm-review-plugin by scm-manager.

the class RemoveReviewMarksOnChangedCommentsHookTest method shouldRemoveMarksOnNewCommentWithSameLocation.

@Test
void shouldRemoveMarksOnNewCommentWithSameLocation() {
    comment.setLocation(new Location("some/file"));
    pullRequest.setReviewMarks(of(new ReviewMark("some/file", "dent")));
    CommentEvent event = new CommentEvent(repository, pullRequest, comment, null, HandlerEventType.CREATE);
    hook.handleCommentEvents(event);
    verify(pullRequestService).removeReviewMarks(repository, pullRequest.getId(), singletonList(new ReviewMark("some/file", "dent")));
}
Also used : CommentEvent(com.cloudogu.scm.review.comment.service.CommentEvent) Location(com.cloudogu.scm.review.comment.service.Location) Test(org.junit.jupiter.api.Test)

Aggregations

Location (com.cloudogu.scm.review.comment.service.Location)10 Comment (com.cloudogu.scm.review.comment.service.Comment)5 Reply (com.cloudogu.scm.review.comment.service.Reply)5 Test (org.junit.jupiter.api.Test)5 Comment.createComment (com.cloudogu.scm.review.comment.service.Comment.createComment)3 CommentEvent (com.cloudogu.scm.review.comment.service.CommentEvent)3 CommentService (com.cloudogu.scm.review.comment.service.CommentService)3 UriBuilder (javax.ws.rs.core.UriBuilder)3 Repository (sonia.scm.repository.Repository)3 RepositoryResolver (com.cloudogu.scm.review.RepositoryResolver)2 BasicComment (com.cloudogu.scm.review.comment.service.BasicComment)2 InlineContext (com.cloudogu.scm.review.comment.service.InlineContext)2 Reply.createReply (com.cloudogu.scm.review.comment.service.Reply.createReply)2 PullRequestResource (com.cloudogu.scm.review.pullrequest.api.PullRequestResource)2 PullRequestRootResource (com.cloudogu.scm.review.pullrequest.api.PullRequestRootResource)2 BranchRevisionResolver (com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver)2 PullRequestMapperImpl (com.cloudogu.scm.review.pullrequest.dto.PullRequestMapperImpl)2 PullRequestService (com.cloudogu.scm.review.pullrequest.service.PullRequestService)2 Providers (com.google.inject.util.Providers)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2