Search in sources :

Example 1 with PullRequest

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

the class CommentRootResource method getAll.

@GET
@Path("")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Get all pull request comments", description = "Returns all pull request comments.", tags = "Pull Request Comment", operationId = "review_get_comments")
@ApiResponse(responseCode = "200", description = "success", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = HalRepresentation.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 = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public HalRepresentation getAll(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId) {
    PullRequestResourceLinks resourceLinks = new PullRequestResourceLinks(uriInfo::getBaseUri);
    Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
    PullRequest pullRequest = pullRequestService.get(namespace, name, pullRequestId);
    BranchRevisionResolver.RevisionResult revisions = branchRevisionResolver.getRevisions(new NamespaceAndName(namespace, name), pullRequest);
    List<Comment> list = service.getAll(namespace, name, pullRequestId);
    List<CommentDto> dtoList = list.stream().map(comment -> mapper.map(comment, repository, pullRequestId, service.possibleTransitions(namespace, name, pullRequestId, comment.getId()), revisions)).collect(Collectors.toList());
    boolean permission = PermissionCheck.mayComment(repository);
    return createCollection(permission, resourceLinks.pullRequestComments().all(namespace, name, pullRequestId), resourceLinks.pullRequestComments().create(namespace, name, pullRequestId, revisions), dtoList, "pullRequestComments");
}
Also used : PullRequestMediaType(com.cloudogu.scm.review.PullRequestMediaType) PathParam(javax.ws.rs.PathParam) Provider(javax.inject.Provider) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) BranchRevisionResolver(com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Inject(javax.inject.Inject) Valid(javax.validation.Valid) Content(io.swagger.v3.oas.annotations.media.Content) Operation(io.swagger.v3.oas.annotations.Operation) MediaType(javax.ws.rs.core.MediaType) VndMediaType(sonia.scm.web.VndMediaType) QueryParam(javax.ws.rs.QueryParam) HalRepresentation(de.otto.edison.hal.HalRepresentation) Consumes(javax.ws.rs.Consumes) Comment(com.cloudogu.scm.review.comment.service.Comment) ErrorDto(sonia.scm.api.v2.resources.ErrorDto) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) PermissionCheck(com.cloudogu.scm.review.PermissionCheck) PullRequestService(com.cloudogu.scm.review.pullrequest.service.PullRequestService) URI(java.net.URI) Schema(io.swagger.v3.oas.annotations.media.Schema) RepositoryResolver(com.cloudogu.scm.review.RepositoryResolver) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) HalRepresentations.createCollection(com.cloudogu.scm.review.HalRepresentations.createCollection) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) AuthorizationException(org.apache.shiro.authz.AuthorizationException) List(java.util.List) Response(javax.ws.rs.core.Response) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) CommentService(com.cloudogu.scm.review.comment.service.CommentService) RevisionChecker.checkRevision(com.cloudogu.scm.review.comment.api.RevisionChecker.checkRevision) UriInfo(javax.ws.rs.core.UriInfo) NamespaceAndName(sonia.scm.repository.NamespaceAndName) Comment(com.cloudogu.scm.review.comment.service.Comment) NamespaceAndName(sonia.scm.repository.NamespaceAndName) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) BranchRevisionResolver(com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver) Repository(sonia.scm.repository.Repository) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) 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 2 with PullRequest

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

the class CommentIndexer method handleEvent.

@Subscribe
public void handleEvent(CommentEvent event) {
    Comment 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) {
        Comment deletedComment = event.getOldItem();
        searchEngine.forType(IndexedComment.class).update(index -> index.delete().byId(createCommentId(deletedComment.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 3 with PullRequest

use of com.cloudogu.scm.review.pullrequest.service.PullRequest 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 4 with PullRequest

use of com.cloudogu.scm.review.pullrequest.service.PullRequest 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 5 with PullRequest

use of com.cloudogu.scm.review.pullrequest.service.PullRequest 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

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