use of sonia.scm.repository.Repository in project scm-review-plugin by scm-manager.
the class CommentService method modifyReply.
public void modifyReply(String namespace, String name, String pullRequestId, String replyId, Reply changedReply) {
Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
PullRequest pullRequest = pullRequestService.get(repository, pullRequestId);
findReplyWithParent(repository, pullRequestId, replyId).<NotFoundException>orElseThrow(() -> {
throw notFound(entity(Reply.class, String.valueOf(changedReply.getId())).in(PullRequest.class, pullRequestId).in(repository.getNamespaceAndName()));
}).execute((parent, reply) -> {
PermissionCheck.checkModifyComment(repository, reply);
Reply clone = reply.clone();
reply.setComment(changedReply.getComment());
reply.addTransition(new ExecutedTransition<>(keyGenerator.createKey(), CHANGE_TEXT, System.currentTimeMillis(), getCurrentUserId()));
handleMentions(repository, pullRequest, reply, clone);
getCommentStore(repository).update(pullRequestId, parent);
eventBus.post(new ReplyEvent(repository, pullRequest, reply, clone, parent, HandlerEventType.MODIFY));
});
}
use of sonia.scm.repository.Repository in project scm-review-plugin by scm-manager.
the class CommentService method transform.
public ExecutedTransition<CommentTransition> transform(String namespace, String name, String pullRequestId, String commentId, CommentTransition transition) {
Comment comment = get(namespace, name, pullRequestId, commentId);
Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
PullRequest pullRequest = pullRequestService.get(repository, pullRequestId);
Comment clone = comment.clone();
transition.accept(clone);
ExecutedTransition<CommentTransition> executedTransition = new ExecutedTransition<>(keyGenerator.createKey(), transition, System.currentTimeMillis(), getCurrentUserId());
clone.addCommentTransition(executedTransition);
getCommentStore(repository).update(pullRequestId, clone);
eventBus.post(new CommentEvent(repository, pullRequest, comment, clone, HandlerEventType.MODIFY));
return executedTransition;
}
use of sonia.scm.repository.Repository in project scm-review-plugin by scm-manager.
the class RepositoryConfigResource method setRepositoryConfig.
@PUT
@Path("{namespace}/{name}/config")
@Consumes(MediaType.APPLICATION_JSON)
@Operation(summary = "Update Repository pull request configuration", description = "Modifies the repository-specific pull request configuration.", tags = "Pull Request Configuration", operationId = "review_put_repo_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 \"configurePullRequest\" privilege")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public void setRepositoryConfig(@PathParam("namespace") String namespace, @PathParam("name") String name, @Valid PullRequestConfigDto configDto) {
Repository repository = repositoryManager.get(new NamespaceAndName(namespace, name));
if (repository == null) {
throw notFound(entity(new NamespaceAndName(namespace, name)));
}
PermissionCheck.checkConfigure(repository);
configService.setRepositoryPullRequestConfig(repository, repositoryConfigMapper.map(configDto));
}
use of sonia.scm.repository.Repository in project scm-review-plugin by scm-manager.
the class PullRequestRootResource method create.
@POST
@Path("{namespace}/{name}")
@Consumes(PullRequestMediaType.PULL_REQUEST)
@Operation(summary = "Create pull request", description = "Creates a new pull request.", tags = "Pull Request", operationId = "review_create_pull_request")
@ApiResponse(responseCode = "201", description = "create success")
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"createPullRequest\" privilege")
@ApiResponse(responseCode = "409", description = "conflict, a similar pull request for these branches already exists")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public Response create(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name, @NotNull @Valid PullRequestDto pullRequestDto) {
Repository repository = service.getRepository(namespace, name);
PermissionCheck.checkCreate(repository);
String source = pullRequestDto.getSource();
String target = pullRequestDto.getTarget();
service.get(repository, source, target, PullRequestStatus.OPEN).ifPresent(pullRequest -> {
throw alreadyExists(entity(repository).in("pull request", pullRequest.getId()).in(repository));
});
service.checkBranch(repository, source);
service.checkBranch(repository, target);
verifyBranchesDiffer(source, target);
User user = CurrentUserResolver.getCurrentUser();
pullRequestDto.setStatus(PullRequestStatus.OPEN);
PullRequest pullRequest = mapper.using(uriInfo).map(pullRequestDto);
pullRequest.setAuthor(user.getId());
String id = service.add(repository, pullRequest);
URI location = uriInfo.getAbsolutePathBuilder().path(id).build();
return Response.created(location).build();
}
use of sonia.scm.repository.Repository 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");
}
Aggregations