Skip to content

Commit c20e3cd

Browse files
Remove manual pagination parameters
1 parent 7a90f00 commit c20e3cd

13 files changed

Lines changed: 28 additions & 138 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535
* Add support for container registry endpoints
3636
* Add support for `Environments::stopStale`
3737
* Add support for `last_activity_after` and `last_activity_before` in `Groups::projects`
38+
* Fix recent list endpoints to rely on the result pager for pagination
3839
* Fix `Projects::pipelines` date filters to include time information
3940

4041

‎src/Api/Deployments.php‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace Gitlab\Api;
1616

1717
use Symfony\Component\OptionsResolver\Options;
18+
use Symfony\Component\OptionsResolver\OptionsResolver;
1819

1920
class Deployments extends AbstractApi
2021
{
@@ -80,6 +81,12 @@ public function show(int|string $project_id, int $deployment_id): mixed
8081

8182
public function mergeRequests(int|string $project_id, int $deployment_id, array $parameters = []): mixed
8283
{
83-
return $this->get($this->getProjectPath($project_id, 'deployments/'.$deployment_id.'/merge_requests'), $parameters);
84+
$resolver = new OptionsResolver();
85+
$resolver->setDefined('state')
86+
->setAllowedValues('state', ['all', 'merged', 'opened', 'closed', 'locked'])
87+
;
88+
$resolver->setDefined('labels');
89+
90+
return $this->get($this->getProjectPath($project_id, 'deployments/'.$deployment_id.'/merge_requests'), $resolver->resolve($parameters));
8491
}
8592
}

‎src/Api/Groups.php‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -733,11 +733,9 @@ public function packages(int|string $group_id, array $parameters = []): mixed
733733
return $this->get('groups/'.self::encodePath($group_id).'/packages', $resolver->resolve($parameters));
734734
}
735735

736-
public function registryRepositories(int|string $group_id, array $parameters = []): mixed
736+
public function registryRepositories(int|string $group_id): mixed
737737
{
738-
$resolver = $this->createOptionsResolver();
739-
740-
return $this->get('groups/'.self::encodePath($group_id).'/registry/repositories', $resolver->resolve($parameters));
738+
return $this->get('groups/'.self::encodePath($group_id).'/registry/repositories');
741739
}
742740

743741
private function getGroupSearchResolver(): OptionsResolver

‎src/Api/PersonalAccessTokens.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class PersonalAccessTokens extends AbstractApi
3737
*/
3838
public function all(array $parameters = []): mixed
3939
{
40-
$resolver = $this->createOptionsResolver();
40+
$resolver = new OptionsResolver();
4141
$datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string {
4242
return $value->format('c');
4343
};

‎src/Api/Projects.php‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ public function deleteAllMergedBranches(int|string $project_id): mixed
11651165
*/
11661166
public function projectAccessTokens(int|string $project_id, array $parameters = []): mixed
11671167
{
1168-
$resolver = $this->createOptionsResolver();
1168+
$resolver = new OptionsResolver();
11691169
$datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string {
11701170
return $value->format('c');
11711171
};
@@ -1305,11 +1305,9 @@ public function updateJobTokenScope(int|string $project_id, bool $enabled): mixe
13051305
return $this->patch($this->getProjectPath($project_id, 'job_token_scope'), ['enabled' => $enabled]);
13061306
}
13071307

1308-
public function jobTokenScopeAllowlistProjects(int|string $project_id, array $parameters = []): mixed
1308+
public function jobTokenScopeAllowlistProjects(int|string $project_id): mixed
13091309
{
1310-
$resolver = $this->createOptionsResolver();
1311-
1312-
return $this->get($this->getProjectPath($project_id, 'job_token_scope/allowlist'), $resolver->resolve($parameters));
1310+
return $this->get($this->getProjectPath($project_id, 'job_token_scope/allowlist'));
13131311
}
13141312

13151313
public function addJobTokenScopeAllowlistProject(int|string $project_id, int $target_project_id): mixed
@@ -1325,11 +1323,9 @@ public function removeJobTokenScopeAllowlistProject(int|string $project_id, int
13251323
return $this->delete($this->getProjectPath($project_id, 'job_token_scope/allowlist/'.self::encodePath($target_project_id)));
13261324
}
13271325

1328-
public function jobTokenScopeAllowlistGroups(int|string $project_id, array $parameters = []): mixed
1326+
public function jobTokenScopeAllowlistGroups(int|string $project_id): mixed
13291327
{
1330-
$resolver = $this->createOptionsResolver();
1331-
1332-
return $this->get($this->getProjectPath($project_id, 'job_token_scope/groups_allowlist'), $resolver->resolve($parameters));
1328+
return $this->get($this->getProjectPath($project_id, 'job_token_scope/groups_allowlist'));
13331329
}
13341330

13351331
public function addJobTokenScopeAllowlistGroup(int|string $project_id, int $target_group_id): mixed
@@ -1354,7 +1350,7 @@ public function removeJobTokenScopeAllowlistGroup(int|string $project_id, int $t
13541350
*/
13551351
public function registryRepositories(int|string $project_id, array $parameters = []): mixed
13561352
{
1357-
$resolver = $this->createOptionsResolver();
1353+
$resolver = new OptionsResolver();
13581354
$booleanNormalizer = function (Options $resolver, $value): string {
13591355
return $value ? 'true' : 'false';
13601356
};

‎src/Api/Registry.php‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,9 @@ public function removeRepository(int|string $project_id, int $repository_id): mi
3939
return $this->delete($this->getProjectPath($project_id, 'registry/repositories/'.self::encodePath($repository_id)));
4040
}
4141

42-
public function repositoryTags(int|string $project_id, int $repository_id, array $parameters = []): mixed
42+
public function repositoryTags(int|string $project_id, int $repository_id): mixed
4343
{
44-
$resolver = $this->createOptionsResolver();
45-
46-
return $this->get(
47-
$this->getProjectPath($project_id, 'registry/repositories/'.self::encodePath($repository_id).'/tags'),
48-
$resolver->resolve($parameters)
49-
);
44+
return $this->get($this->getProjectPath($project_id, 'registry/repositories/'.self::encodePath($repository_id).'/tags'));
5045
}
5146

5247
public function repositoryTag(int|string $project_id, int $repository_id, string $tag_name): mixed

‎src/Api/Users.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace Gitlab\Api;
1616

1717
use Symfony\Component\OptionsResolver\Options;
18+
use Symfony\Component\OptionsResolver\OptionsResolver;
1819

1920
class Users extends AbstractApi
2021
{
@@ -177,7 +178,7 @@ public function usersProjects(int $id, array $parameters = []): mixed
177178
*/
178179
public function usersContributedProjects(int|string $id, array $parameters = []): mixed
179180
{
180-
$resolver = $this->createOptionsResolver();
181+
$resolver = new OptionsResolver();
181182
$booleanNormalizer = function (Options $resolver, $value): string {
182183
return $value ? 'true' : 'false';
183184
};

‎tests/Api/DeploymentsTest.php‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ public function shouldGetDeploymentMergeRequestsWithParameters(): void
135135
$parameters = [
136136
'state' => 'merged',
137137
'labels' => 'release,backend',
138-
'page' => 2,
139-
'per_page' => 25,
140138
];
141139

142140
$api = $this->getApiMock();

‎tests/Api/GroupsTest.php‎

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -782,31 +782,13 @@ public function shouldGetGroupRegistryRepositories(): void
782782
$api = $this->getApiMock();
783783
$api->expects($this->once())
784784
->method('get')
785-
->with('groups/1/registry/repositories', [])
785+
->with('groups/1/registry/repositories')
786786
->willReturn($expectedArray)
787787
;
788788

789789
$this->assertEquals($expectedArray, $api->registryRepositories(1));
790790
}
791791

792-
#[Test]
793-
public function shouldGetGroupRegistryRepositoriesWithPagination(): void
794-
{
795-
$expectedArray = [
796-
['id' => 1, 'name' => 'A registry'],
797-
['id' => 2, 'name' => 'Another registry'],
798-
];
799-
800-
$api = $this->getApiMock();
801-
$api->expects($this->once())
802-
->method('get')
803-
->with('groups/1/registry/repositories', ['page' => 2, 'per_page' => 15])
804-
->willReturn($expectedArray)
805-
;
806-
807-
$this->assertEquals($expectedArray, $api->registryRepositories(1, ['page' => 2, 'per_page' => 15]));
808-
}
809-
810792
#[Test]
811793
public function shouldGetGroupMergeRequests(): void
812794
{

‎tests/Api/PersonalAccessTokensTest.php‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ public function shouldGetAllTokensWithFilters(): void
6565
'last_used_after' => $lastUsedAfter->format('c'),
6666
'last_used_before' => $lastUsedBefore->format('c'),
6767
'sort' => 'name_desc',
68-
'page' => 1,
69-
'per_page' => 10,
7068
])
7169
->willReturn($expectedArray)
7270
;
@@ -83,8 +81,6 @@ public function shouldGetAllTokensWithFilters(): void
8381
'last_used_after' => $lastUsedAfter,
8482
'last_used_before' => $lastUsedBefore,
8583
'sort' => 'name_desc',
86-
'page' => 1,
87-
'per_page' => 10,
8884
]));
8985
}
9086

0 commit comments

Comments
 (0)