Search in sources :

Example 1 with PullRequestResourceLinks

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

the class CommentRootResource method getAll.

@GET
@Path("")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Get all pull request comments", description = "Returns all pull request comments.", tags = "Pull Request Comment", operationId = "review_get_comments")
@ApiResponse(responseCode = "200", description = "success", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = HalRepresentation.class)))
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"commentPullRequest\" privilege")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public HalRepresentation getAll(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId) {
    PullRequestResourceLinks resourceLinks = new PullRequestResourceLinks(uriInfo::getBaseUri);
    Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
    PullRequest pullRequest = pullRequestService.get(namespace, name, pullRequestId);
    BranchRevisionResolver.RevisionResult revisions = branchRevisionResolver.getRevisions(new NamespaceAndName(namespace, name), pullRequest);
    List<Comment> list = service.getAll(namespace, name, pullRequestId);
    List<CommentDto> dtoList = list.stream().map(comment -> mapper.map(comment, repository, pullRequestId, service.possibleTransitions(namespace, name, pullRequestId, comment.getId()), revisions)).collect(Collectors.toList());
    boolean permission = PermissionCheck.mayComment(repository);
    return createCollection(permission, resourceLinks.pullRequestComments().all(namespace, name, pullRequestId), resourceLinks.pullRequestComments().create(namespace, name, pullRequestId, revisions), dtoList, "pullRequestComments");
}
Also used : PullRequestMediaType(com.cloudogu.scm.review.PullRequestMediaType) PathParam(javax.ws.rs.PathParam) Provider(javax.inject.Provider) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) BranchRevisionResolver(com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Inject(javax.inject.Inject) Valid(javax.validation.Valid) Content(io.swagger.v3.oas.annotations.media.Content) Operation(io.swagger.v3.oas.annotations.Operation) MediaType(javax.ws.rs.core.MediaType) VndMediaType(sonia.scm.web.VndMediaType) QueryParam(javax.ws.rs.QueryParam) HalRepresentation(de.otto.edison.hal.HalRepresentation) Consumes(javax.ws.rs.Consumes) Comment(com.cloudogu.scm.review.comment.service.Comment) ErrorDto(sonia.scm.api.v2.resources.ErrorDto) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) PermissionCheck(com.cloudogu.scm.review.PermissionCheck) PullRequestService(com.cloudogu.scm.review.pullrequest.service.PullRequestService) URI(java.net.URI) Schema(io.swagger.v3.oas.annotations.media.Schema) RepositoryResolver(com.cloudogu.scm.review.RepositoryResolver) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) HalRepresentations.createCollection(com.cloudogu.scm.review.HalRepresentations.createCollection) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) AuthorizationException(org.apache.shiro.authz.AuthorizationException) List(java.util.List) Response(javax.ws.rs.core.Response) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) CommentService(com.cloudogu.scm.review.comment.service.CommentService) RevisionChecker.checkRevision(com.cloudogu.scm.review.comment.api.RevisionChecker.checkRevision) UriInfo(javax.ws.rs.core.UriInfo) NamespaceAndName(sonia.scm.repository.NamespaceAndName) Comment(com.cloudogu.scm.review.comment.service.Comment) NamespaceAndName(sonia.scm.repository.NamespaceAndName) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) BranchRevisionResolver(com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver) Repository(sonia.scm.repository.Repository) 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 2 with PullRequestResourceLinks

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

the class PullRequestRootResource method getAll.

@GET
@Path("{namespace}/{name}")
@Produces(PullRequestMediaType.PULL_REQUEST_COLLECTION)
@Operation(summary = "Collection of pull requests", description = "Returns a list of pull requests by status.", tags = "Pull Request", operationId = "review_get_pull_request_collection")
@ApiResponse(responseCode = "200", description = "success", content = @Content(mediaType = PullRequestMediaType.PULL_REQUEST_COLLECTION, schema = @Schema(implementation = HalRepresentation.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 HalRepresentation getAll(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name, @QueryParam("status") @DefaultValue("OPEN") PullRequestSelector pullRequestSelector) {
    Repository repository = service.getRepository(namespace, name);
    PermissionCheck.checkRead(repository);
    List<PullRequestDto> pullRequestDtos = service.getAll(namespace, name).stream().filter(pullRequestSelector).map(pr -> mapper.using(uriInfo).map(pr, repository)).sorted(Comparator.comparing(this::getLastModification).reversed()).collect(Collectors.toList());
    PullRequestResourceLinks resourceLinks = new PullRequestResourceLinks(uriInfo::getBaseUri);
    boolean permission = PermissionCheck.mayCreate(repository);
    return createCollection(permission, resourceLinks.pullRequestCollection().all(namespace, name), resourceLinks.pullRequestCollection().create(namespace, name), pullRequestDtos, "pullRequests");
}
Also used : PullRequestDto(com.cloudogu.scm.review.pullrequest.dto.PullRequestDto) Repository(sonia.scm.repository.Repository) 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 3 with PullRequestResourceLinks

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

the class GlobalEngineConfigMapper method create.

@ObjectFactory
GlobalEngineConfigDto create(@Context UriInfo uriInfo) {
    final Links.Builder linksBuilder = new Links.Builder();
    PullRequestResourceLinks.WorkflowEngineGlobalConfigLinks workflowEngineGlobalConfigLinks = new PullRequestResourceLinks(uriInfo::getBaseUri).workflowEngineGlobalConfigLinks();
    linksBuilder.self(workflowEngineGlobalConfigLinks.getConfig());
    if (PermissionCheck.mayConfigureGlobalWorkflowConfig()) {
        linksBuilder.single(link("update", workflowEngineGlobalConfigLinks.setConfig()));
    }
    if (PermissionCheck.mayReadGlobalWorkflowConfig() || PermissionCheck.mayConfigureGlobalWorkflowConfig()) {
        linksBuilder.single(link("availableRules", workflowEngineGlobalConfigLinks.availableRules()));
    }
    return new GlobalEngineConfigDto(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)

Example 4 with PullRequestResourceLinks

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

the class MergeResource method check.

@POST
@Path("{namespace}/{name}/{pullRequestId}/merge-check")
@Produces(PullRequestMediaType.MERGE_CHECK_RESULT)
@Operation(summary = "Check pull request merge", description = "Checks if the pull request can be merged.", tags = "Pull Request")
@ApiResponse(responseCode = "200", description = "update success", content = @Content(mediaType = PullRequestMediaType.MERGE_CHECK_RESULT, schema = @Schema(implementation = MergeCheckResultDto.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 = "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 MergeCheckResultDto check(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId, @Context UriInfo uriInfo) {
    NamespaceAndName namespaceAndName = new NamespaceAndName(namespace, name);
    MergeCheckResult mergeCheckResult = service.checkMerge(namespaceAndName, pullRequestId);
    String checkLink = new PullRequestResourceLinks(uriInfo::getBaseUri).mergeLinks().check(namespace, name, pullRequestId);
    return new MergeCheckResultDto(Links.linkingTo().self(checkLink).build(), mergeCheckResult.hasConflicts(), mergeCheckResult.getMergeObstacles());
}
Also used : MergeCheckResultDto(com.cloudogu.scm.review.pullrequest.dto.MergeCheckResultDto) NamespaceAndName(sonia.scm.repository.NamespaceAndName) MergeCheckResult(com.cloudogu.scm.review.pullrequest.service.MergeCheckResult) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 5 with PullRequestResourceLinks

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

the class PullRequestRootResource method createCheckResultLinks.

private Links createCheckResultLinks(UriInfo uriInfo, Repository repository, String source, String target) {
    PullRequestResourceLinks pullRequestResourceLinks = new PullRequestResourceLinks(uriInfo::getBaseUri);
    String checkLink = String.format("%s?source=%s&target=%s", pullRequestResourceLinks.pullRequestCollection().check(repository.getNamespace(), repository.getName()), source, target);
    return Links.linkingTo().self(checkLink).build();
}
Also used : PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks)

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