mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 01:15:44 +01:00
Create links to load more lines in diffs
This commit is contained in:
@@ -43,7 +43,11 @@ public class DiffResultDto extends HalRepresentation {
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
|
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
|
||||||
public static class FileDto {
|
public static class FileDto extends HalRepresentation {
|
||||||
|
|
||||||
|
public FileDto(Links links) {
|
||||||
|
super(links);
|
||||||
|
}
|
||||||
|
|
||||||
private String oldPath;
|
private String oldPath;
|
||||||
private String newPath;
|
private String newPath;
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ package sonia.scm.api.v2.resources;
|
|||||||
import com.github.sdorra.spotter.ContentTypes;
|
import com.github.sdorra.spotter.ContentTypes;
|
||||||
import com.github.sdorra.spotter.Language;
|
import com.github.sdorra.spotter.Language;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import de.otto.edison.hal.Links;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
import sonia.scm.repository.api.DiffFile;
|
import sonia.scm.repository.api.DiffFile;
|
||||||
import sonia.scm.repository.api.DiffLine;
|
import sonia.scm.repository.api.DiffLine;
|
||||||
@@ -38,6 +39,7 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.OptionalInt;
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
|
import static de.otto.edison.hal.Link.linkBuilder;
|
||||||
import static de.otto.edison.hal.Links.linkingTo;
|
import static de.otto.edison.hal.Links.linkingTo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,26 +56,30 @@ class DiffResultToDiffResultDtoMapper {
|
|||||||
|
|
||||||
public DiffResultDto mapForIncoming(Repository repository, DiffResult result, String source, String target) {
|
public DiffResultDto mapForIncoming(Repository repository, DiffResult result, String source, String target) {
|
||||||
DiffResultDto dto = new DiffResultDto(linkingTo().self(resourceLinks.incoming().diffParsed(repository.getNamespace(), repository.getName(), source, target)).build());
|
DiffResultDto dto = new DiffResultDto(linkingTo().self(resourceLinks.incoming().diffParsed(repository.getNamespace(), repository.getName(), source, target)).build());
|
||||||
setFiles(result, dto);
|
setFiles(result, dto, repository, target);
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiffResultDto mapForRevision(Repository repository, DiffResult result, String revision) {
|
public DiffResultDto mapForRevision(Repository repository, DiffResult result, String revision) {
|
||||||
DiffResultDto dto = new DiffResultDto(linkingTo().self(resourceLinks.diff().parsed(repository.getNamespace(), repository.getName(), revision)).build());
|
DiffResultDto dto = new DiffResultDto(linkingTo().self(resourceLinks.diff().parsed(repository.getNamespace(), repository.getName(), revision)).build());
|
||||||
setFiles(result, dto);
|
setFiles(result, dto, repository, revision);
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setFiles(DiffResult result, DiffResultDto dto) {
|
private void setFiles(DiffResult result, DiffResultDto dto, Repository repository, String revision) {
|
||||||
List<DiffResultDto.FileDto> files = new ArrayList<>();
|
List<DiffResultDto.FileDto> files = new ArrayList<>();
|
||||||
for (DiffFile file : result) {
|
for (DiffFile file : result) {
|
||||||
files.add(mapFile(file));
|
files.add(mapFile(file, repository, revision));
|
||||||
}
|
}
|
||||||
dto.setFiles(files);
|
dto.setFiles(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DiffResultDto.FileDto mapFile(DiffFile file) {
|
private DiffResultDto.FileDto mapFile(DiffFile file, Repository repository, String revision) {
|
||||||
DiffResultDto.FileDto dto = new DiffResultDto.FileDto();
|
Links.Builder links = linkingTo();
|
||||||
|
if (file.iterator().hasNext()) {
|
||||||
|
links.single(linkBuilder("lines", resourceLinks.source().content(repository.getNamespace(), repository.getName(), revision, file.getNewPath()) + "?start={start}?end={end}").build());
|
||||||
|
}
|
||||||
|
DiffResultDto.FileDto dto = new DiffResultDto.FileDto(links.build());
|
||||||
// ???
|
// ???
|
||||||
dto.setOldEndingNewLine(true);
|
dto.setOldEndingNewLine(true);
|
||||||
dto.setNewEndingNewLine(true);
|
dto.setNewEndingNewLine(true);
|
||||||
|
|||||||
@@ -86,6 +86,19 @@ class DiffResultToDiffResultDtoMapperTest {
|
|||||||
.isEqualTo("/scm/api/v2/repositories/space/X/diff/123/parsed");
|
.isEqualTo("/scm/api/v2/repositories/space/X/diff/123/parsed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldCreateLinkToLoadMoreLinesForFilesWithHunks() {
|
||||||
|
DiffResultDto dto = mapper.mapForRevision(REPOSITORY, createResult(), "123");
|
||||||
|
|
||||||
|
assertThat(dto.getFiles().get(0).getLinks().getLinkBy("lines"))
|
||||||
|
.isNotPresent();
|
||||||
|
assertThat(dto.getFiles().get(1).getLinks().getLinkBy("lines"))
|
||||||
|
.isPresent()
|
||||||
|
.get()
|
||||||
|
.extracting("href")
|
||||||
|
.isEqualTo("/scm/api/v2/repositories/space/X/content/123/B.ts?start={start}?end={end}");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldCreateSelfLinkForIncoming() {
|
void shouldCreateSelfLinkForIncoming() {
|
||||||
DiffResultDto dto = mapper.mapForIncoming(REPOSITORY, createResult(), "feature/some", "master");
|
DiffResultDto dto = mapper.mapForIncoming(REPOSITORY, createResult(), "feature/some", "master");
|
||||||
|
|||||||
Reference in New Issue
Block a user