Skip to content

Commit bfd48ac

Browse files
committed
Use OptionsResolver in Repositories::commits
1 parent 01ee70f commit bfd48ac

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

UPGRADE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ Use the `deployKeys`, `deployKey`, `addDeployKey`, `deleteDeployKey`, `removeDep
6767

6868
## `Gitlab\Api\Repositories` changes
6969

70-
* The `commits` page argument now start from 1 instead of 0.
7170
* The `commitBuilds` method have been removed. Use `Gitlab\Api\Projects::pipelines` instead.
71+
* The `commits` method second and subsequent arguments have been replaced by a single associative array of query string parameters.
7272

7373
## `Gitlab\Model\Project` changes
7474

lib/Gitlab/Api/Repositories.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,33 @@ public function updateRelease($project_id, $tag_name, $description)
129129

130130
/**
131131
* @param int $project_id
132-
* @param int $page
133-
* @param int $per_page
134-
* @param null $ref_name
132+
* @param array $parameters (
133+
*
134+
* @var string $ref_name The name of a repository branch or tag or if not given the default branch.
135+
* @var \DateTimeInterface $since Only commits after or on this date will be returned.
136+
* @var \DateTimeInterface $until Only commits before or on this date will be returned.
137+
* )
138+
*
135139
* @return mixed
136140
*/
137-
public function commits($project_id, $page = 1, $per_page = self::PER_PAGE, $ref_name = null)
141+
public function commits($project_id, array $parameters = [])
138142
{
139-
return $this->get($this->getProjectPath($project_id, 'repository/commits'), array(
140-
'page' => $page,
141-
'per_page' => $per_page,
142-
'ref_name' => $ref_name
143-
));
143+
$resolver = $this->createOptionsResolver();
144+
$datetimeNormalizer = function (\DateTimeInterface $value) {
145+
return $value->format('c');
146+
};
147+
148+
$resolver->setDefined('ref_name');
149+
$resolver->setDefined('since')
150+
->setAllowedTypes('since', \DateTimeInterface::class)
151+
->setNormalizer('since', $datetimeNormalizer)
152+
;
153+
$resolver->setDefined('until')
154+
->setAllowedTypes('until', \DateTimeInterface::class)
155+
->setNormalizer('until', $datetimeNormalizer)
156+
;
157+
158+
return $this->get($this->getProjectPath($project_id, 'repository/commits'), $resolver->resolve($parameters));
144159
}
145160

146161
/**

test/Gitlab/Tests/Api/RepositoriesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public function shouldGetCommits()
230230
$api = $this->getApiMock();
231231
$api->expects($this->once())
232232
->method('get')
233-
->with('projects/1/repository/commits', array('page' => 1, 'per_page' => AbstractApi::PER_PAGE, 'ref_name' => null))
233+
->with('projects/1/repository/commits', array())
234234
->will($this->returnValue($expectedArray))
235235
;
236236

@@ -254,7 +254,7 @@ public function shouldGetCommitsWithParams()
254254
->will($this->returnValue($expectedArray))
255255
;
256256

257-
$this->assertEquals($expectedArray, $api->commits(1, 2, 25, 'master'));
257+
$this->assertEquals($expectedArray, $api->commits(1, ['page' => 2, 'per_page' => 25, 'ref_name' => 'master']));
258258
}
259259

260260
/**

0 commit comments

Comments
 (0)