Search in sources :

Example 6 with NamespaceAndName

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

use of sonia.scm.repository.NamespaceAndName 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)

Example 8 with NamespaceAndName

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

the class CommentService method modifyReply.

public void modifyReply(String namespace, String name, String pullRequestId, String replyId, Reply changedReply) {
    Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
    PullRequest pullRequest = pullRequestService.get(repository, pullRequestId);
    findReplyWithParent(repository, pullRequestId, replyId).<NotFoundException>orElseThrow(() -> {
        throw notFound(entity(Reply.class, String.valueOf(changedReply.getId())).in(PullRequest.class, pullRequestId).in(repository.getNamespaceAndName()));
    }).execute((parent, reply) -> {
        PermissionCheck.checkModifyComment(repository, reply);
        Reply clone = reply.clone();
        reply.setComment(changedReply.getComment());
        reply.addTransition(new ExecutedTransition<>(keyGenerator.createKey(), CHANGE_TEXT, System.currentTimeMillis(), getCurrentUserId()));
        handleMentions(repository, pullRequest, reply, clone);
        getCommentStore(repository).update(pullRequestId, parent);
        eventBus.post(new ReplyEvent(repository, pullRequest, reply, clone, parent, HandlerEventType.MODIFY));
    });
}
Also used : Repository(sonia.scm.repository.Repository) NamespaceAndName(sonia.scm.repository.NamespaceAndName) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest)

Example 9 with NamespaceAndName

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

the class CommentService method transform.

public ExecutedTransition<CommentTransition> transform(String namespace, String name, String pullRequestId, String commentId, CommentTransition transition) {
    Comment comment = get(namespace, name, pullRequestId, commentId);
    Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
    PullRequest pullRequest = pullRequestService.get(repository, pullRequestId);
    Comment clone = comment.clone();
    transition.accept(clone);
    ExecutedTransition<CommentTransition> executedTransition = new ExecutedTransition<>(keyGenerator.createKey(), transition, System.currentTimeMillis(), getCurrentUserId());
    clone.addCommentTransition(executedTransition);
    getCommentStore(repository).update(pullRequestId, clone);
    eventBus.post(new CommentEvent(repository, pullRequest, comment, clone, HandlerEventType.MODIFY));
    return executedTransition;
}
Also used : Repository(sonia.scm.repository.Repository) NamespaceAndName(sonia.scm.repository.NamespaceAndName) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest)

Example 10 with NamespaceAndName

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

the class RepositoryConfigResource method setRepositoryConfig.

@PUT
@Path("{namespace}/{name}/config")
@Consumes(MediaType.APPLICATION_JSON)
@Operation(summary = "Update Repository pull request configuration", description = "Modifies the repository-specific pull request configuration.", tags = "Pull Request Configuration", operationId = "review_put_repo_config")
@ApiResponse(responseCode = "204", description = "update success")
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"configurePullRequest\" privilege")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public void setRepositoryConfig(@PathParam("namespace") String namespace, @PathParam("name") String name, @Valid PullRequestConfigDto configDto) {
    Repository repository = repositoryManager.get(new NamespaceAndName(namespace, name));
    if (repository == null) {
        throw notFound(entity(new NamespaceAndName(namespace, name)));
    }
    PermissionCheck.checkConfigure(repository);
    configService.setRepositoryPullRequestConfig(repository, repositoryConfigMapper.map(configDto));
}
Also used : Repository(sonia.scm.repository.Repository) NamespaceAndName(sonia.scm.repository.NamespaceAndName) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Operation(io.swagger.v3.oas.annotations.Operation) PUT(javax.ws.rs.PUT) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Aggregations

NamespaceAndName (sonia.scm.repository.NamespaceAndName)35 Repository (sonia.scm.repository.Repository)15 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)11 Operation (io.swagger.v3.oas.annotations.Operation)10 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)10 Path (javax.ws.rs.Path)10 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)8 Test (org.junit.jupiter.api.Test)8 Produces (javax.ws.rs.Produces)7 MergeCommitDto (com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto)6 SubjectAware (com.github.sdorra.shiro.SubjectAware)6 GET (javax.ws.rs.GET)6 Comment (com.cloudogu.scm.review.comment.service.Comment)5 Consumes (javax.ws.rs.Consumes)5 Test (org.junit.Test)5 TestData.createPullRequest (com.cloudogu.scm.review.TestData.createPullRequest)4 BranchRevisionResolver (com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver)3 POST (javax.ws.rs.POST)3 NotFoundException (sonia.scm.NotFoundException)3 PermissionCheck (com.cloudogu.scm.review.PermissionCheck)2