Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions NGitLab.Mock.Tests/GroupsMockTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,21 @@ public async Task Test_group_created_at_date()
Assert.That(group.CreatedAt, Is.GreaterThanOrEqualTo(t1));
Assert.That(group.CreatedAt, Is.LessThanOrEqualTo(t2));
}

[Test]
public async Task Test_group_page()
{
using var server = CreateProjectHierarchy();
var client = server.CreateClient("user1");

var result = client.Groups.SearchProjectsAsync("tlg", new GroupProjectsQuery
{
Page = 3,
PerPage = 1,
IncludeSubGroups = true,
}).ToArray();

Assert.That(result, Has.Length.EqualTo(1));
Assert.That(result[0].Name, Is.EqualTo("p3"));
}
}
3 changes: 1 addition & 2 deletions NGitLab.Mock.Tests/ProjectSearchTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Linq;
using NGitLab.Mock.Config;
using NUnit.Framework;

Expand Down
11 changes: 11 additions & 0 deletions NGitLab.Mock/Clients/GroupClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ public async Task RestoreAsync(long id, CancellationToken cancellationToken = de

var projects = query?.IncludeSubGroups is true ? group.AllProjects : group.Projects;

var pageIndex = 0;
var perPage = query?.PerPage ?? 20;

if (query != null)
{
if (query.Archived != null)
Expand All @@ -238,6 +241,11 @@ public async Task RestoreAsync(long id, CancellationToken cancellationToken = de
projects = projects.Where(project => project.Visibility >= query.Visibility.Value);
}

if (query.Page.HasValue)
{
pageIndex = query.Page.Value - 1;
}

if (!string.IsNullOrEmpty(query.Search))
throw new NotImplementedException();

Expand All @@ -246,6 +254,9 @@ public async Task RestoreAsync(long id, CancellationToken cancellationToken = de
}

projects = projects.Where(project => project.CanUserViewProject(Context.User));
var lowerBound = pageIndex * perPage;

projects = projects.Skip(lowerBound);
return GitLabCollectionResponse.Create(projects.Select(project => project.ToClientProject(Context.User)).ToArray());
}
}
Expand Down
22 changes: 22 additions & 0 deletions NGitLab.Tests/GroupsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,28 @@ public async Task Test_group_projects_query_returns_archived()
Assert.That(projectResult.Id, Is.EqualTo(project.Id));
Assert.That(projectResult.Archived, Is.True);
}

[Test]
[NGitLabRetry]
public async Task Test_group_projects_query_page()
{
using var context = await GitLabTestContext.CreateAsync();
var groupClient = context.Client.Groups;

var group = context.CreateGroup();
var project1 = context.CreateProject(group.Id);
var project2 = context.CreateProject(group.Id);

var projects = groupClient.GetProjectsAsync(group.Id, new GroupProjectsQuery
{
Page = 2,
PerPage = 1,
Sort = "asc",
}).ToArray();

Assert.That(projects, Has.Length.EqualTo(1));
Assert.That(projects[0].Id, Is.EqualTo(project2.Id));
}

[Test]
[NGitLabRetry]
Expand Down
2 changes: 1 addition & 1 deletion NGitLab/Impl/GroupsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public GitLabCollectionResponse<Project> GetProjectsAsync(long groupId, GroupPro

public GitLabCollectionResponse<Project> SearchProjectsAsync(GroupId groupId, GroupProjectsQuery query)
{
var url = CreateGetProjectsUrl(groupId, query);
var url = CreateGetProjectsUrl(groupId, query, page: query?.Page, perPage: query?.PerPage);
return _api.Get().GetAllAsync<Project>(url);
}

Expand Down
10 changes: 10 additions & 0 deletions NGitLab/Models/GroupProjectsQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,14 @@ public sealed class GroupProjectsQuery
/// Return only projects that have security reports artifacts present in any of their builds. This means “projects with security reports enabled”. Default is false
/// </summary>
public bool? WithSecurityReports { get; set; }

/// <summary>
/// Specifies how many records per page (GitLab supports a maximum of 100 items per page and defaults to 20).
/// </summary>
public int? PerPage { get; set; }

/// <summary>
/// Specifies the start page.
/// </summary>
public int? Page { get; set; }
}
4 changes: 4 additions & 0 deletions NGitLab/PublicAPI/net10.0/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,10 @@ NGitLab.Models.GroupProjectsQuery.OrderBy.get -> string
NGitLab.Models.GroupProjectsQuery.OrderBy.set -> void
NGitLab.Models.GroupProjectsQuery.Owned.get -> bool?
NGitLab.Models.GroupProjectsQuery.Owned.set -> void
NGitLab.Models.GroupProjectsQuery.Page.get -> int?
NGitLab.Models.GroupProjectsQuery.Page.set -> void
NGitLab.Models.GroupProjectsQuery.PerPage.get -> int?
NGitLab.Models.GroupProjectsQuery.PerPage.set -> void
NGitLab.Models.GroupProjectsQuery.Search.get -> string
NGitLab.Models.GroupProjectsQuery.Search.set -> void
NGitLab.Models.GroupProjectsQuery.Simple.get -> bool?
Expand Down
4 changes: 4 additions & 0 deletions NGitLab/PublicAPI/net472/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2288,6 +2288,10 @@ NGitLab.Models.GroupProjectsQuery.OrderBy.get -> string
NGitLab.Models.GroupProjectsQuery.OrderBy.set -> void
NGitLab.Models.GroupProjectsQuery.Owned.get -> bool?
NGitLab.Models.GroupProjectsQuery.Owned.set -> void
NGitLab.Models.GroupProjectsQuery.Page.get -> int?
NGitLab.Models.GroupProjectsQuery.Page.set -> void
NGitLab.Models.GroupProjectsQuery.PerPage.get -> int?
NGitLab.Models.GroupProjectsQuery.PerPage.set -> void
NGitLab.Models.GroupProjectsQuery.Search.get -> string
NGitLab.Models.GroupProjectsQuery.Search.set -> void
NGitLab.Models.GroupProjectsQuery.Simple.get -> bool?
Expand Down
4 changes: 4 additions & 0 deletions NGitLab/PublicAPI/net8.0/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,10 @@ NGitLab.Models.GroupProjectsQuery.OrderBy.get -> string
NGitLab.Models.GroupProjectsQuery.OrderBy.set -> void
NGitLab.Models.GroupProjectsQuery.Owned.get -> bool?
NGitLab.Models.GroupProjectsQuery.Owned.set -> void
NGitLab.Models.GroupProjectsQuery.Page.get -> int?
NGitLab.Models.GroupProjectsQuery.Page.set -> void
NGitLab.Models.GroupProjectsQuery.PerPage.get -> int?
NGitLab.Models.GroupProjectsQuery.PerPage.set -> void
NGitLab.Models.GroupProjectsQuery.Search.get -> string
NGitLab.Models.GroupProjectsQuery.Search.set -> void
NGitLab.Models.GroupProjectsQuery.Simple.get -> bool?
Expand Down
4 changes: 4 additions & 0 deletions NGitLab/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2288,6 +2288,10 @@ NGitLab.Models.GroupProjectsQuery.OrderBy.get -> string
NGitLab.Models.GroupProjectsQuery.OrderBy.set -> void
NGitLab.Models.GroupProjectsQuery.Owned.get -> bool?
NGitLab.Models.GroupProjectsQuery.Owned.set -> void
NGitLab.Models.GroupProjectsQuery.Page.get -> int?
NGitLab.Models.GroupProjectsQuery.Page.set -> void
NGitLab.Models.GroupProjectsQuery.PerPage.get -> int?
NGitLab.Models.GroupProjectsQuery.PerPage.set -> void
NGitLab.Models.GroupProjectsQuery.Search.get -> string
NGitLab.Models.GroupProjectsQuery.Search.set -> void
NGitLab.Models.GroupProjectsQuery.Simple.get -> bool?
Expand Down
Loading