Search in sources :

Example 51 with Repository

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

the class RepositoryEngineConfigResource method getRepositoryEngineConfig.

@GET
@Path("{namespace}/{name}/config")
@Produces(WORKFLOW_MEDIA_TYPE)
@Operation(summary = "Workflow engine configuration", description = "Returns the repository specific workflow engine configuration.", tags = "Workflow Engine", operationId = "review_get_repository_workflow_configuration")
@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 \"repository:readWorkflowConfig\" privilege")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public RepositoryEngineConfigDto getRepositoryEngineConfig(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name) {
    Repository repository = loadRepository(namespace, name);
    PermissionCheck.checkReadWorkflowConfig(repository);
    return mapper.map(configurator.getEngineConfiguration(repository), repository, uriInfo);
}
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 52 with Repository

use of sonia.scm.repository.Repository 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()));
}
Also used : Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Links(de.otto.edison.hal.Links) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) 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 53 with Repository

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

the class RepositoryResolverTest method testResolveForUnsupportedType.

@Test
public void testResolveForUnsupportedType() {
    Repository repository = RepositoryTestData.createHeartOfGold("svn");
    repository.setId("42");
    when(repositoryManager.get(namespaceAndName)).thenReturn(repository);
    when(repositoryServiceFactory.create(repository)).thenReturn(repositoryService);
    when(repositoryService.isSupported(Command.MERGE)).thenReturn(Boolean.FALSE);
    PullRequestNotSupportedException exception = assertThrows(PullRequestNotSupportedException.class, () -> resolver.resolve(namespaceAndName));
    ContextEntry contextEntry = exception.getContext().get(0);
    assertThat(contextEntry.getType()).isEqualTo("Repository");
    assertThat(contextEntry.getId()).isEqualTo("hitchhiker/HeartOfGold");
}
Also used : Repository(sonia.scm.repository.Repository) ContextEntry(sonia.scm.ContextEntry) Test(org.junit.jupiter.api.Test)

Example 54 with Repository

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

the class RepositoryResolverTest method testResolve.

@Test
public void testResolve() {
    Repository repository = RepositoryTestData.createHeartOfGold("git");
    repository.setId("42");
    when(repositoryManager.get(namespaceAndName)).thenReturn(repository);
    when(repositoryServiceFactory.create(repository)).thenReturn(repositoryService);
    when(repositoryService.isSupported(Command.MERGE)).thenReturn(Boolean.TRUE);
    Repository resolvedRepository = resolver.resolve(namespaceAndName);
    assertThat(resolvedRepository).isSameAs(repository);
}
Also used : Repository(sonia.scm.repository.Repository) Test(org.junit.jupiter.api.Test)

Example 55 with Repository

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

the class CommentStoreFactoryTest method shouldCreateCommentStore.

@Test
public void shouldCreateCommentStore() {
    Repository repository = RepositoryTestData.createHeartOfGold("git");
    repository.setId("repo");
    when(dataStoreFactory.getStore(any())).thenReturn((DataStore) store);
    when(dataStoreFactory.withType(any())).thenCallRealMethod();
    CommentStore commentStore = storeFactory.create(repository);
    assertThat(commentStore).isNotNull();
}
Also used : Repository(sonia.scm.repository.Repository) Test(org.junit.jupiter.api.Test)

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