Search in sources :

Example 41 with PullRequest

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

the class CommentService method delete.

public void delete(String namespace, String name, String pullRequestId, String commentId) {
    Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
    PullRequest pullRequest = pullRequestService.get(repository, pullRequestId);
    findRootComment(repository, pullRequestId, commentId).ifPresent(rootComment -> {
        PermissionCheck.checkModifyComment(repository, rootComment);
        doThrow().violation("Must not delete system comment").when(rootComment.isSystemComment());
        doThrow().violation("Must not delete root comment with existing replies").when(!rootComment.getReplies().isEmpty());
        getCommentStore(repository).delete(pullRequestId, commentId);
        eventBus.post(new CommentEvent(repository, pullRequest, null, rootComment, HandlerEventType.DELETE));
    });
    findReplyWithParent(repository, pullRequestId, commentId).ifPresent(replyWithParent -> replyWithParent.execute((parent, reply) -> {
        PermissionCheck.checkModifyComment(repository, reply);
        doThrow().violation("Must not delete system reply").when(reply.isSystemReply());
        parent.removeReply(reply);
        getCommentStore(repository).update(pullRequestId, parent);
        eventBus.post(new ReplyEvent(repository, pullRequest, null, reply, parent, HandlerEventType.DELETE));
    }));
}
Also used : EagerSingleton(sonia.scm.EagerSingleton) PullRequestEmergencyMergedEvent(com.cloudogu.scm.review.pullrequest.service.PullRequestEmergencyMergedEvent) ScmEventBus(sonia.scm.event.ScmEventBus) KeyGenerator(sonia.scm.security.KeyGenerator) NotFoundException.notFound(sonia.scm.NotFoundException.notFound) Subscribe(com.github.legman.Subscribe) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Inject(javax.inject.Inject) HandlerEventType(sonia.scm.HandlerEventType) MAKE_TASK(com.cloudogu.scm.review.comment.service.CommentTransition.MAKE_TASK) Collections.singleton(java.util.Collections.singleton) ContextBuilder.entity(sonia.scm.ContextEntry.ContextBuilder.entity) Arrays.asList(java.util.Arrays.asList) BiConsumer(java.util.function.BiConsumer) PermissionCheck(com.cloudogu.scm.review.PermissionCheck) PullRequestService(com.cloudogu.scm.review.pullrequest.service.PullRequestService) PullRequestMergedEvent(com.cloudogu.scm.review.pullrequest.service.PullRequestMergedEvent) NotFoundException(sonia.scm.NotFoundException) RepositoryResolver(com.cloudogu.scm.review.RepositoryResolver) Builder.doThrow(sonia.scm.ScmConstraintViolationException.Builder.doThrow) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Extension(sonia.scm.plugin.Extension) MentionMapper(com.cloudogu.scm.review.comment.api.MentionMapper) PullRequestRejectedEvent(com.cloudogu.scm.review.pullrequest.service.PullRequestRejectedEvent) List(java.util.List) Stream(java.util.stream.Stream) CHANGE_TEXT(com.cloudogu.scm.review.comment.service.TextTransition.CHANGE_TEXT) SET_DONE(com.cloudogu.scm.review.comment.service.CommentTransition.SET_DONE) Optional(java.util.Optional) REOPEN(com.cloudogu.scm.review.comment.service.CommentTransition.REOPEN) SecurityUtils(org.apache.shiro.SecurityUtils) NamespaceAndName(sonia.scm.repository.NamespaceAndName) MAKE_COMMENT(com.cloudogu.scm.review.comment.service.CommentTransition.MAKE_COMMENT) Repository(sonia.scm.repository.Repository) NamespaceAndName(sonia.scm.repository.NamespaceAndName) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest)

Example 42 with PullRequest

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

the class CommentService method addWithoutPermissionCheck.

private String addWithoutPermissionCheck(Repository repository, String pullRequestId, Comment pullRequestComment) {
    PullRequest pullRequest = pullRequestService.get(repository, pullRequestId);
    initializeNewComment(pullRequestComment, pullRequest, repository.getId());
    String newId = getCommentStore(repository).add(pullRequestId, pullRequestComment);
    fireMentionEventIfMentionsExist(repository, pullRequest, pullRequestComment);
    eventBus.post(new CommentEvent(repository, pullRequest, pullRequestComment, null, HandlerEventType.CREATE));
    return newId;
}
Also used : PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest)

Example 43 with PullRequest

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

the class BasicPRMailTextResolver method getMailSubject.

protected String getMailSubject(E event, String displayEventNameKey, Locale locale) {
    Repository repository = event.getRepository();
    PullRequest pullRequest = event.getPullRequest();
    String displayEventName = SUBJECT_BUNDLES.get(locale).getString(displayEventNameKey);
    return MessageFormat.format(SUBJECT_PATTERN, repository.getNamespace(), repository.getName(), displayEventName, pullRequest.getId(), pullRequest.getTitle());
}
Also used : Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest)

Example 44 with PullRequest

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

the class BasicPRMailTextResolver method getPullRequestLink.

private String getPullRequestLink(String baseUrl, E event) {
    Repository repository = event.getRepository();
    PullRequest pullRequest = event.getPullRequest();
    return MessageFormat.format(SCM_PULL_REQUEST_URL_PATTERN, baseUrl, repository.getNamespace(), repository.getName(), pullRequest.getId());
}
Also used : Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest)

Example 45 with PullRequest

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

the class EmailNotificationHook method handleUpdatedPullRequest.

@Subscribe
public void handleUpdatedPullRequest(PullRequestUpdatedEvent event) {
    PullRequest pullRequest = event.getPullRequest();
    handleEvent(event, new PullRequestUpdatedMailTextResolver(event), pullRequest, getSubscribersWithoutCurrentUser(pullRequest));
}
Also used : PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Subscribe(com.github.legman.Subscribe)

Aggregations

PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)82 Repository (sonia.scm.repository.Repository)27 Test (org.junit.jupiter.api.Test)20 Test (org.junit.Test)18 TestData.createPullRequest (com.cloudogu.scm.review.TestData.createPullRequest)17 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)16 Subscribe (com.github.legman.Subscribe)13 SubjectAware (com.github.sdorra.shiro.SubjectAware)13 NamespaceAndName (sonia.scm.repository.NamespaceAndName)13 User (sonia.scm.user.User)11 DisplayUser (sonia.scm.user.DisplayUser)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 Optional (java.util.Optional)7 Comment (com.cloudogu.scm.review.comment.service.Comment)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 PermissionCheck (com.cloudogu.scm.review.PermissionCheck)5 PullRequestService (com.cloudogu.scm.review.pullrequest.service.PullRequestService)5 Operation (io.swagger.v3.oas.annotations.Operation)5 List (java.util.List)5