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