Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Add support for container registry endpoints
* Add support for `Environments::stopStale`
* Add support for `last_activity_after` and `last_activity_before` in `Groups::projects`
* Fix recent list endpoints to rely on the result pager for pagination
* Fix `Projects::pipelines` date filters to include time information


Expand Down
16 changes: 15 additions & 1 deletion src/Api/Deployments.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Gitlab\Api;

use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

class Deployments extends AbstractApi
{
Expand Down Expand Up @@ -78,8 +79,21 @@ public function show(int|string $project_id, int $deployment_id): mixed
return $this->get($this->getProjectPath($project_id, 'deployments/'.$deployment_id));
}

/**
* @param array $parameters {
*
* @var string $state return all merge requests or just those that are opened, closed, locked, or merged
* @var string $labels return merge requests matching a comma separated list of labels
* }
*/
public function mergeRequests(int|string $project_id, int $deployment_id, array $parameters = []): mixed
{
return $this->get($this->getProjectPath($project_id, 'deployments/'.$deployment_id.'/merge_requests'), $parameters);
$resolver = new OptionsResolver();
$resolver->setDefined('state')
->setAllowedValues('state', ['all', 'merged', 'opened', 'closed', 'locked'])
;
$resolver->setDefined('labels');

return $this->get($this->getProjectPath($project_id, 'deployments/'.$deployment_id.'/merge_requests'), $resolver->resolve($parameters));
}
}
6 changes: 2 additions & 4 deletions src/Api/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -733,11 +733,9 @@ public function packages(int|string $group_id, array $parameters = []): mixed
return $this->get('groups/'.self::encodePath($group_id).'/packages', $resolver->resolve($parameters));
}

public function registryRepositories(int|string $group_id, array $parameters = []): mixed
public function registryRepositories(int|string $group_id): mixed
{
$resolver = $this->createOptionsResolver();

return $this->get('groups/'.self::encodePath($group_id).'/registry/repositories', $resolver->resolve($parameters));
return $this->get('groups/'.self::encodePath($group_id).'/registry/repositories');
}

private function getGroupSearchResolver(): OptionsResolver
Expand Down
2 changes: 1 addition & 1 deletion src/Api/PersonalAccessTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PersonalAccessTokens extends AbstractApi
*/
public function all(array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
$resolver = new OptionsResolver();
$datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string {
return $value->format('c');
};
Expand Down
16 changes: 6 additions & 10 deletions src/Api/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ public function deleteAllMergedBranches(int|string $project_id): mixed
*/
public function projectAccessTokens(int|string $project_id, array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
$resolver = new OptionsResolver();
$datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string {
return $value->format('c');
};
Expand Down Expand Up @@ -1305,11 +1305,9 @@ public function updateJobTokenScope(int|string $project_id, bool $enabled): mixe
return $this->patch($this->getProjectPath($project_id, 'job_token_scope'), ['enabled' => $enabled]);
}

public function jobTokenScopeAllowlistProjects(int|string $project_id, array $parameters = []): mixed
public function jobTokenScopeAllowlistProjects(int|string $project_id): mixed
{
$resolver = $this->createOptionsResolver();

return $this->get($this->getProjectPath($project_id, 'job_token_scope/allowlist'), $resolver->resolve($parameters));
return $this->get($this->getProjectPath($project_id, 'job_token_scope/allowlist'));
}

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

public function jobTokenScopeAllowlistGroups(int|string $project_id, array $parameters = []): mixed
public function jobTokenScopeAllowlistGroups(int|string $project_id): mixed
{
$resolver = $this->createOptionsResolver();

return $this->get($this->getProjectPath($project_id, 'job_token_scope/groups_allowlist'), $resolver->resolve($parameters));
return $this->get($this->getProjectPath($project_id, 'job_token_scope/groups_allowlist'));
}

public function addJobTokenScopeAllowlistGroup(int|string $project_id, int $target_group_id): mixed
Expand All @@ -1354,7 +1350,7 @@ public function removeJobTokenScopeAllowlistGroup(int|string $project_id, int $t
*/
public function registryRepositories(int|string $project_id, array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
$resolver = new OptionsResolver();
$booleanNormalizer = function (Options $resolver, $value): string {
return $value ? 'true' : 'false';
};
Expand Down
9 changes: 2 additions & 7 deletions src/Api/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,9 @@ public function removeRepository(int|string $project_id, int $repository_id): mi
return $this->delete($this->getProjectPath($project_id, 'registry/repositories/'.self::encodePath($repository_id)));
}

public function repositoryTags(int|string $project_id, int $repository_id, array $parameters = []): mixed
public function repositoryTags(int|string $project_id, int $repository_id): mixed
{
$resolver = $this->createOptionsResolver();

return $this->get(
$this->getProjectPath($project_id, 'registry/repositories/'.self::encodePath($repository_id).'/tags'),
$resolver->resolve($parameters)
);
return $this->get($this->getProjectPath($project_id, 'registry/repositories/'.self::encodePath($repository_id).'/tags'));
}

public function repositoryTag(int|string $project_id, int $repository_id, string $tag_name): mixed
Expand Down
3 changes: 2 additions & 1 deletion src/Api/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Gitlab\Api;

use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

class Users extends AbstractApi
{
Expand Down Expand Up @@ -177,7 +178,7 @@ public function usersProjects(int $id, array $parameters = []): mixed
*/
public function usersContributedProjects(int|string $id, array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
$resolver = new OptionsResolver();
$booleanNormalizer = function (Options $resolver, $value): string {
return $value ? 'true' : 'false';
};
Expand Down
2 changes: 0 additions & 2 deletions tests/Api/DeploymentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ public function shouldGetDeploymentMergeRequestsWithParameters(): void
$parameters = [
'state' => 'merged',
'labels' => 'release,backend',
'page' => 2,
'per_page' => 25,
];

$api = $this->getApiMock();
Expand Down
20 changes: 1 addition & 19 deletions tests/Api/GroupsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -782,31 +782,13 @@ public function shouldGetGroupRegistryRepositories(): void
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('groups/1/registry/repositories', [])
->with('groups/1/registry/repositories')
->willReturn($expectedArray)
;

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

#[Test]
public function shouldGetGroupRegistryRepositoriesWithPagination(): void
{
$expectedArray = [
['id' => 1, 'name' => 'A registry'],
['id' => 2, 'name' => 'Another registry'],
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('groups/1/registry/repositories', ['page' => 2, 'per_page' => 15])
->willReturn($expectedArray)
;

$this->assertEquals($expectedArray, $api->registryRepositories(1, ['page' => 2, 'per_page' => 15]));
}

#[Test]
public function shouldGetGroupMergeRequests(): void
{
Expand Down
4 changes: 0 additions & 4 deletions tests/Api/PersonalAccessTokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ public function shouldGetAllTokensWithFilters(): void
'last_used_after' => $lastUsedAfter->format('c'),
'last_used_before' => $lastUsedBefore->format('c'),
'sort' => 'name_desc',
'page' => 1,
'per_page' => 10,
])
->willReturn($expectedArray)
;
Expand All @@ -83,8 +81,6 @@ public function shouldGetAllTokensWithFilters(): void
'last_used_after' => $lastUsedAfter,
'last_used_before' => $lastUsedBefore,
'sort' => 'name_desc',
'page' => 1,
'per_page' => 10,
]));
}

Expand Down
61 changes: 2 additions & 59 deletions tests/Api/ProjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2678,8 +2678,6 @@ public function shouldGetProjectAccessTokensWithFilters(): void
'last_used_after' => $lastUsedAfter->format('c'),
'last_used_before' => $lastUsedBefore->format('c'),
'sort' => 'name_desc',
'page' => 1,
'per_page' => 10,
])
->willReturn($expectedArray);

Expand All @@ -2694,8 +2692,6 @@ public function shouldGetProjectAccessTokensWithFilters(): void
'last_used_after' => $lastUsedAfter,
'last_used_before' => $lastUsedBefore,
'sort' => 'name_desc',
'page' => 1,
'per_page' => 10,
]));
}

Expand Down Expand Up @@ -2878,30 +2874,12 @@ public function shouldGetJobTokenScopeAllowlistProjects(): void
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/1/job_token_scope/allowlist', [])
->with('projects/1/job_token_scope/allowlist')
->willReturn($expectedArray);

$this->assertEquals($expectedArray, $api->jobTokenScopeAllowlistProjects(1));
}

#[Test]
public function shouldGetJobTokenScopeAllowlistProjectsWithPagination(): void
{
$expectedArray = [[
'id' => 4,
'name' => 'Diaspora Client',
'web_url' => 'https://gitlab.example.com/diaspora/diaspora-client',
]];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/1/job_token_scope/allowlist', ['page' => 2, 'per_page' => 15])
->willReturn($expectedArray);

$this->assertEquals($expectedArray, $api->jobTokenScopeAllowlistProjects(1, ['page' => 2, 'per_page' => 15]));
}

#[Test]
public function shouldAddJobTokenScopeAllowlistProject(): void
{
Expand Down Expand Up @@ -2945,30 +2923,12 @@ public function shouldGetJobTokenScopeAllowlistGroups(): void
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/1/job_token_scope/groups_allowlist', [])
->with('projects/1/job_token_scope/groups_allowlist')
->willReturn($expectedArray);

$this->assertEquals($expectedArray, $api->jobTokenScopeAllowlistGroups(1));
}

#[Test]
public function shouldGetJobTokenScopeAllowlistGroupsWithPagination(): void
{
$expectedArray = [[
'id' => 4,
'name' => 'namegroup',
'web_url' => 'https://gitlab.example.com/groups/diaspora/diaspora-group',
]];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/1/job_token_scope/groups_allowlist', ['page' => 2, 'per_page' => 15])
->willReturn($expectedArray);

$this->assertEquals($expectedArray, $api->jobTokenScopeAllowlistGroups(1, ['page' => 2, 'per_page' => 15]));
}

#[Test]
public function shouldAddJobTokenScopeAllowlistGroup(): void
{
Expand Down Expand Up @@ -3034,23 +2994,6 @@ public function shouldGetProjectRegistryRepositoriesWithTags(): void
$this->assertEquals($expectedArray, $api->registryRepositories(123, ['tags' => true, 'tags_count' => true]));
}

#[Test]
public function shouldGetProjectRegistryRepositoriesWithPagination(): void
{
$expectedArray = [
['id' => 1, 'name' => 'A registry'],
['id' => 2, 'name' => 'Another registry'],
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/123/registry/repositories', ['page' => 2, 'per_page' => 15])
->willReturn($expectedArray);

$this->assertEquals($expectedArray, $api->registryRepositories(123, ['page' => 2, 'per_page' => 15]));
}

#[Test]
public function shouldUploadAvatar(): void
{
Expand Down
19 changes: 1 addition & 18 deletions tests/Api/RegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,12 @@ public function shouldGetRepositoryTags(): void
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/1/registry/repositories/2/tags', [])
->with('projects/1/registry/repositories/2/tags')
->willReturn($expectedArray);

$this->assertEquals($expectedArray, $api->repositoryTags(1, 2));
}

#[Test]
public function shouldGetRepositoryTagsWithPagination(): void
{
$expectedArray = [
['name' => 'v1.0.0', 'path' => 'group/project:v1.0.0'],
['name' => 'v1.1.0', 'path' => 'group/project:v1.1.0'],
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/1/registry/repositories/2/tags', ['page' => 2, 'per_page' => 15])
->willReturn($expectedArray);

$this->assertEquals($expectedArray, $api->repositoryTags(1, 2, ['page' => 2, 'per_page' => 15]));
}

#[Test]
public function shouldGetRepositoryTag(): void
{
Expand Down
14 changes: 2 additions & 12 deletions tests/Api/UsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,6 @@ public function shouldShowUsersContributedProjectsByUsername(): void
$this->assertEquals($expectedArray, $api->usersContributedProjects('matt'));
}

#[Test]
public function shouldShowUsersContributedProjectsWithLimit(): void
{
$expectedArray = [$this->getUsersProjectsData()[0]];

$api = $this->getUsersProjectsRequestMock('users/1/contributed_projects', $expectedArray, ['per_page' => 1]);

$this->assertEquals($expectedArray, $api->usersContributedProjects(1, ['per_page' => 1]));
}

#[Test]
public function shouldGetAllUsersContributedProjectsSortedByStars(): void
{
Expand All @@ -325,12 +315,12 @@ public function shouldGetAllUsersContributedProjectsSortedByStars(): void
$api = $this->getUsersProjectsRequestMock(
'users/1/contributed_projects',
$expectedArray,
['page' => 1, 'per_page' => 5, 'order_by' => 'star_count', 'sort' => 'desc']
['order_by' => 'star_count', 'sort' => 'desc']
);

$this->assertEquals(
$expectedArray,
$api->usersContributedProjects(1, ['page' => 1, 'per_page' => 5, 'order_by' => 'star_count', 'sort' => 'desc'])
$api->usersContributedProjects(1, ['order_by' => 'star_count', 'sort' => 'desc'])
);
}

Expand Down