Skip to content

Commit 5975617

Browse files
authored
Merge pull request #488 from Dyflexis/implement-optional-show-mr-params
Implement optional parameters for show single MR API endpoint
2 parents 053a5f3 + 8c60060 commit 5975617

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

lib/Gitlab/Api/MergeRequests.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,23 @@ public function all($project_id, array $parameters = [])
9797
/**
9898
* @param int $project_id
9999
* @param int $mr_id
100+
* @param array $parameters {
101+
* @var bool $include_diverged_commits_count Return the commits behind the target branch
102+
* @var bool $include_rebase_in_progress Return whether a rebase operation is in progress
103+
* }
100104
* @return mixed
101105
*/
102-
public function show($project_id, $mr_id)
106+
public function show($project_id, $mr_id, $parameters = [])
103107
{
104-
return $this->get($this->getProjectPath($project_id, 'merge_requests/'.$this->encodePath($mr_id)));
108+
$resolver = $this->createOptionsResolver();
109+
$resolver->setDefined('include_diverged_commits_count')
110+
->setAllowedTypes('include_diverged_commits_count', 'bool')
111+
;
112+
$resolver->setDefined('include_rebase_in_progress')
113+
->setAllowedTypes('include_rebase_in_progress', 'bool')
114+
;
115+
116+
return $this->get($this->getProjectPath($project_id, 'merge_requests/'.$this->encodePath($mr_id)), $resolver->resolve($parameters));
105117
}
106118

107119
/**

test/Gitlab/Tests/Api/MergeRequestsTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,31 @@ public function shouldShowMergeRequest()
108108

109109
$this->assertEquals($expectedArray, $api->show(1, 2));
110110
}
111+
112+
/**
113+
* @test
114+
*/
115+
public function shouldShowMergeRequestWithOptionalParameters()
116+
{
117+
$expectedArray = array(
118+
'id' => 2,
119+
'name' => 'A merge request',
120+
'diverged_commits_count' => 0,
121+
'rebase_in_progress' => false
122+
);
123+
124+
$api = $this->getApiMock();
125+
$api->expects($this->once())
126+
->method('get')
127+
->with('projects/1/merge_requests/2', array('include_diverged_commits_count' => true, 'include_rebase_in_progress' => true))
128+
->will($this->returnValue($expectedArray))
129+
;
130+
131+
$this->assertEquals($expectedArray, $api->show(1, 2, array(
132+
'include_diverged_commits_count' => true,
133+
'include_rebase_in_progress' => true
134+
)));
135+
}
111136

112137
/**
113138
* @test

0 commit comments

Comments
 (0)