Search in sources :

Example 6 with Repository

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

the class CommentIndexer method handleEvent.

@Subscribe
public void handleEvent(ReplyEvent event) {
    Reply comment = event.getItem();
    PullRequest pullRequest = event.getPullRequest();
    Repository repository = event.getRepository();
    if (event.getEventType() == HandlerEventType.CREATE || event.getEventType() == HandlerEventType.MODIFY) {
        updateIndexedComment(repository, pullRequest, IndexedComment.transform(pullRequest.getId(), comment));
    } else if (event.getEventType() == HandlerEventType.DELETE) {
        Reply deletedReply = event.getOldItem();
        searchEngine.forType(IndexedComment.class).update(index -> index.delete().byId(createCommentId(deletedReply.getId(), pullRequest.getId(), repository.getId())));
    }
}
Also used : Index(sonia.scm.search.Index) RepositoryImportEvent(sonia.scm.repository.RepositoryImportEvent) RepositoryPermissions(sonia.scm.repository.RepositoryPermissions) IndexLog(sonia.scm.search.IndexLog) Subscribe(com.github.legman.Subscribe) Extension(sonia.scm.plugin.Extension) IndexTask(sonia.scm.search.IndexTask) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Inject(javax.inject.Inject) HandlerEventType(sonia.scm.HandlerEventType) SearchEngine(sonia.scm.search.SearchEngine) RepositoryManager(sonia.scm.repository.RepositoryManager) ServletContextEvent(javax.servlet.ServletContextEvent) SerializableIndexTask(sonia.scm.search.SerializableIndexTask) Optional(java.util.Optional) PermissionCheck(com.cloudogu.scm.review.PermissionCheck) PullRequestService(com.cloudogu.scm.review.pullrequest.service.PullRequestService) Id(sonia.scm.search.Id) IndexLogStore(sonia.scm.search.IndexLogStore) ServletContextListener(javax.servlet.ServletContextListener) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Subscribe(com.github.legman.Subscribe)

Example 7 with Repository

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

the class CommentService method modifyComment.

public void modifyComment(String namespace, String name, String pullRequestId, String commentId, Comment changedComment) {
    Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
    PullRequest pullRequest = pullRequestService.get(repository, pullRequestId);
    Comment rootComment = findRootComment(repository, pullRequestId, commentId).<NotFoundException>orElseThrow(() -> {
        throw notFound(entity(BasicComment.class, String.valueOf(changedComment.getId())).in(PullRequest.class, pullRequestId).in(repository.getNamespaceAndName()));
    });
    PermissionCheck.checkModifyComment(repository, rootComment);
    Comment clone = rootComment.clone();
    rootComment.setComment(changedComment.getComment());
    handleMentions(repository, pullRequest, rootComment, clone);
    rootComment.addTransition(new ExecutedTransition<>(keyGenerator.createKey(), CHANGE_TEXT, System.currentTimeMillis(), getCurrentUserId()));
    getCommentStore(repository).update(pullRequestId, rootComment);
    eventBus.post(new CommentEvent(repository, pullRequest, rootComment, clone, HandlerEventType.MODIFY));
}
Also used : Repository(sonia.scm.repository.Repository) NamespaceAndName(sonia.scm.repository.NamespaceAndName) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) NotFoundException(sonia.scm.NotFoundException)

Example 8 with Repository

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

the class CommentService method add.

public String add(String namespace, String name, String pullRequestId, Comment pullRequestComment) {
    Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
    PermissionCheck.checkComment(repository);
    return addWithoutPermissionCheck(repository, pullRequestId, pullRequestComment);
}
Also used : Repository(sonia.scm.repository.Repository) NamespaceAndName(sonia.scm.repository.NamespaceAndName)

Example 9 with Repository

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

the class CommentService method markAsOutdated.

public void markAsOutdated(String namespace, String name, String pullRequestId, String commentId) {
    Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
    Comment rootComment = findRootComment(repository, pullRequestId, commentId).<NotFoundException>orElseThrow(() -> {
        throw notFound(entity(BasicComment.class, commentId).in(PullRequest.class, pullRequestId).in(repository.getNamespaceAndName()));
    });
    if (!rootComment.isOutdated()) {
        rootComment.setOutdated(true);
        getCommentStore(repository).update(pullRequestId, rootComment);
    }
}
Also used : Repository(sonia.scm.repository.Repository) NamespaceAndName(sonia.scm.repository.NamespaceAndName) NotFoundException(sonia.scm.NotFoundException)

Example 10 with Repository

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

the class CommentService method reply.

public String reply(String namespace, String name, String pullRequestId, String rootCommentId, Reply reply) {
    Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
    PermissionCheck.checkComment(repository);
    PullRequest pullRequest = pullRequestService.get(repository, pullRequestId);
    Comment originalRootComment = get(repository, pullRequestId, rootCommentId);
    reply.setId(keyGenerator.createKey());
    initializeNewComment(reply, pullRequest, repository.getId());
    originalRootComment.addReply(reply);
    getCommentStore(repository).update(pullRequestId, originalRootComment);
    fireMentionEventIfMentionsExist(repository, pullRequest, reply);
    eventBus.post(new ReplyEvent(repository, pullRequest, reply, null, originalRootComment, HandlerEventType.CREATE));
    return reply.getId();
}
Also used : Repository(sonia.scm.repository.Repository) NamespaceAndName(sonia.scm.repository.NamespaceAndName) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest)

Aggregations

Repository (sonia.scm.repository.Repository)66 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)25 Operation (io.swagger.v3.oas.annotations.Operation)20 Path (javax.ws.rs.Path)20 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)19 NamespaceAndName (sonia.scm.repository.NamespaceAndName)16 GET (javax.ws.rs.GET)11 Produces (javax.ws.rs.Produces)11 Test (org.junit.jupiter.api.Test)9 Subscribe (com.github.legman.Subscribe)6 SubjectAware (com.github.sdorra.shiro.SubjectAware)6 Consumes (javax.ws.rs.Consumes)6 POST (javax.ws.rs.POST)6 Test (org.junit.Test)6 HalEnricherContext (sonia.scm.api.v2.resources.HalEnricherContext)6 PermissionCheck (com.cloudogu.scm.review.PermissionCheck)5 PullRequestResourceLinks (com.cloudogu.scm.review.PullRequestResourceLinks)5 Comment (com.cloudogu.scm.review.comment.service.Comment)5 PullRequestService (com.cloudogu.scm.review.pullrequest.service.PullRequestService)5 Inject (javax.inject.Inject)5