use of de.otto.edison.hal.Link 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);
}
}
}
}
use of de.otto.edison.hal.Link in project scm-review-plugin by scm-manager.
the class PullRequestMapperTest method shouldAppendSourceAndTargetBranchLinks.
@Test
void shouldAppendSourceAndTargetBranchLinks() {
String sourceLink = "/api/v2/source";
String targetLink = "/api/v2/target";
when(branchLinkProvider.get(REPOSITORY.getNamespaceAndName(), "develop")).thenReturn(sourceLink);
when(branchLinkProvider.get(REPOSITORY.getNamespaceAndName(), "master")).thenReturn(targetLink);
PullRequest pullRequest = TestData.createPullRequest();
PullRequestDto dto = mapper.map(pullRequest, REPOSITORY);
assertThat(dto.getLinks().isEmpty()).isFalse();
Optional<Link> sourceBranch = dto.getLinks().getLinkBy("sourceBranch");
assertThat(sourceBranch).isPresent();
assertThat(sourceBranch.get().getHref()).isEqualTo(sourceLink);
Optional<Link> targetBranch = dto.getLinks().getLinkBy("targetBranch");
assertThat(targetBranch).isPresent();
assertThat(targetBranch.get().getHref()).isEqualTo(targetLink);
}
Aggregations