mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-05-07 05:16:04 +02: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());
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import sonia.scm.repository.api.IgnoreWhitespaceLevel;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
@@ -181,6 +182,7 @@ class DiffResultToDiffResultDtoMapperTest {
|
||||
void shouldMapStatistics() {
|
||||
DiffResult result = createResult();
|
||||
when(result.getStatistics()).thenReturn(of(new DiffResult.DiffStatistics(1, 2, 3)));
|
||||
when(result.getDiffTree()).thenReturn(of(DiffResult.DiffTreeNode.createRootNode()));
|
||||
|
||||
DiffResultDto.DiffStatisticsDto dto = mapper.mapForIncoming(REPOSITORY, result, "feature/some", "master").getStatistics();
|
||||
|
||||
@@ -189,6 +191,38 @@ class DiffResultToDiffResultDtoMapperTest {
|
||||
assertThat(dto.getDeleted()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldMapDiffTree() {
|
||||
DiffResult result = createResult();
|
||||
DiffResult.DiffTreeNode root = DiffResult.DiffTreeNode.createRootNode();
|
||||
root.addChild("a.txt", DiffFile.ChangeType.MODIFY);
|
||||
root.addChild("b.txt", DiffFile.ChangeType.DELETE);
|
||||
root.addChild("victory/road/c.txt", DiffFile.ChangeType.ADD);
|
||||
root.addChild("victory/road/d.txt", DiffFile.ChangeType.RENAME);
|
||||
root.addChild("indigo/plateau/e.txt", DiffFile.ChangeType.COPY);
|
||||
when(result.getDiffTree()).thenReturn(of(root));
|
||||
|
||||
DiffResultDto.DiffTreeNodeDto actualTree = mapper.mapForIncoming(REPOSITORY, result, "feature/some", "master").getTree();
|
||||
|
||||
DiffResultDto.DiffTreeNodeDto expectedTree = new DiffResultDto.DiffTreeNodeDto("", Map.of(
|
||||
"a.txt", new DiffResultDto.DiffTreeNodeDto("a.txt", Map.of(), Optional.of(DiffFile.ChangeType.MODIFY)),
|
||||
"b.txt", new DiffResultDto.DiffTreeNodeDto("b.txt", Map.of(),Optional.of(DiffFile.ChangeType.DELETE)),
|
||||
"victory", new DiffResultDto.DiffTreeNodeDto("victory", Map.of(
|
||||
"road", new DiffResultDto.DiffTreeNodeDto("road", Map.of(
|
||||
"c.txt", new DiffResultDto.DiffTreeNodeDto("c.txt", Map.of(), Optional.of(DiffFile.ChangeType.ADD)),
|
||||
"d.txt", new DiffResultDto.DiffTreeNodeDto("d.txt", Map.of(), Optional.of(DiffFile.ChangeType.RENAME))
|
||||
),Optional.empty())
|
||||
),Optional.empty()),
|
||||
"indigo", new DiffResultDto.DiffTreeNodeDto("indigo", Map.of(
|
||||
"plateau", new DiffResultDto.DiffTreeNodeDto("plateau", Map.of(
|
||||
"e.txt", new DiffResultDto.DiffTreeNodeDto("e.txt", Map.of(), Optional.of(DiffFile.ChangeType.COPY))
|
||||
), Optional.empty())
|
||||
), Optional.empty())
|
||||
), Optional.empty());
|
||||
|
||||
assertThat(actualTree).isEqualTo(expectedTree);
|
||||
}
|
||||
|
||||
private void mockPartialResult(DiffResult result) {
|
||||
when(result.getLimit()).thenReturn(of(10));
|
||||
when(result.getOffset()).thenReturn(20);
|
||||
|
||||
Reference in New Issue
Block a user