Search in sources :

Example 1 with Link

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);
            }
        }
    }
}
Also used : Mapping(org.mapstruct.Mapping) RepositoryPermissions(sonia.scm.repository.RepositoryPermissions) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) MappingTarget(org.mapstruct.MappingTarget) Embedded.embeddedBuilder(de.otto.edison.hal.Embedded.embeddedBuilder) Links(de.otto.edison.hal.Links) Mapper(org.mapstruct.Mapper) Comment(com.cloudogu.scm.review.comment.service.Comment) Map(java.util.Map) Link.link(de.otto.edison.hal.Link.link) PermissionCheck(com.cloudogu.scm.review.PermissionCheck) RepositoryService(sonia.scm.repository.api.RepositoryService) CurrentUserResolver.getCurrentUser(com.cloudogu.scm.review.CurrentUserResolver.getCurrentUser) PullRequestService(com.cloudogu.scm.review.pullrequest.service.PullRequestService) URI(java.net.URI) Predicate(java.util.function.Predicate) Set(java.util.Set) MergeStrategy(sonia.scm.repository.api.MergeStrategy) Collectors(java.util.stream.Collectors) List(java.util.List) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) CommentService(com.cloudogu.scm.review.comment.service.CommentService) CommentType(com.cloudogu.scm.review.comment.service.CommentType) UserDisplayManager(sonia.scm.user.UserDisplayManager) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) NamespaceAndName(sonia.scm.repository.NamespaceAndName) PullRequestStatus(com.cloudogu.scm.review.pullrequest.service.PullRequestStatus) Embedded(de.otto.edison.hal.Embedded) HashMap(java.util.HashMap) DisplayUser(sonia.scm.user.DisplayUser) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) EdisonHalAppender(sonia.scm.web.EdisonHalAppender) CurrentUserResolver(com.cloudogu.scm.review.CurrentUserResolver) RepositoryServiceFactory(sonia.scm.repository.api.RepositoryServiceFactory) Named(javax.inject.Named) Command(sonia.scm.repository.api.Command) BaseMapper(sonia.scm.api.v2.resources.BaseMapper) BranchLinkProvider(sonia.scm.api.v2.resources.BranchLinkProvider) AfterMapping(org.mapstruct.AfterMapping) Context(org.mapstruct.Context) ObjectFactory(org.mapstruct.ObjectFactory) Links.linkingTo(de.otto.edison.hal.Links.linkingTo) User(sonia.scm.user.User) Collectors.toList(java.util.stream.Collectors.toList) ReviewMark(com.cloudogu.scm.review.pullrequest.service.ReviewMark) Link(de.otto.edison.hal.Link) Link(de.otto.edison.hal.Link) RepositoryService(sonia.scm.repository.api.RepositoryService)

Example 2 with Link

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);
}
Also used : PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Link(de.otto.edison.hal.Link) Test(org.junit.jupiter.api.Test)

Aggregations

PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)2 Link (de.otto.edison.hal.Link)2 CurrentUserResolver (com.cloudogu.scm.review.CurrentUserResolver)1 CurrentUserResolver.getCurrentUser (com.cloudogu.scm.review.CurrentUserResolver.getCurrentUser)1 PermissionCheck (com.cloudogu.scm.review.PermissionCheck)1 PullRequestResourceLinks (com.cloudogu.scm.review.PullRequestResourceLinks)1 Comment (com.cloudogu.scm.review.comment.service.Comment)1 CommentService (com.cloudogu.scm.review.comment.service.CommentService)1 CommentType (com.cloudogu.scm.review.comment.service.CommentType)1 PullRequestService (com.cloudogu.scm.review.pullrequest.service.PullRequestService)1 PullRequestStatus (com.cloudogu.scm.review.pullrequest.service.PullRequestStatus)1 ReviewMark (com.cloudogu.scm.review.pullrequest.service.ReviewMark)1 Strings (com.google.common.base.Strings)1 Embedded (de.otto.edison.hal.Embedded)1 Embedded.embeddedBuilder (de.otto.edison.hal.Embedded.embeddedBuilder)1 Link.link (de.otto.edison.hal.Link.link)1 Links (de.otto.edison.hal.Links)1 Links.linkingTo (de.otto.edison.hal.Links.linkingTo)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1