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
7 changes: 6 additions & 1 deletion doc/gitdata/references.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
$references = $client->api('gitData')->references()->all('KnpLabs', 'php-github-api');
```

### List Matching references
```php
$references = $client->api('gitData')->references()->matching('KnpLabs', 'php-github-api', 'heads/branchName'); // use 'tags/tagName' for third argument if ref is tag
```

### Show a reference

```php
Expand Down Expand Up @@ -41,4 +46,4 @@ $references = $client->api('gitData')->references()->branches('KnpLabs', 'php-gi
### List all tags
```php
$references = $client->api('gitData')->references()->tags('KnpLabs', 'php-github-api');
```
```
16 changes: 16 additions & 0 deletions lib/Github/Api/GitData/References.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ public function all($username, $repository)
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs');
}

/**
* Get all matching references for the supplied reference name.
*
* @param string $username
* @param string $repository
* @param string $reference
*
* @return array
*/
public function matching(string $username, string $repository, string $reference): array
{
$reference = $this->encodeReference($reference);

return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/matching-refs/'.$reference);
}

/**
* Get all branches of a repository.
*
Expand Down
16 changes: 16 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,22 @@ public function shouldGetAllRepoReferences()
$this->assertEquals($expectedValue, $api->all('l3l0', 'l3l0repo'));
}

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

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

$this->assertEquals($expectedValue, $api->matching('l3l0', 'l3l0repo', 'heads/refName'));
}

/**
* @test
*/
Expand Down