Skip to content
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