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 @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Add support for personal access tokens
* Add support for `job_inputs` and `job_variables_attributes` in `Jobs::play`
* Add support for filters in `Projects::projectAccessTokens`
* Add support for listing merge requests associated with a commit


## [12.0.0] - 2025-02-23
Expand Down
19 changes: 19 additions & 0 deletions src/Api/Repositories.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,25 @@ public function commitRefs(int|string $project_id, string $sha, array $parameter
);
}

/**
* @param array $parameters {
*
* @var string $state Returns merge requests with the specified state: opened, closed, locked, or merged.
* }
*/
public function commitMergeRequests(int|string $project_id, string $sha, array $parameters = []): mixed
{
$resolver = new OptionsResolver();
$resolver->setDefined('state')
->setAllowedValues('state', ['opened', 'closed', 'locked', 'merged'])
;

return $this->get(
$this->getProjectPath($project_id, 'repository/commits/'.self::encodePath($sha).'/merge_requests'),
$resolver->resolve($parameters)
);
}

/**
* @param array $parameters {
*
Expand Down
35 changes: 35 additions & 0 deletions tests/Api/RepositoriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,41 @@ public function shouldGetCommitRefs(): void
$this->assertEquals($expectedArray, $api->commitRefs(1, 'abcd1234'));
}

#[Test]
public function shouldGetCommitMergeRequests(): void
{
$expectedArray = [
['id' => 1, 'title' => 'A merge request'],
['id' => 2, 'title' => 'Another merge request'],
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/1/repository/commits/abcd1234/merge_requests', [])
->willReturn($expectedArray)
;

$this->assertEquals($expectedArray, $api->commitMergeRequests(1, 'abcd1234'));
}

#[Test]
public function shouldGetCommitMergeRequestsWithState(): void
{
$expectedArray = [
['id' => 1, 'title' => 'A merge request', 'state' => 'opened'],
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/1/repository/commits/abcd1234/merge_requests', ['state' => 'opened'])
->willReturn($expectedArray)
;

$this->assertEquals($expectedArray, $api->commitMergeRequests(1, 'abcd1234', ['state' => 'opened']));
}

#[Test]
#[DataProvider('dataGetCommitRefsWithParams')]
public function shouldGetCommitRefsWithParams(string $type, array $expectedArray): void
Expand Down