Search in sources :

Example 21 with NamespaceAndName

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

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

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

Example 24 with NamespaceAndName

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

the class RepositoryConfigResource method getRepositoryConfig.

@GET
@Path("{namespace}/{name}/config")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Repository pull request configuration", description = "Returns the repository-specific pull request configuration.", tags = "Pull Request Configuration", operationId = "review_get_repo_config")
@ApiResponse(responseCode = "200", description = "success", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = PullRequestConfigDto.class)))
@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 PullRequestConfigDto getRepositoryConfig(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name) {
    Repository repository = repositoryManager.get(new NamespaceAndName(namespace, name));
    if (repository == null) {
        throw notFound(entity(new NamespaceAndName(namespace, name)));
    }
    PermissionCheck.checkConfigure(repository);
    return repositoryConfigMapper.map(configService.getRepositoryPullRequestConfig(repository), repository, uriInfo);
}
Also used : Repository(sonia.scm.repository.Repository) NamespaceAndName(sonia.scm.repository.NamespaceAndName) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 25 with NamespaceAndName

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

the class MergeResource method emergencyMerge.

@POST
@Path("{namespace}/{name}/{pullRequestId}/emergency")
@Consumes(PullRequestMediaType.MERGE_COMMAND)
@Operation(summary = "Merge pull request", description = "Merges pull request with selected strategy as emergency merge.", tags = "Pull Request")
@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 \"performEmergencyMerge\" privilege")
@ApiResponse(responseCode = "404", description = "not found, no pull request with the specified id is available")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public void emergencyMerge(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId, @QueryParam("strategy") MergeStrategy strategy, @NotNull @Valid MergeCommitDto mergeCommitDto) {
    NamespaceAndName namespaceAndName = new NamespaceAndName(namespace, name);
    service.merge(namespaceAndName, pullRequestId, mergeCommitDto, strategy, true);
}
Also used : NamespaceAndName(sonia.scm.repository.NamespaceAndName) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Operation(io.swagger.v3.oas.annotations.Operation) 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