mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-26 16:30:50 +01:00
Add table to diff view
Pushed-by: Florian Scholdei<florian.scholdei@cloudogu.com> Pushed-by: Viktor Egorov<viktor.egorov-extern@cloudogu.com> Pushed-by: k8s-git-ops<admin@cloudogu.com> Committed-by: Thomas Zerr<thomas.zerr@cloudogu.com> Co-authored-by: Viktor<viktor.egorov@triology.de> Co-authored-by: Thomas Zerr<thomas.zerr@cloudogu.com> Pushed-by: Thomas Zerr<thomas.zerr@cloudogu.com>
This commit is contained in:
@@ -31,10 +31,11 @@ import de.otto.edison.hal.Links;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import sonia.scm.repository.api.DiffResult;
|
||||
import sonia.scm.repository.api.DiffFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@@ -47,6 +48,7 @@ public class DiffResultDto extends HalRepresentation {
|
||||
private List<FileDto> files;
|
||||
private boolean partial;
|
||||
private DiffStatisticsDto statistics;
|
||||
private DiffTreeNodeDto tree;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@@ -81,6 +83,15 @@ public class DiffResultDto extends HalRepresentation {
|
||||
private int modified;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@AllArgsConstructor
|
||||
public static class DiffTreeNodeDto {
|
||||
private String nodeName;
|
||||
private Map<String, DiffTreeNodeDto> children;
|
||||
private Optional<DiffFile.ChangeType> changeType;
|
||||
}
|
||||
|
||||
@Data
|
||||
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
|
||||
public static class HunkDto {
|
||||
|
||||
@@ -35,7 +35,9 @@ import sonia.scm.repository.api.DiffResult;
|
||||
import sonia.scm.repository.api.Hunk;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
@@ -99,6 +101,19 @@ class DiffResultToDiffResultDtoMapper {
|
||||
}
|
||||
}
|
||||
|
||||
private DiffResultDto.DiffTreeNodeDto mapDiffTreeNodeDto(DiffResult.DiffTreeNode node) {
|
||||
if(node == null){
|
||||
return null;
|
||||
}
|
||||
Map<String, DiffResultDto.DiffTreeNodeDto> list = new LinkedHashMap<>();
|
||||
if(node.getChildren() != null) {
|
||||
for(Map.Entry<String, DiffResult.DiffTreeNode> entry : node.getChildren().entrySet()) {
|
||||
list.put(entry.getKey(), mapDiffTreeNodeDto(entry.getValue()));
|
||||
}
|
||||
}
|
||||
return new DiffResultDto.DiffTreeNodeDto(node.getNodeName(), list, node.getChangeType());
|
||||
}
|
||||
|
||||
private void setFiles(DiffResult result, DiffResultDto dto, Repository repository, String revision) {
|
||||
List<DiffResultDto.FileDto> files = new ArrayList<>();
|
||||
for (DiffFile file : result) {
|
||||
@@ -106,6 +121,8 @@ class DiffResultToDiffResultDtoMapper {
|
||||
}
|
||||
dto.setFiles(files);
|
||||
Optional<DiffResult.DiffStatistics> statistics = result.getStatistics();
|
||||
Optional<DiffResult.DiffTreeNode> diffTree = result.getDiffTree();
|
||||
|
||||
if (statistics.isPresent()) {
|
||||
DiffResult.DiffStatistics diffStatistics = statistics.get();
|
||||
DiffResultDto.DiffStatisticsDto diffStatisticsDto = new DiffResultDto.DiffStatisticsDto(
|
||||
@@ -115,6 +132,7 @@ class DiffResultToDiffResultDtoMapper {
|
||||
);
|
||||
dto.setStatistics(diffStatisticsDto);
|
||||
}
|
||||
diffTree.ifPresent(diffTreeNode -> dto.setTree(new DiffResultDto.DiffTreeNodeDto(diffTreeNode.getNodeName(), mapDiffTreeNodeDto(diffTreeNode).getChildren(), diffTreeNode.getChangeType())));
|
||||
dto.setPartial(result.isPartial());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user