Search in sources :

Example 46 with Repository

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

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

the class DefaultPullRequestService method approve.

@Override
public void approve(NamespaceAndName namespaceAndName, String pullRequestId, User user) {
    Repository repository = getRepository(namespaceAndName.getNamespace(), namespaceAndName.getName());
    PermissionCheck.checkComment(repository);
    PullRequest pullRequest = getPullRequestFromStore(repository, pullRequestId);
    pullRequest.addApprover(user.getId());
    getStore(repository).update(pullRequest);
    eventBus.post(new PullRequestApprovalEvent(repository, pullRequest, APPROVED));
}
Also used : Repository(sonia.scm.repository.Repository)

Example 48 with Repository

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

the class DefaultPullRequestService method disapprove.

@Override
public void disapprove(NamespaceAndName namespaceAndName, String pullRequestId, User user) {
    Repository repository = getRepository(namespaceAndName.getNamespace(), namespaceAndName.getName());
    PermissionCheck.checkComment(repository);
    PullRequest pullRequest = getPullRequestFromStore(repository, pullRequestId);
    Set<String> approver = pullRequest.getReviewer().keySet();
    approver.stream().filter(recipient -> user.getId().equals(recipient)).findFirst().ifPresent(approval -> {
        pullRequest.removeApprover(approval);
        getStore(repository).update(pullRequest);
        eventBus.post(new PullRequestApprovalEvent(repository, pullRequest, APPROVAL_REMOVED));
    });
}
Also used : Repository(sonia.scm.repository.Repository)

Example 49 with Repository

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

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

the class RepositoryEngineConfigResource method setRepositoryEngineConfig.

@PUT
@Path("{namespace}/{name}/config")
@Consumes(WORKFLOW_MEDIA_TYPE)
@Operation(summary = "Update Repository workflow engine configuration", description = "Modifies the repository-specific workflow engine configuration.", tags = "Workflow Engine", operationId = "review_put_repository_workflow_config")
@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 \"repository:writeWorkflowConfig\" privilege")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public void setRepositoryEngineConfig(@PathParam("namespace") String namespace, @PathParam("name") String name, @Valid RepositoryEngineConfigDto configDto) {
    Repository repository = loadRepository(namespace, name);
    PermissionCheck.checkWriteWorkflowConfig(repository);
    configurator.setEngineConfiguration(repository, mapper.map(configDto));
}
Also used : Repository(sonia.scm.repository.Repository) 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)

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