Skip to content

Add Support For GitData Reference Matching Methods #875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 18, 2020
28 changes: 28 additions & 0 deletions lib/Github/Api/GitData/References.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,34 @@ public function all($username, $repository)
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs');
}

/**
* Get all matching references for a particular branch of a repository.
*
* @param string $username
* @param string $repository
* @param string $branch
*
* @return array
*/
public function matchingBranch(string $username, string $repository, string $branch): array
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/matching-refs/heads/'.rawurlencode($branch));
}

/**
* Get all matching references for a particular branch of a repository.
*
* @param string $username
* @param string $repository
* @param string $tag
*
* @return array
*/
public function matchingTag(string $username, string $repository, string $tag): array
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/matching-refs/tags/'.rawurlencode($tag));
}

/**
* Get all branches of a repository.
*
Expand Down
32 changes: 32 additions & 0 deletions test/Github/Tests/Api/GitData/ReferencesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,38 @@ public function shouldGetAllRepoReferences()
$this->assertEquals($expectedValue, $api->all('l3l0', 'l3l0repo'));
}

/**
* @test
*/
public function shouldGetAllMatchingBranchRepoReferences()
{
$expectedValue = [['reference' => 'some data']];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/repos/l3l0/l3l0repo/git/matching-refs/heads/branchName')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->matchingBranch('l3l0', 'l3l0repo', 'branchName'));
}

/**
* @test
*/
public function shouldGetAllMatchingTagRepoReferences()
{
$expectedValue = [['reference' => 'some data']];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/repos/l3l0/l3l0repo/git/matching-refs/tags/tagName')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->matchingTag('l3l0', 'l3l0repo', 'tagName'));
}

/**
* @test
*/
Expand Down