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");
}
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())));
}
}
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())));
}
}
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));
}
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();
}
Aggregations