Search in sources :

Example 41 with Repository

use of sonia.scm.repository.Repository in project scm-review-plugin by scm-manager.

the class PullRequestResource method reject.

@POST
@Path("reject")
@Operation(summary = "Reject pull request", description = "Rejects a pull request.", tags = "Pull Request")
@ApiResponse(responseCode = "204", description = "update success")
@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 void reject(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId) {
    Repository repository = service.getRepository(namespace, name);
    service.reject(repository, pullRequestId, PullRequestRejectedEvent.RejectionCause.REJECTED_BY_USER);
}
Also used : Repository(sonia.scm.repository.Repository) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 42 with Repository

use of sonia.scm.repository.Repository in project scm-review-plugin by scm-manager.

the class PullRequestResource method subscribe.

@POST
@Path("subscribe")
@Operation(summary = "Subscribe", description = "Subscribes current user to a pull request.", tags = "Pull Request")
@ApiResponse(responseCode = "204", description = "update success")
@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 = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public void subscribe(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId) {
    Repository repository = service.getRepository(namespace, name);
    PermissionCheck.checkRead(repository);
    service.subscribe(repository, pullRequestId);
}
Also used : Repository(sonia.scm.repository.Repository) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 43 with Repository

use of sonia.scm.repository.Repository 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 44 with Repository

use of sonia.scm.repository.Repository in project scm-review-plugin by scm-manager.

the class PullRequestResource method get.

@GET
@Path("")
@Produces(PullRequestMediaType.PULL_REQUEST)
@Operation(summary = "Get pull requests", description = "Returns a single pull request by id.", tags = "Pull Request", operationId = "review_get_pull_requests")
@ApiResponse(responseCode = "200", description = "success", content = @Content(mediaType = PullRequestMediaType.PULL_REQUEST, schema = @Schema(implementation = PullRequestDto.class)))
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"readPullRequest\" privilege")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public PullRequestDto get(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId) {
    Repository repository = service.getRepository(namespace, name);
    PermissionCheck.checkRead(repository);
    return mapper.using(uriInfo).map(service.get(namespace, name, pullRequestId), repository);
}
Also used : Repository(sonia.scm.repository.Repository) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 45 with Repository

use of sonia.scm.repository.Repository in project scm-review-plugin by scm-manager.

the class PullRequestResource method getSubscription.

@GET
@Path("subscription")
@Produces(PullRequestMediaType.PULL_REQUEST)
@Operation(summary = "Evaluates which subscription link should be used", hidden = true)
@ApiResponse(responseCode = "200", description = "success")
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"readPullRequest\" privilege")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public Response getSubscription(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId) {
    Repository repository = service.getRepository(namespace, name);
    PermissionCheck.checkRead(repository);
    if (CurrentUserResolver.getCurrentUser() != null && Strings.isNullOrEmpty(CurrentUserResolver.getCurrentUser().getMail())) {
        return Response.ok().build();
    }
    if (service.isUserSubscribed(repository, pullRequestId)) {
        PullRequestResourceLinks resourceLinks = new PullRequestResourceLinks(uriInfo::getBaseUri);
        String unsubscribe = resourceLinks.pullRequest().unsubscribe(namespace, name, pullRequestId);
        Links.Builder linksBuilder = linkingTo().single(Link.link("unsubscribe", unsubscribe));
        return Response.ok(new HalRepresentation(linksBuilder.build())).build();
    } else {
        PullRequestResourceLinks resourceLinks = new PullRequestResourceLinks(uriInfo::getBaseUri);
        String subscribe = resourceLinks.pullRequest().subscribe(namespace, name, pullRequestId);
        Links.Builder linksBuilder = linkingTo().single(Link.link("subscribe", subscribe));
        return Response.ok(new HalRepresentation(linksBuilder.build())).build();
    }
}
Also used : Repository(sonia.scm.repository.Repository) HalRepresentation(de.otto.edison.hal.HalRepresentation) Links(de.otto.edison.hal.Links) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Aggregations

Repository (sonia.scm.repository.Repository)66 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)25 Operation (io.swagger.v3.oas.annotations.Operation)20 Path (javax.ws.rs.Path)20 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)19 NamespaceAndName (sonia.scm.repository.NamespaceAndName)16 GET (javax.ws.rs.GET)11 Produces (javax.ws.rs.Produces)11 Test (org.junit.jupiter.api.Test)9 Subscribe (com.github.legman.Subscribe)6 SubjectAware (com.github.sdorra.shiro.SubjectAware)6 Consumes (javax.ws.rs.Consumes)6 POST (javax.ws.rs.POST)6 Test (org.junit.Test)6 HalEnricherContext (sonia.scm.api.v2.resources.HalEnricherContext)6 PermissionCheck (com.cloudogu.scm.review.PermissionCheck)5 PullRequestResourceLinks (com.cloudogu.scm.review.PullRequestResourceLinks)5 Comment (com.cloudogu.scm.review.comment.service.Comment)5 PullRequestService (com.cloudogu.scm.review.pullrequest.service.PullRequestService)5 Inject (javax.inject.Inject)5