Search in sources :

Example 51 with PullRequest

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

the class PullRequestMapper method appendMergeStrategyLinks.

private void appendMergeStrategyLinks(Links.Builder linksBuilder, Repository repository, PullRequest pullRequest) {
    try (RepositoryService service = serviceFactory.create(repository)) {
        if (service.isSupported(Command.MERGE)) {
            List<Link> mergeStrategyLinks = service.getMergeCommand().getSupportedMergeStrategies().stream().map(strategy -> createMergeStrategyLink(repository.getNamespaceAndName(), pullRequest, strategy)).collect(toList());
            linksBuilder.array(mergeStrategyLinks);
            if (PermissionCheck.mayPerformEmergencyMerge(repository)) {
                List<Link> emergencyMergeStrategyLinks = service.getMergeCommand().getSupportedMergeStrategies().stream().map(strategy -> createEmergencyMergeStrategyLink(repository.getNamespaceAndName(), pullRequest, strategy)).collect(toList());
                linksBuilder.array(emergencyMergeStrategyLinks);
            }
        }
    }
}
Also used : Mapping(org.mapstruct.Mapping) RepositoryPermissions(sonia.scm.repository.RepositoryPermissions) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) MappingTarget(org.mapstruct.MappingTarget) Embedded.embeddedBuilder(de.otto.edison.hal.Embedded.embeddedBuilder) Links(de.otto.edison.hal.Links) Mapper(org.mapstruct.Mapper) Comment(com.cloudogu.scm.review.comment.service.Comment) Map(java.util.Map) Link.link(de.otto.edison.hal.Link.link) PermissionCheck(com.cloudogu.scm.review.PermissionCheck) RepositoryService(sonia.scm.repository.api.RepositoryService) CurrentUserResolver.getCurrentUser(com.cloudogu.scm.review.CurrentUserResolver.getCurrentUser) PullRequestService(com.cloudogu.scm.review.pullrequest.service.PullRequestService) URI(java.net.URI) Predicate(java.util.function.Predicate) Set(java.util.Set) MergeStrategy(sonia.scm.repository.api.MergeStrategy) Collectors(java.util.stream.Collectors) List(java.util.List) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) CommentService(com.cloudogu.scm.review.comment.service.CommentService) CommentType(com.cloudogu.scm.review.comment.service.CommentType) UserDisplayManager(sonia.scm.user.UserDisplayManager) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) NamespaceAndName(sonia.scm.repository.NamespaceAndName) PullRequestStatus(com.cloudogu.scm.review.pullrequest.service.PullRequestStatus) Embedded(de.otto.edison.hal.Embedded) HashMap(java.util.HashMap) DisplayUser(sonia.scm.user.DisplayUser) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) EdisonHalAppender(sonia.scm.web.EdisonHalAppender) CurrentUserResolver(com.cloudogu.scm.review.CurrentUserResolver) RepositoryServiceFactory(sonia.scm.repository.api.RepositoryServiceFactory) Named(javax.inject.Named) Command(sonia.scm.repository.api.Command) BaseMapper(sonia.scm.api.v2.resources.BaseMapper) BranchLinkProvider(sonia.scm.api.v2.resources.BranchLinkProvider) AfterMapping(org.mapstruct.AfterMapping) Context(org.mapstruct.Context) ObjectFactory(org.mapstruct.ObjectFactory) Links.linkingTo(de.otto.edison.hal.Links.linkingTo) User(sonia.scm.user.User) Collectors.toList(java.util.stream.Collectors.toList) ReviewMark(com.cloudogu.scm.review.pullrequest.service.ReviewMark) Link(de.otto.edison.hal.Link) Link(de.otto.edison.hal.Link) RepositoryService(sonia.scm.repository.api.RepositoryService)

Example 52 with PullRequest

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

the class PullRequestResource method events.

@GET
@Path("events")
@SseResponse
@Operation(summary = "Register SSE", hidden = true)
@Produces(MediaType.SERVER_SENT_EVENTS)
public void events(@Context Sse sse, @Context SseEventSink eventSink, @BeanParam EventSubscriptionRequest request) {
    Repository repository = service.getRepository(request.getNamespace(), request.getName());
    PermissionCheck.checkRead(repository);
    PullRequest pullRequest = service.get(repository, request.getPullRequestId());
    Channel channel = channelRegistry.channel(new ChannelId(repository, pullRequest));
    channel.register(new Registration(request.getSessionId(), sse, eventSink));
}
Also used : Repository(sonia.scm.repository.Repository) Registration(sonia.scm.sse.Registration) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Channel(sonia.scm.sse.Channel) ChannelId(com.cloudogu.scm.review.events.ChannelId) Path(javax.ws.rs.Path) SseResponse(sonia.scm.sse.SseResponse) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Example 53 with PullRequest

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

the class PullRequestResource method update.

@PUT
@Path("")
@Consumes(PullRequestMediaType.PULL_REQUEST)
@Operation(summary = "Update pull request", description = "Modifies a pull request.", tags = "Pull Request", operationId = "review_put_pull_request")
@ApiResponse(responseCode = "204", description = "update success")
@ApiResponse(responseCode = "400", description = "Invalid body")
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"modifyPullRequest\" privilege")
@ApiResponse(responseCode = "404", description = "not found, no pull request with the specified id is available")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public Response update(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId, PullRequestDto pullRequestDto) {
    Repository repository = service.getRepository(namespace, name);
    if (!PermissionCheck.mayModifyPullRequest(repository, service.get(namespace, name, pullRequestId))) {
        return Response.status(Response.Status.FORBIDDEN).build();
    }
    PullRequest pullRequest = mapper.map(pullRequestDto);
    service.update(repository, pullRequestId, pullRequest);
    return Response.noContent().build();
}
Also used : Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Operation(io.swagger.v3.oas.annotations.Operation) PUT(javax.ws.rs.PUT) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 54 with PullRequest

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

the class AllTasksDoneRule method getComments.

private List<Comment> getComments(Context context) {
    Repository repository = context.getRepository();
    PullRequest pullRequest = context.getPullRequest();
    return commentService.getAll(repository.getNamespace(), repository.getName(), pullRequest.getId());
}
Also used : Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest)

Example 55 with PullRequest

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

the class ApprovedByXReviewersRule method validate.

@Override
public Result validate(Context context) {
    final PullRequest pullRequest = context.getPullRequest();
    Configuration configuration = context.getConfiguration(Configuration.class);
    long numberOfReviewers = pullRequest.getReviewer().values().stream().filter(b -> b).count();
    return numberOfReviewers >= configuration.numberOfReviewers ? success() : failed(new ErrorContext(configuration.numberOfReviewers, (int) numberOfReviewers, (int) (configuration.numberOfReviewers - numberOfReviewers)));
}
Also used : Setter(lombok.Setter) Getter(lombok.Getter) Extension(sonia.scm.plugin.Extension) Optional(java.util.Optional) Min(javax.validation.constraints.Min) AllArgsConstructor(lombok.AllArgsConstructor) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) NoArgsConstructor(lombok.NoArgsConstructor) 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