Search in sources :

Example 31 with Repository

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

the class StatusCheckHook method checkStatus.

@Subscribe(async = false)
public void checkStatus(PostReceiveRepositoryHookEvent event) {
    Repository repository = event.getRepository();
    if (ignoreHook(event.getContext(), repository)) {
        return;
    }
    List<PullRequest> pullRequests = pullRequestService.getAll(repository.getNamespace(), repository.getName());
    new Worker(event).process(pullRequests);
}
Also used : Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Subscribe(com.github.legman.Subscribe)

Example 32 with Repository

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

the class CommentResource method getComment.

@GET
@Path("")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(PullRequestMediaType.PULL_REQUEST)
@Operation(summary = "Pull request comment", description = "Returns a single pull request comment.", tags = "Pull Request Comment")
@ApiResponse(responseCode = "200", description = "success", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = CommentDto.class)))
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"commentPullRequest\" privilege")
@ApiResponse(responseCode = "404", description = "not found, a comment with the given id is not available for this pull request")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public CommentDto getComment(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId, @PathParam("commentId") String commentId, @QueryParam("sourceRevision") String expectedSourceRevision, @QueryParam("targetRevision") String expectedTargetRevision) {
    checkRevision(branchRevisionResolver, namespace, name, pullRequestId, expectedSourceRevision, expectedTargetRevision);
    Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
    BranchRevisionResolver.RevisionResult revisions = branchRevisionResolver.getRevisions(namespace, name, pullRequestId);
    Comment comment = service.get(namespace, name, pullRequestId, commentId);
    Collection<CommentTransition> possibleTransitions = service.possibleTransitions(namespace, name, pullRequestId, comment.getId());
    return commentMapper.map(comment, repository, pullRequestId, possibleTransitions, revisions);
}
Also used : CommentTransition(com.cloudogu.scm.review.comment.service.CommentTransition) Comment(com.cloudogu.scm.review.comment.service.Comment) Repository(sonia.scm.repository.Repository) NamespaceAndName(sonia.scm.repository.NamespaceAndName) BranchRevisionResolver(com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 33 with Repository

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

the class CommentService method possibleTransitions.

public Collection<CommentTransition> possibleTransitions(String namespace, String name, String pullRequestId, String commentId) {
    Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
    if (!PermissionCheck.mayComment(repository)) {
        return emptyList();
    }
    Comment comment = get(namespace, name, pullRequestId, commentId);
    switch(comment.getType()) {
        case COMMENT:
            return singleton(MAKE_TASK);
        case TASK_TODO:
            return asList(SET_DONE, MAKE_COMMENT);
        case TASK_DONE:
            return asList(REOPEN, MAKE_COMMENT);
        default:
            throw new IllegalStateException("unknown type in comment: " + comment.getType());
    }
}
Also used : Repository(sonia.scm.repository.Repository) NamespaceAndName(sonia.scm.repository.NamespaceAndName)

Example 34 with Repository

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

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

the class CommentService method getAll.

public List<Comment> getAll(String namespace, String name, String pullRequestId) {
    Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
    PermissionCheck.checkRead(repository);
    return getCommentStore(repository).getAll(pullRequestId);
}
Also used : Repository(sonia.scm.repository.Repository) NamespaceAndName(sonia.scm.repository.NamespaceAndName)

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