Skip to content

Implement optional parameters for show single MR API endpoint #488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
16 changes: 14 additions & 2 deletions lib/Gitlab/Api/MergeRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,23 @@ public function all($project_id, array $parameters = [])
/**
* @param int $project_id
* @param int $mr_id
* @param array $parameters {
* @var bool $include_diverged_commits_count Return the commits behind the target branch
* @var bool $include_rebase_in_progress Return whether a rebase operation is in progress
* }
* @return mixed
*/
public function show($project_id, $mr_id)
public function show($project_id, $mr_id, $parameters = [])
{
return $this->get($this->getProjectPath($project_id, 'merge_requests/'.$this->encodePath($mr_id)));
$resolver = $this->createOptionsResolver();
$resolver->setDefined('include_diverged_commits_count')
->setAllowedTypes('include_diverged_commits_count', 'bool')
;
$resolver->setDefined('include_rebase_in_progress')
->setAllowedTypes('include_rebase_in_progress', 'bool')
;

return $this->get($this->getProjectPath($project_id, 'merge_requests/'.$this->encodePath($mr_id)), $resolver->resolve($parameters));
}

/**
Expand Down
25 changes: 25 additions & 0 deletions test/Gitlab/Tests/Api/MergeRequestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,31 @@ public function shouldShowMergeRequest()

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

/**
* @test
*/
public function shouldShowMergeRequestWithOptionalParameters()
{
$expectedArray = array(
'id' => 2,
'name' => 'A merge request',
'diverged_commits_count' => 0,
'rebase_in_progress' => false
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/1/merge_requests/2', array('include_diverged_commits_count' => true, 'include_rebase_in_progress' => true))
->will($this->returnValue($expectedArray))
;

$this->assertEquals($expectedArray, $api->show(1, 2, array(
'include_diverged_commits_count' => true,
'include_rebase_in_progress' => true
)));
}

/**
* @test
Expand Down