Search in sources :

Example 6 with PullRequest

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));
    });
}
Also used : Repository(sonia.scm.repository.Repository) NamespaceAndName(sonia.scm.repository.NamespaceAndName) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest)

Example 7 with PullRequest

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;
}
Also used : Repository(sonia.scm.repository.Repository) NamespaceAndName(sonia.scm.repository.NamespaceAndName) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest)

Example 8 with PullRequest

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));
    }
}
Also used : PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Subscribe(com.github.legman.Subscribe)

Example 9 with 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();
}
Also used : Repository(sonia.scm.repository.Repository) User(sonia.scm.user.User) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) URI(java.net.URI) 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)

Example 10 with PullRequest

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());
}
Also used : PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Test(org.junit.jupiter.api.Test)

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