Add extension point to branches overview (#1888)

Prepare branches overview to show additional branch details.

Co-authored-by: René Pfeuffer <rene.pfeuffer@cloudogu.com>
This commit is contained in:
Eduard Heimbuch
2021-12-10 11:04:59 +01:00
committed by GitHub
parent b2d7ed88e4
commit b8d6c219ee
21 changed files with 249 additions and 78 deletions

View File

@@ -30,27 +30,27 @@ import de.otto.edison.hal.Links;
import org.mapstruct.Context;
import org.mapstruct.Mapper;
import org.mapstruct.ObjectFactory;
import sonia.scm.repository.BranchDetails;
import sonia.scm.repository.Repository;
import sonia.scm.repository.api.BranchDetailsCommandResult;
import sonia.scm.web.EdisonHalAppender;
import javax.inject.Inject;
import java.util.Optional;
@Mapper
public abstract class BranchDetailsMapper extends BaseMapper<BranchDetailsCommandResult, BranchDetailsDto> {
public abstract class BranchDetailsMapper extends BaseMapper<BranchDetails, BranchDetailsDto> {
@Inject
private ResourceLinks resourceLinks;
abstract BranchDetailsDto map(@Context Repository repository, String branchName, BranchDetailsCommandResult result);
abstract BranchDetailsDto map(@Context Repository repository, String branchName, BranchDetails result);
@ObjectFactory
BranchDetailsDto createDto(@Context Repository repository, String branchName, BranchDetailsCommandResult result) {
BranchDetailsDto createDto(@Context Repository repository, String branchName, BranchDetails result) {
Links.Builder linksBuilder = createLinks(repository, branchName);
Embedded.Builder embeddedBuilder = Embedded.embeddedBuilder();
applyEnrichers(new EdisonHalAppender(linksBuilder, embeddedBuilder), result, branchName, repository);
applyEnrichers(new EdisonHalAppender(linksBuilder, embeddedBuilder), result, repository);
return new BranchDetailsDto(linksBuilder.build(), embeddedBuilder.build());
}

View File

@@ -117,7 +117,7 @@ public class BranchDetailsResource {
) {
try (RepositoryService service = serviceFactory.create(new NamespaceAndName(namespace, name))) {
BranchDetailsCommandResult result = service.getBranchDetailsCommand().execute(branchName);
BranchDetailsDto dto = mapper.map(service.getRepository(), branchName, result);
BranchDetailsDto dto = mapper.map(service.getRepository(), branchName, result.getDetails());
return Response.ok(dto).build();
} catch (CommandNotSupportedException ex) {
return Response.status(Response.Status.BAD_REQUEST).build();
@@ -186,7 +186,7 @@ public class BranchDetailsResource {
for (String branch : branches) {
try {
BranchDetailsCommandResult result = branchDetailsCommand.execute(branch);
dtos.add(mapper.map(service.getRepository(), branch, result));
dtos.add(mapper.map(service.getRepository(), branch, result.getDetails()));
} catch (NotFoundException e) {
// we simply omit details for branches that do not exist
}