Search in sources :

Example 6 with PullRequestResourceLinks

use of com.cloudogu.scm.review.PullRequestResourceLinks 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)

Example 7 with PullRequestResourceLinks

use of com.cloudogu.scm.review.PullRequestResourceLinks in project scm-review-plugin by scm-manager.

the class EngineResultResource method getResult.

@GET
@Path("")
@Produces(WORKFLOW_RESULT_MEDIA_TYPE)
@Operation(summary = "Workflow engine result", description = "Returns the result of the workflow checks for the given pull request.", tags = "Workflow Engine", operationId = "review_get_repository_workflow_result")
@ApiResponse(responseCode = "200", description = "success", content = @Content(mediaType = WORKFLOW_RESULT_MEDIA_TYPE, schema = @Schema(implementation = ResultListDto.class)))
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"repository:readWorkflowConfig\" privilege")
@ApiResponse(responseCode = "404", description = "either repository or pull request not found")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public ResultListDto getResult(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId) {
    Repository repository = pullRequestService.getRepository(namespace, name);
    PullRequest pullRequest = pullRequestService.get(namespace, name, pullRequestId);
    final Links.Builder linksBuilder = new Links.Builder();
    linksBuilder.self(new PullRequestResourceLinks(uriInfo::getBaseUri).workflowEngineLinks().results(repository.getNamespace(), repository.getName(), pullRequestId));
    List<Result> ruleResults = engine.validate(repository, pullRequest).getRuleResults();
    return new ResultListDto(linksBuilder.build(), ruleResults.stream().map(this::createDto).collect(Collectors.toList()));
}
Also used : Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) 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)

Example 8 with PullRequestResourceLinks

use of com.cloudogu.scm.review.PullRequestResourceLinks in project scm-review-plugin by scm-manager.

the class RepositoryEngineConfigMapper method create.

@ObjectFactory
RepositoryEngineConfigDto create(@Context Repository repository, @Context UriInfo uriInfo) {
    final Links.Builder linksBuilder = new Links.Builder();
    PullRequestResourceLinks links = new PullRequestResourceLinks(uriInfo::getBaseUri);
    PullRequestResourceLinks.WorkflowEngineConfigLinks workflowEngineConfigLinks = links.workflowEngineConfigLinks();
    linksBuilder.self(workflowEngineConfigLinks.getConfig(repository.getNamespace(), repository.getName()));
    if (!globalEngineConfigurator.getEngineConfiguration().isDisableRepositoryConfiguration()) {
        if (PermissionCheck.mayConfigureWorkflowConfig(repository)) {
            linksBuilder.single(link("update", workflowEngineConfigLinks.setConfig(repository.getNamespace(), repository.getName())));
        }
        if (PermissionCheck.mayReadWorkflowConfig(repository) || PermissionCheck.mayConfigureWorkflowConfig(repository)) {
            linksBuilder.single(link("availableRules", links.workflowEngineGlobalConfigLinks().availableRules()));
        }
    }
    return new RepositoryEngineConfigDto(linksBuilder.build());
}
Also used : Links(de.otto.edison.hal.Links) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) ObjectFactory(org.mapstruct.ObjectFactory)

Aggregations

PullRequestResourceLinks (com.cloudogu.scm.review.PullRequestResourceLinks)8 Operation (io.swagger.v3.oas.annotations.Operation)5 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 Links (de.otto.edison.hal.Links)4 GET (javax.ws.rs.GET)4 Repository (sonia.scm.repository.Repository)4 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)2 HalRepresentation (de.otto.edison.hal.HalRepresentation)2 POST (javax.ws.rs.POST)2 ObjectFactory (org.mapstruct.ObjectFactory)2 HalRepresentations.createCollection (com.cloudogu.scm.review.HalRepresentations.createCollection)1 PermissionCheck (com.cloudogu.scm.review.PermissionCheck)1 PullRequestMediaType (com.cloudogu.scm.review.PullRequestMediaType)1 RepositoryResolver (com.cloudogu.scm.review.RepositoryResolver)1 RevisionChecker.checkRevision (com.cloudogu.scm.review.comment.api.RevisionChecker.checkRevision)1 Comment (com.cloudogu.scm.review.comment.service.Comment)1 CommentService (com.cloudogu.scm.review.comment.service.CommentService)1 BranchRevisionResolver (com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver)1