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();
}
}
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()));
}
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());
}
Aggregations