use of com.cloudogu.scm.review.pullrequest.service.PullRequest in project scm-review-plugin by scm-manager.
the class CommentService method modifyReply.
public void modifyReply(String namespace, String name, String pullRequestId, String replyId, Reply changedReply) {
Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
PullRequest pullRequest = pullRequestService.get(repository, pullRequestId);
findReplyWithParent(repository, pullRequestId, replyId).<NotFoundException>orElseThrow(() -> {
throw notFound(entity(Reply.class, String.valueOf(changedReply.getId())).in(PullRequest.class, pullRequestId).in(repository.getNamespaceAndName()));
}).execute((parent, reply) -> {
PermissionCheck.checkModifyComment(repository, reply);
Reply clone = reply.clone();
reply.setComment(changedReply.getComment());
reply.addTransition(new ExecutedTransition<>(keyGenerator.createKey(), CHANGE_TEXT, System.currentTimeMillis(), getCurrentUserId()));
handleMentions(repository, pullRequest, reply, clone);
getCommentStore(repository).update(pullRequestId, parent);
eventBus.post(new ReplyEvent(repository, pullRequest, reply, clone, parent, HandlerEventType.MODIFY));
});
}
use of com.cloudogu.scm.review.pullrequest.service.PullRequest in project scm-review-plugin by scm-manager.
the class CommentService method transform.
public ExecutedTransition<CommentTransition> transform(String namespace, String name, String pullRequestId, String commentId, CommentTransition transition) {
Comment comment = get(namespace, name, pullRequestId, commentId);
Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
PullRequest pullRequest = pullRequestService.get(repository, pullRequestId);
Comment clone = comment.clone();
transition.accept(clone);
ExecutedTransition<CommentTransition> executedTransition = new ExecutedTransition<>(keyGenerator.createKey(), transition, System.currentTimeMillis(), getCurrentUserId());
clone.addCommentTransition(executedTransition);
getCommentStore(repository).update(pullRequestId, clone);
eventBus.post(new CommentEvent(repository, pullRequest, comment, clone, HandlerEventType.MODIFY));
return executedTransition;
}
use of com.cloudogu.scm.review.pullrequest.service.PullRequest in project scm-review-plugin by scm-manager.
the class EmailNotificationHook method handleCommentEvents.
@Subscribe
public void handleCommentEvents(CommentEvent event) {
if (!isSystemComment(event)) {
PullRequest pullRequest = event.getPullRequest();
handleEvent(event, new CommentEventMailTextResolver(event), pullRequest, getSubscribersWithoutCurrentUser(pullRequest));
}
}
use of com.cloudogu.scm.review.pullrequest.service.PullRequest in project scm-review-plugin by scm-manager.
the class PullRequestRootResource method create.
@POST
@Path("{namespace}/{name}")
@Consumes(PullRequestMediaType.PULL_REQUEST)
@Operation(summary = "Create pull request", description = "Creates a new pull request.", tags = "Pull Request", operationId = "review_create_pull_request")
@ApiResponse(responseCode = "201", description = "create success")
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"createPullRequest\" privilege")
@ApiResponse(responseCode = "409", description = "conflict, a similar pull request for these branches already exists")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public Response create(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name, @NotNull @Valid PullRequestDto pullRequestDto) {
Repository repository = service.getRepository(namespace, name);
PermissionCheck.checkCreate(repository);
String source = pullRequestDto.getSource();
String target = pullRequestDto.getTarget();
service.get(repository, source, target, PullRequestStatus.OPEN).ifPresent(pullRequest -> {
throw alreadyExists(entity(repository).in("pull request", pullRequest.getId()).in(repository));
});
service.checkBranch(repository, source);
service.checkBranch(repository, target);
verifyBranchesDiffer(source, target);
User user = CurrentUserResolver.getCurrentUser();
pullRequestDto.setStatus(PullRequestStatus.OPEN);
PullRequest pullRequest = mapper.using(uriInfo).map(pullRequestDto);
pullRequest.setAuthor(user.getId());
String id = service.add(repository, pullRequest);
URI location = uriInfo.getAbsolutePathBuilder().path(id).build();
return Response.created(location).build();
}
use of com.cloudogu.scm.review.pullrequest.service.PullRequest in project scm-review-plugin by scm-manager.
the class MergeObstacleCheckHookTest method shouldIgnoreClosedPullRequest.
@Test
void shouldIgnoreClosedPullRequest() {
PullRequest pullRequest = new PullRequest("pr", "source", "target");
pullRequest.setStatus(PullRequestStatus.REJECTED);
when(pullRequestService.getAll(NAMESPACE, NAME)).thenReturn(singletonList(pullRequest));
when(branchProvider.getCreatedOrModified()).thenReturn(singletonList("source"));
hook.checkForObstacles(event);
verify(branchProvider, never()).getCreatedOrModified();
verify(mergeDetectionProvider, never()).branchesMerged(any(), any());
}
Aggregations