Search in sources :

Example 36 with Repository

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

the class RepositoryConfigResource method getRepositoryConfig.

@GET
@Path("{namespace}/{name}/config")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Repository pull request configuration", description = "Returns the repository-specific pull request configuration.", tags = "Pull Request Configuration", operationId = "review_get_repo_config")
@ApiResponse(responseCode = "200", description = "success", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = PullRequestConfigDto.class)))
@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 PullRequestConfigDto getRepositoryConfig(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name) {
    Repository repository = repositoryManager.get(new NamespaceAndName(namespace, name));
    if (repository == null) {
        throw notFound(entity(new NamespaceAndName(namespace, name)));
    }
    PermissionCheck.checkConfigure(repository);
    return repositoryConfigMapper.map(configService.getRepositoryPullRequestConfig(repository), repository, uriInfo);
}
Also used : Repository(sonia.scm.repository.Repository) NamespaceAndName(sonia.scm.repository.NamespaceAndName) 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 37 with Repository

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

the class BasicPRMailTextResolver method getMailSubject.

protected String getMailSubject(E event, String displayEventNameKey, Locale locale) {
    Repository repository = event.getRepository();
    PullRequest pullRequest = event.getPullRequest();
    String displayEventName = SUBJECT_BUNDLES.get(locale).getString(displayEventNameKey);
    return MessageFormat.format(SUBJECT_PATTERN, repository.getNamespace(), repository.getName(), displayEventName, pullRequest.getId(), pullRequest.getTitle());
}
Also used : Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest)

Example 38 with Repository

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

the class BasicPRMailTextResolver method getPullRequestLink.

private String getPullRequestLink(String baseUrl, E event) {
    Repository repository = event.getRepository();
    PullRequest pullRequest = event.getPullRequest();
    return MessageFormat.format(SCM_PULL_REQUEST_URL_PATTERN, baseUrl, repository.getNamespace(), repository.getName(), pullRequest.getId());
}
Also used : Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest)

Example 39 with Repository

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

the class PullRequestRootResource method check.

@GET
@Path("{namespace}/{name}/check")
@Produces(PullRequestMediaType.PULL_REQUEST)
@Operation(summary = "Checks pull request", description = "Checks if new pull request can be created.", tags = "Pull Request", operationId = "review_check_pull_request")
@ApiResponse(responseCode = "200", description = "Returns pull request check result")
@ApiResponse(responseCode = "400", description = "Invalid request / the provided source branch or target branch may not exist")
@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 = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public PullRequestCheckResultDto check(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name, @QueryParam("source") String source, @QueryParam("target") String target) throws IOException {
    Repository repository = service.getRepository(namespace, name);
    PermissionCheck.checkCreate(repository);
    service.checkBranch(repository, source);
    service.checkBranch(repository, target);
    return checkIfPullRequestIsValid(uriInfo, repository, source, target);
}
Also used : Repository(sonia.scm.repository.Repository) 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 40 with Repository

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

the class PullRequestMapper method appendMergeStrategyLinks.

private void appendMergeStrategyLinks(Links.Builder linksBuilder, Repository repository, PullRequest pullRequest) {
    try (RepositoryService service = serviceFactory.create(repository)) {
        if (service.isSupported(Command.MERGE)) {
            List<Link> mergeStrategyLinks = service.getMergeCommand().getSupportedMergeStrategies().stream().map(strategy -> createMergeStrategyLink(repository.getNamespaceAndName(), pullRequest, strategy)).collect(toList());
            linksBuilder.array(mergeStrategyLinks);
            if (PermissionCheck.mayPerformEmergencyMerge(repository)) {
                List<Link> emergencyMergeStrategyLinks = service.getMergeCommand().getSupportedMergeStrategies().stream().map(strategy -> createEmergencyMergeStrategyLink(repository.getNamespaceAndName(), pullRequest, strategy)).collect(toList());
                linksBuilder.array(emergencyMergeStrategyLinks);
            }
        }
    }
}
Also used : Mapping(org.mapstruct.Mapping) RepositoryPermissions(sonia.scm.repository.RepositoryPermissions) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) MappingTarget(org.mapstruct.MappingTarget) Embedded.embeddedBuilder(de.otto.edison.hal.Embedded.embeddedBuilder) Links(de.otto.edison.hal.Links) Mapper(org.mapstruct.Mapper) Comment(com.cloudogu.scm.review.comment.service.Comment) Map(java.util.Map) Link.link(de.otto.edison.hal.Link.link) PermissionCheck(com.cloudogu.scm.review.PermissionCheck) RepositoryService(sonia.scm.repository.api.RepositoryService) CurrentUserResolver.getCurrentUser(com.cloudogu.scm.review.CurrentUserResolver.getCurrentUser) PullRequestService(com.cloudogu.scm.review.pullrequest.service.PullRequestService) URI(java.net.URI) Predicate(java.util.function.Predicate) Set(java.util.Set) MergeStrategy(sonia.scm.repository.api.MergeStrategy) Collectors(java.util.stream.Collectors) List(java.util.List) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) CommentService(com.cloudogu.scm.review.comment.service.CommentService) CommentType(com.cloudogu.scm.review.comment.service.CommentType) UserDisplayManager(sonia.scm.user.UserDisplayManager) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) NamespaceAndName(sonia.scm.repository.NamespaceAndName) PullRequestStatus(com.cloudogu.scm.review.pullrequest.service.PullRequestStatus) Embedded(de.otto.edison.hal.Embedded) HashMap(java.util.HashMap) DisplayUser(sonia.scm.user.DisplayUser) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) EdisonHalAppender(sonia.scm.web.EdisonHalAppender) CurrentUserResolver(com.cloudogu.scm.review.CurrentUserResolver) RepositoryServiceFactory(sonia.scm.repository.api.RepositoryServiceFactory) Named(javax.inject.Named) Command(sonia.scm.repository.api.Command) BaseMapper(sonia.scm.api.v2.resources.BaseMapper) BranchLinkProvider(sonia.scm.api.v2.resources.BranchLinkProvider) AfterMapping(org.mapstruct.AfterMapping) Context(org.mapstruct.Context) ObjectFactory(org.mapstruct.ObjectFactory) Links.linkingTo(de.otto.edison.hal.Links.linkingTo) User(sonia.scm.user.User) Collectors.toList(java.util.stream.Collectors.toList) ReviewMark(com.cloudogu.scm.review.pullrequest.service.ReviewMark) Link(de.otto.edison.hal.Link) Link(de.otto.edison.hal.Link) RepositoryService(sonia.scm.repository.api.RepositoryService)

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