mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +01:00
Fix paging for log command
This commit is contained in:
@@ -100,9 +100,10 @@ public class BranchRootResource {
|
|||||||
try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) {
|
try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) {
|
||||||
Repository repository = repositoryService.getRepository();
|
Repository repository = repositoryService.getRepository();
|
||||||
RepositoryPermissions.read(repository).check();
|
RepositoryPermissions.read(repository).check();
|
||||||
ChangesetPagingResult changesets = repositoryService.getLogCommand()
|
ChangesetPagingResult changesets = new PagedLogCommandBuilder(repositoryService)
|
||||||
.setPagingStart(page)
|
.page(page)
|
||||||
.setPagingLimit(pageSize)
|
.pageSize(pageSize)
|
||||||
|
.create()
|
||||||
.setBranch(branchName)
|
.setBranch(branchName)
|
||||||
.getChangesets();
|
.getChangesets();
|
||||||
if (changesets != null && changesets.getChangesets() != null) {
|
if (changesets != null && changesets.getChangesets() != null) {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import sonia.scm.repository.Repository;
|
|||||||
import sonia.scm.repository.RepositoryNotFoundException;
|
import sonia.scm.repository.RepositoryNotFoundException;
|
||||||
import sonia.scm.repository.RepositoryPermissions;
|
import sonia.scm.repository.RepositoryPermissions;
|
||||||
import sonia.scm.repository.RevisionNotFoundException;
|
import sonia.scm.repository.RevisionNotFoundException;
|
||||||
|
import sonia.scm.repository.api.LogCommandBuilder;
|
||||||
import sonia.scm.repository.api.RepositoryService;
|
import sonia.scm.repository.api.RepositoryService;
|
||||||
import sonia.scm.repository.api.RepositoryServiceFactory;
|
import sonia.scm.repository.api.RepositoryServiceFactory;
|
||||||
import sonia.scm.web.VndMediaType;
|
import sonia.scm.web.VndMediaType;
|
||||||
@@ -59,9 +60,10 @@ public class ChangesetRootResource {
|
|||||||
try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) {
|
try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) {
|
||||||
Repository repository = repositoryService.getRepository();
|
Repository repository = repositoryService.getRepository();
|
||||||
RepositoryPermissions.read(repository).check();
|
RepositoryPermissions.read(repository).check();
|
||||||
ChangesetPagingResult changesets = repositoryService.getLogCommand()
|
ChangesetPagingResult changesets = new PagedLogCommandBuilder(repositoryService)
|
||||||
.setPagingStart(page)
|
.page(page)
|
||||||
.setPagingLimit(pageSize)
|
.pageSize(pageSize)
|
||||||
|
.create()
|
||||||
.getChangesets();
|
.getChangesets();
|
||||||
if (changesets != null && changesets.getChangesets() != null) {
|
if (changesets != null && changesets.getChangesets() != null) {
|
||||||
PageResult<Changeset> pageResult = new PageResult<>(changesets.getChangesets(), changesets.getTotal());
|
PageResult<Changeset> pageResult = new PageResult<>(changesets.getChangesets(), changesets.getTotal());
|
||||||
|
|||||||
@@ -73,9 +73,10 @@ public class FileHistoryRootResource {
|
|||||||
try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) {
|
try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) {
|
||||||
log.info("Get changesets of the file {} and revision {}", path, revision);
|
log.info("Get changesets of the file {} and revision {}", path, revision);
|
||||||
Repository repository = repositoryService.getRepository();
|
Repository repository = repositoryService.getRepository();
|
||||||
ChangesetPagingResult changesets = repositoryService.getLogCommand()
|
ChangesetPagingResult changesets = new PagedLogCommandBuilder(repositoryService)
|
||||||
.setPagingStart(page)
|
.page(page)
|
||||||
.setPagingLimit(pageSize)
|
.pageSize(pageSize)
|
||||||
|
.create()
|
||||||
.setPath(path)
|
.setPath(path)
|
||||||
.setStartChangeset(revision)
|
.setStartChangeset(revision)
|
||||||
.getChangesets();
|
.getChangesets();
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package sonia.scm.api.v2.resources;
|
||||||
|
|
||||||
|
import sonia.scm.repository.api.LogCommandBuilder;
|
||||||
|
import sonia.scm.repository.api.RepositoryService;
|
||||||
|
|
||||||
|
class PagedLogCommandBuilder {
|
||||||
|
private final RepositoryService repositoryService;
|
||||||
|
private int page;
|
||||||
|
private int pageSize ;
|
||||||
|
|
||||||
|
PagedLogCommandBuilder(RepositoryService repositoryService) {
|
||||||
|
this.repositoryService = repositoryService;
|
||||||
|
}
|
||||||
|
|
||||||
|
PagedLogCommandBuilder page(int page) {
|
||||||
|
this.page = page;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
PagedLogCommandBuilder pageSize(int pageSize) {
|
||||||
|
this.pageSize = pageSize;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogCommandBuilder create() {
|
||||||
|
return repositoryService.getLogCommand()
|
||||||
|
.setPagingStart(page * pageSize)
|
||||||
|
.setPagingLimit(pageSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -109,8 +109,8 @@ public class ChangesetRootResourceTest extends RepositoryTestBase {
|
|||||||
List<Changeset> changesetList = Lists.newArrayList(new Changeset(id, Date.from(creationDate).getTime(), new Person(authorName, authorEmail), commit));
|
List<Changeset> changesetList = Lists.newArrayList(new Changeset(id, Date.from(creationDate).getTime(), new Person(authorName, authorEmail), commit));
|
||||||
when(changesetPagingResult.getChangesets()).thenReturn(changesetList);
|
when(changesetPagingResult.getChangesets()).thenReturn(changesetList);
|
||||||
when(changesetPagingResult.getTotal()).thenReturn(1);
|
when(changesetPagingResult.getTotal()).thenReturn(1);
|
||||||
when(logCommandBuilder.setPagingStart(anyInt())).thenReturn(logCommandBuilder);
|
when(logCommandBuilder.setPagingStart(0)).thenReturn(logCommandBuilder);
|
||||||
when(logCommandBuilder.setPagingLimit(anyInt())).thenReturn(logCommandBuilder);
|
when(logCommandBuilder.setPagingLimit(10)).thenReturn(logCommandBuilder);
|
||||||
when(logCommandBuilder.setBranch(anyString())).thenReturn(logCommandBuilder);
|
when(logCommandBuilder.setBranch(anyString())).thenReturn(logCommandBuilder);
|
||||||
when(logCommandBuilder.getChangesets()).thenReturn(changesetPagingResult);
|
when(logCommandBuilder.getChangesets()).thenReturn(changesetPagingResult);
|
||||||
MockHttpRequest request = MockHttpRequest
|
MockHttpRequest request = MockHttpRequest
|
||||||
@@ -126,6 +126,34 @@ public class ChangesetRootResourceTest extends RepositoryTestBase {
|
|||||||
assertTrue(response.getContentAsString().contains(String.format("\"description\":\"%s\"", commit)));
|
assertTrue(response.getContentAsString().contains(String.format("\"description\":\"%s\"", commit)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldGetSinglePageOfChangeSets() throws Exception {
|
||||||
|
String id = "revision_123";
|
||||||
|
Instant creationDate = Instant.now();
|
||||||
|
String authorName = "name";
|
||||||
|
String authorEmail = "em@i.l";
|
||||||
|
String commit = "my branch commit";
|
||||||
|
ChangesetPagingResult changesetPagingResult = mock(ChangesetPagingResult.class);
|
||||||
|
List<Changeset> changesetList = Lists.newArrayList(new Changeset(id, Date.from(creationDate).getTime(), new Person(authorName, authorEmail), commit));
|
||||||
|
when(changesetPagingResult.getChangesets()).thenReturn(changesetList);
|
||||||
|
when(changesetPagingResult.getTotal()).thenReturn(1);
|
||||||
|
when(logCommandBuilder.setPagingStart(20)).thenReturn(logCommandBuilder);
|
||||||
|
when(logCommandBuilder.setPagingLimit(10)).thenReturn(logCommandBuilder);
|
||||||
|
when(logCommandBuilder.setBranch(anyString())).thenReturn(logCommandBuilder);
|
||||||
|
when(logCommandBuilder.getChangesets()).thenReturn(changesetPagingResult);
|
||||||
|
MockHttpRequest request = MockHttpRequest
|
||||||
|
.get(CHANGESET_URL + "?page=2")
|
||||||
|
.accept(VndMediaType.CHANGESET_COLLECTION);
|
||||||
|
MockHttpResponse response = new MockHttpResponse();
|
||||||
|
dispatcher.invoke(request, response);
|
||||||
|
assertEquals(200, response.getStatus());
|
||||||
|
log.info("Response :{}", response.getContentAsString());
|
||||||
|
assertTrue(response.getContentAsString().contains(String.format("\"id\":\"%s\"", id)));
|
||||||
|
assertTrue(response.getContentAsString().contains(String.format("\"name\":\"%s\"", authorName)));
|
||||||
|
assertTrue(response.getContentAsString().contains(String.format("\"mail\":\"%s\"", authorEmail)));
|
||||||
|
assertTrue(response.getContentAsString().contains(String.format("\"description\":\"%s\"", commit)));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldGetChangeSet() throws Exception {
|
public void shouldGetChangeSet() throws Exception {
|
||||||
String id = "revision_123";
|
String id = "revision_123";
|
||||||
@@ -137,8 +165,6 @@ public class ChangesetRootResourceTest extends RepositoryTestBase {
|
|||||||
List<Changeset> changesetList = Lists.newArrayList(new Changeset(id, Date.from(creationDate).getTime(), new Person(authorName, authorEmail), commit));
|
List<Changeset> changesetList = Lists.newArrayList(new Changeset(id, Date.from(creationDate).getTime(), new Person(authorName, authorEmail), commit));
|
||||||
when(changesetPagingResult.getChangesets()).thenReturn(changesetList);
|
when(changesetPagingResult.getChangesets()).thenReturn(changesetList);
|
||||||
when(changesetPagingResult.getTotal()).thenReturn(1);
|
when(changesetPagingResult.getTotal()).thenReturn(1);
|
||||||
when(logCommandBuilder.setPagingStart(anyInt())).thenReturn(logCommandBuilder);
|
|
||||||
when(logCommandBuilder.setPagingLimit(anyInt())).thenReturn(logCommandBuilder);
|
|
||||||
when(logCommandBuilder.setEndChangeset(anyString())).thenReturn(logCommandBuilder);
|
when(logCommandBuilder.setEndChangeset(anyString())).thenReturn(logCommandBuilder);
|
||||||
when(logCommandBuilder.setStartChangeset(anyString())).thenReturn(logCommandBuilder);
|
when(logCommandBuilder.setStartChangeset(anyString())).thenReturn(logCommandBuilder);
|
||||||
when(logCommandBuilder.getChangesets()).thenReturn(changesetPagingResult);
|
when(logCommandBuilder.getChangesets()).thenReturn(changesetPagingResult);
|
||||||
|
|||||||
Reference in New Issue
Block a user