Search in sources :

Example 1 with HalEnricherContext

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

the class RepositoryLinkEnricher method enrich.

@Override
public void enrich(HalEnricherContext context, HalAppender appender) {
    Repository repository = context.oneRequireByType(Repository.class);
    if (pullRequestService.supportsPullRequests(repository)) {
        if (mayRead(repository)) {
            LinkBuilder linkBuilder = new LinkBuilder(scmPathInfoStore.get().get(), PullRequestRootResource.class);
            appender.appendLink("pullRequest", linkBuilder.method("getAll").parameters(repository.getNamespace(), repository.getName()).href());
        }
        if (mayCreate(repository)) {
            LinkBuilder linkBuilder = new LinkBuilder(scmPathInfoStore.get().get(), PullRequestRootResource.class);
            appender.appendLink("pullRequestCheck", linkBuilder.method("check").parameters(repository.getNamespace(), repository.getName()).href());
        }
        if (mayConfigure(repository) && !configService.getGlobalPullRequestConfig().isDisableRepositoryConfiguration()) {
            LinkBuilder linkBuilder = new LinkBuilder(scmPathInfoStore.get().get(), RepositoryConfigResource.class);
            appender.appendLink("pullRequestConfig", linkBuilder.method("getRepositoryConfig").parameters(repository.getNamespace(), repository.getName()).href());
        }
        if (isWorkflowEngineConfigurable(repository)) {
            LinkBuilder linkBuilder = new LinkBuilder(scmPathInfoStore.get().get(), RepositoryEngineConfigResource.class);
            appender.appendLink("workflowConfig", linkBuilder.method("getRepositoryEngineConfig").parameters(repository.getNamespace(), repository.getName()).href());
        }
    }
}
Also used : Repository(sonia.scm.repository.Repository) LinkBuilder(sonia.scm.api.v2.resources.LinkBuilder)

Example 2 with HalEnricherContext

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

the class RepositoryLinkEnricherTest method shouldNotEnrichBecauseOfMissingPermission.

@Test
@SubjectAware(username = "trillian", password = "secret")
public void shouldNotEnrichBecauseOfMissingPermission() {
    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, never()).appendLink(any(), 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 3 with HalEnricherContext

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

the class RepositoryLinkEnricherTest method shouldEnrichWorkflowConfigLink.

@Test
@SubjectAware(username = "dent", password = "secret")
public void shouldEnrichWorkflowConfigLink() {
    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("workflowConfig", "https://scm-manager.org/scm/api/v2/workflow/space/name/config");
}
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 4 with HalEnricherContext

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

the class RepositoryLinkEnricherTest method shouldNotEnrichRepositoriesWithoutBranchSupport.

@Test
@SubjectAware(username = "dent", password = "secret")
public void shouldNotEnrichRepositoriesWithoutBranchSupport() {
    enricher = new RepositoryLinkEnricher(scmPathInfoStoreProvider, pullRequestService, configService, globalEngineConfigurator);
    when(pullRequestService.supportsPullRequests(any())).thenReturn(false);
    Repository repo = new Repository("id", "type", "space", "name");
    HalEnricherContext context = HalEnricherContext.of(repo);
    enricher.enrich(context, appender);
    verify(appender, never()).appendLink(any(), 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 5 with HalEnricherContext

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

the class RepositoryLinkEnricherTest method shouldEnrichRepositoriesWithBranchSupport.

@Test
@SubjectAware(username = "dent", password = "secret")
public void shouldEnrichRepositoriesWithBranchSupport() {
    enricher = new RepositoryLinkEnricher(scmPathInfoStoreProvider, pullRequestService, configService, globalEngineConfigurator);
    when(pullRequestService.supportsPullRequests(any())).thenReturn(true);
    mockGlobalConfig(false);
    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).appendLink("pullRequestConfig", "https://scm-manager.org/scm/api/v2/pull-requests/space/name/config");
}
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