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());
}
}
}
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());
}
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");
}
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());
}
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");
}
Aggregations