Search in sources :

Example 6 with HalEnricherContext

use of sonia.scm.api.v2.resources.HalEnricherContext in project scm-review-plugin by scm-manager.

the class IndexLinkEnricher method enrich.

@Override
public void enrich(HalEnricherContext context, HalAppender appender) {
    if (PermissionCheck.mayReadGlobalConfig()) {
        String globalConfigUrl = new LinkBuilder(scmPathInfoStore.get().get(), GlobalConfigResource.class).method("getGlobalConfig").parameters().href();
        appender.appendLink("pullRequestConfig", globalConfigUrl);
    }
    if (PermissionCheck.mayReadGlobalWorkflowConfig()) {
        String globalEngineConfigUrl = new LinkBuilder(scmPathInfoStore.get().get(), GlobalEngineConfigResource.class).method("getGlobalEngineConfig").parameters().href();
        appender.appendLink("workflowConfig", globalEngineConfigUrl);
    }
}
Also used : LinkBuilder(sonia.scm.api.v2.resources.LinkBuilder) GlobalEngineConfigResource(com.cloudogu.scm.review.workflow.GlobalEngineConfigResource) GlobalConfigResource(com.cloudogu.scm.review.config.api.GlobalConfigResource)

Example 7 with HalEnricherContext

use of sonia.scm.api.v2.resources.HalEnricherContext in project scm-review-plugin by scm-manager.

the class RepositoryLinkEnricherTest method shouldNotEnrichRepositoriesForConfigWhenRepositoryConfigIsDisabled.

@Test
@SubjectAware(username = "dent", password = "secret")
public void shouldNotEnrichRepositoriesForConfigWhenRepositoryConfigIsDisabled() {
    enricher = new RepositoryLinkEnricher(scmPathInfoStoreProvider, pullRequestService, configService, globalEngineConfigurator);
    when(pullRequestService.supportsPullRequests(any())).thenReturn(true);
    mockGlobalConfig(true);
    Repository repo = new Repository("id", "type", "space", "name");
    HalEnricherContext context = HalEnricherContext.of(repo);
    enricher.enrich(context, appender);
    verify(appender).appendLink("pullRequest", "https://scm-manager.org/scm/api/v2/pull-requests/space/name");
    verify(appender, never()).appendLink(eq("pullRequestConfig"), any());
}
Also used : Repository(sonia.scm.repository.Repository) HalEnricherContext(sonia.scm.api.v2.resources.HalEnricherContext) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 8 with HalEnricherContext

use of sonia.scm.api.v2.resources.HalEnricherContext in project scm-review-plugin by scm-manager.

the class RepositoryLinkEnricherTest method shouldEnrichPullRequestCheckLink.

@Test
@SubjectAware(username = "dent", password = "secret")
public void shouldEnrichPullRequestCheckLink() {
    when(pullRequestService.supportsPullRequests(any())).thenReturn(true);
    mockGlobalConfig(true);
    enricher = new RepositoryLinkEnricher(scmPathInfoStoreProvider, pullRequestService, configService, globalEngineConfigurator);
    Repository repo = new Repository("id", "type", "space", "name");
    HalEnricherContext context = HalEnricherContext.of(repo);
    enricher.enrich(context, appender);
    verify(appender).appendLink("pullRequestCheck", "https://scm-manager.org/scm/api/v2/pull-requests/space/name/check");
}
Also used : Repository(sonia.scm.repository.Repository) HalEnricherContext(sonia.scm.api.v2.resources.HalEnricherContext) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Aggregations

Repository (sonia.scm.repository.Repository)7 SubjectAware (com.github.sdorra.shiro.SubjectAware)6 Test (org.junit.Test)6 HalEnricherContext (sonia.scm.api.v2.resources.HalEnricherContext)6 LinkBuilder (sonia.scm.api.v2.resources.LinkBuilder)2 GlobalConfigResource (com.cloudogu.scm.review.config.api.GlobalConfigResource)1 GlobalEngineConfigResource (com.cloudogu.scm.review.workflow.GlobalEngineConfigResource)1