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:
Thomas Zerr
2024-09-16 17:52:10 +02:00
parent 96466807be
commit 8f0ed74b7a
18 changed files with 547 additions and 35 deletions

View File

@@ -57,6 +57,8 @@ public class GitDiffResult implements DiffResult {
private final int offset;
private final Integer limit;
private DiffTreeNode tree;
public GitDiffResult(Repository scmRepository,
org.eclipse.jgit.lib.Repository repository,
Differ.Diff diff,
@@ -210,4 +212,32 @@ public class GitDiffResult implements DiffResult {
DiffStatistics stats = new DiffStatistics(addCounter, modifiedCounter, deletedCounter);
return Optional.of(stats);
}
@Override
public Optional<DiffTreeNode> getDiffTree() {
if (this.tree == null) {
tree = DiffTreeNode.createRootNode();
for (DiffEntry diffEntry : diffEntries) {
DiffEntry.Side side = DiffEntry.Side.NEW;
if (diffEntry.getChangeType() == DiffEntry.ChangeType.DELETE) {
side = DiffEntry.Side.OLD;
}
DiffEntry.ChangeType type = diffEntry.getChangeType();
String path = diffEntry.getPath(side);
tree.addChild(path, mapChangeType(type));
}
}
return Optional.of(tree);
}
private DiffFile.ChangeType mapChangeType(DiffEntry.ChangeType changeType) {
return switch (changeType) {
case ADD -> DiffFile.ChangeType.ADD;
case MODIFY -> DiffFile.ChangeType.MODIFY;
case DELETE -> DiffFile.ChangeType.DELETE;
case COPY -> DiffFile.ChangeType.COPY;
case RENAME -> DiffFile.ChangeType.RENAME;
};
}
}

View File

@@ -33,8 +33,10 @@ import sonia.scm.repository.api.IgnoreWhitespaceLevel;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.InstanceOfAssertFactories.OPTIONAL;
import static org.junit.Assert.assertEquals;
public class GitDiffResultCommandTest extends AbstractGitCommandTestBase {
@@ -189,6 +191,15 @@ public class GitDiffResultCommandTest extends AbstractGitCommandTestBase {
assertThat(diffResult.getStatistics()).get().extracting("added").isEqualTo(0);
}
@Test
public void shouldCreateFileTree() throws IOException {
DiffResult.DiffTreeNode root = DiffResult.DiffTreeNode.createRootNode();
root.addChild("a.txt", DiffFile.ChangeType.MODIFY);
root.addChild("b.txt", DiffFile.ChangeType.DELETE);
DiffResult diffResult = createDiffResult("3f76a12f08a6ba0dc988c68b7f0b2cd190efc3c4");
assertEquals(Optional.of(root),diffResult.getDiffTree());
}
@Test
public void shouldNotIgnoreWhiteSpace() throws IOException {
GitDiffResultCommand gitDiffResultCommand = new GitDiffResultCommand(createContext());