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 @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Add support for `with_custom_attributes` and `with_projects` in `Groups::show`
* Add support for project remote mirror read endpoints
* Add support for permanent project removal and project restoration
* Add support for `regex` and `sort` in `Repositories::branches`


## [12.0.0] - 2025-02-23
Expand Down
14 changes: 12 additions & 2 deletions src/Api/Repositories.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,24 @@ class Repositories extends AbstractApi
/**
* @param array $parameters {
*
* @var string $search
* @var string $search return branches matching the search string
* @var string $regex return branches matching an RE2 regex
* @var string $sort return branches sorted by name_asc, updated_asc, or updated_desc
* }
*/
public function branches(int|string $project_id, array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
$resolver->setDefined('search')
->setAllowedTypes('search', 'string');
->setAllowedTypes('search', 'string')
;
$resolver->setDefined('regex')
->setAllowedTypes('regex', 'string')
;
$resolver->setDefined('sort')
->setAllowedTypes('sort', 'string')
->setAllowedValues('sort', ['name_asc', 'updated_asc', 'updated_desc'])
;

return $this->get($this->getProjectPath($project_id, 'repository/branches'), $resolver->resolve($parameters));
}
Expand Down
22 changes: 22 additions & 0 deletions tests/Api/RepositoriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ public function shouldGetBranches(): void
$this->assertEquals($expectedArray, $api->branches(1, ['search' => '^term']));
}

#[Test]
public function shouldGetBranchesWithAdditionalParameters(): void
{
$expectedArray = [
['name' => 'release/1.0'],
['name' => 'release/1.1'],
];
$parameters = [
'regex' => '^release/.*',
'sort' => 'updated_desc',
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/1/repository/branches', $parameters)
->willReturn($expectedArray)
;

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

#[Test]
public function shouldGetBranch(): void
{
Expand Down