Skip to content

Commit 2004705

Browse files
Matth--m1guelpf
authored andcommitted
Add straight option for compare api
1 parent 9a0ff6e commit 2004705

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lib/Gitlab/Api/Repositories.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,14 @@ public function postCommitBuildStatus($project_id, $sha, $state, array $params =
320320
* @param int $project_id
321321
* @param string $fromShaOrMaster
322322
* @param string $toShaOrMaster
323+
* @param bool $straight
323324
* @return mixed
324325
*/
325-
public function compare($project_id, $fromShaOrMaster, $toShaOrMaster)
326+
public function compare($project_id, $fromShaOrMaster, $toShaOrMaster, $straight = false)
326327
{
327328
return $this->get($this->getProjectPath(
328329
$project_id,
329-
'repository/compare?from='.$this->encodePath($fromShaOrMaster).'&to='.$this->encodePath($toShaOrMaster)
330+
'repository/compare?from='.$this->encodePath($fromShaOrMaster).'&to='.$this->encodePath($toShaOrMaster).'&straight='.$this->encodePath($straight ? 'true' : 'false')
330331
));
331332
}
332333

test/Gitlab/Tests/Api/RepositoriesTest.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,14 +455,31 @@ public function shouldCreateCommitCommentWithParams()
455455
/**
456456
* @test
457457
*/
458-
public function shouldCompare()
458+
public function shouldCompareStraight()
459459
{
460460
$expectedArray = array('commit' => 'object');
461461

462462
$api = $this->getApiMock();
463463
$api->expects($this->once())
464464
->method('get')
465-
->with('projects/1/repository/compare?from=master&to=feature')
465+
->with('projects/1/repository/compare?from=master&to=feature&straight=true')
466+
->will($this->returnValue($expectedArray))
467+
;
468+
469+
$this->assertEquals($expectedArray, $api->compare(1, 'master', 'feature', true));
470+
}
471+
472+
/**
473+
* @test
474+
*/
475+
public function shouldNotCompareStraight()
476+
{
477+
$expectedArray = array('commit' => 'object');
478+
479+
$api = $this->getApiMock();
480+
$api->expects($this->once())
481+
->method('get')
482+
->with('projects/1/repository/compare?from=master&to=feature&straight=false')
466483
->will($this->returnValue($expectedArray))
467484
;
468485

0 commit comments

Comments
 (0)