Skip to content

Commit f12eb89

Browse files
Revert "Revert "[11.5] Add from_project_id to Repositories::compare (#652)""
This reverts commit 55cb1b2.
1 parent c47bf9c commit f12eb89

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/Api/Repositories.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,20 +403,25 @@ public function postCommitBuildStatus($project_id, string $sha, string $state, a
403403
}
404404

405405
/**
406-
* @param int|string $project_id
407-
* @param string $fromShaOrMaster
408-
* @param string $toShaOrMaster
409-
* @param bool $straight
406+
* @param int|string $project_id
407+
* @param string $fromShaOrMaster
408+
* @param string $toShaOrMaster
409+
* @param bool $straight
410+
* @param string|null $fromProjectId
410411
*
411412
* @return mixed
412413
*/
413-
public function compare($project_id, string $fromShaOrMaster, string $toShaOrMaster, bool $straight = false)
414+
public function compare($project_id, string $fromShaOrMaster, string $toShaOrMaster, bool $straight = false, string $fromProjectId = null)
414415
{
415416
$params = [
416417
'from' => self::encodePath($fromShaOrMaster),
417418
'to' => self::encodePath($toShaOrMaster),
418419
'straight' => self::encodePath($straight ? 'true' : 'false'),
419420
];
421+
422+
if (null !== $fromProjectId) {
423+
$params['from_project_id'] = self::encodePath($fromProjectId);
424+
}
420425

421426
return $this->get($this->getProjectPath($project_id, 'repository/compare'), $params);
422427
}

tests/Api/RepositoriesTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,23 @@ public function shouldNotCompareStraight(): void
541541
$this->assertEquals($expectedArray, $api->compare(1, 'master', 'feature'));
542542
}
543543

544+
/**
545+
* @test
546+
*/
547+
public function shouldCompareWithFromProjectId(): void
548+
{
549+
$expectedArray = ['commit' => 'object'];
550+
551+
$api = $this->getApiMock();
552+
$api->expects($this->once())
553+
->method('get')
554+
->with('projects/1/repository/compare', ['from' => 'master', 'to' => 'feature', 'straight' => 'true', 'from_project_id' => '123'])
555+
->will($this->returnValue($expectedArray))
556+
;
557+
558+
$this->assertEquals($expectedArray, $api->compare(1, 'master', 'feature', true, '123'));
559+
}
560+
544561
/**
545562
* @test
546563
*/

0 commit comments

Comments
 (0)