Skip to content

Commit 04251cf

Browse files
Bertrand Jaminm1guelpf
Bertrand Jamin
authored andcommitted
Add a "type" parameter for commitRefs
1 parent 73c12f2 commit 04251cf

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

lib/Gitlab/Api/Repositories.php

+25-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
class Repositories extends AbstractApi
77
{
8+
const TYPE_BRANCH = 'branch';
9+
const TYPE_TAG = 'tag';
10+
811
/**
912
* @param int $project_id
1013
* @param array $parameters
@@ -182,11 +185,16 @@ public function commit($project_id, $sha)
182185
/**
183186
* @param int $project_id
184187
* @param $sha
188+
* @param array $parameters
189+
*
185190
* @return mixed
186191
*/
187-
public function commitRefs($project_id, $sha)
192+
public function commitRefs($project_id, $sha, array $parameters = [])
188193
{
189-
return $this->get($this->getProjectPath($project_id, 'repository/commits/'.$this->encodePath($sha).'/refs'));
194+
$resolver = $this->createOptionsResolver();
195+
196+
return $this->get($this->getProjectPath($project_id, 'repository/commits/' . $this->encodePath($sha) . '/refs'),
197+
$resolver->resolve($parameters));
190198
}
191199

192200
/**
@@ -471,4 +479,19 @@ public function mergeBase($project_id, $refs)
471479
{
472480
return $this->get($this->getProjectPath($project_id, 'repository/merge_base'), array('refs' => $refs));
473481
}
482+
483+
protected function createOptionsResolver()
484+
{
485+
$allowedTypeValues = [
486+
self::TYPE_BRANCH,
487+
self::TYPE_TAG
488+
];
489+
490+
$resolver = parent::createOptionsResolver();
491+
$resolver->setDefined('type')
492+
->setAllowedTypes('type', 'string')
493+
->setAllowedValues('type', $allowedTypeValues);
494+
495+
return $resolver;
496+
}
474497
}

test/Gitlab/Tests/Api/RepositoriesTest.php

+34
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php namespace Gitlab\Tests\Api;
22

33
use Gitlab\Api\AbstractApi;
4+
use Gitlab\Api\Repositories;
45

56
class RepositoriesTest extends TestCase
67
{
@@ -322,6 +323,39 @@ public function shouldGetCommitRefs()
322323
$this->assertEquals($expectedArray, $api->commitRefs(1, 'abcd1234'));
323324
}
324325

326+
/**
327+
* @dataProvider dataGetCommitRefsWithParams
328+
* @test
329+
*
330+
* @param string $type
331+
* @param array $expectedArray
332+
*/
333+
public function shouldGetCommitRefsWithParams($type, array $expectedArray)
334+
{
335+
$api = $this->getApiMock();
336+
$api->expects($this->once())
337+
->method('get')
338+
->with('projects/1/repository/commits/abcd1234/refs', ['type' => $type])
339+
->will($this->returnValue($expectedArray))
340+
;
341+
342+
$this->assertEquals($expectedArray, $api->commitRefs(1, 'abcd1234', ['type' => $type]));
343+
}
344+
345+
public function dataGetCommitRefsWithParams()
346+
{
347+
return [
348+
'type_tag' => [
349+
'type' => Repositories::TYPE_TAG,
350+
'expectedArray' => [['type' => 'tag', 'name' => 'v1.1.0']]
351+
],
352+
'type_branch' => [
353+
'type' => Repositories::TYPE_BRANCH,
354+
'expectedArray' => [['type' => 'branch', 'name' => 'master']]
355+
],
356+
];
357+
}
358+
325359
/**
326360
* @test
327361
*/

0 commit comments

Comments
 (0)