Skip to content

Commit 11b683c

Browse files
authored
feature KnpLabs#875 Add Support For GitData Reference Matching Methods (nickpoulos)
This PR was squashed before being merged into the 2.14.x-dev branch. Discussion ---------- This PR adds two methods - `matchingBranch()` and `matchingTag()` to `GitHub/Api/GitData/References.php`. These methods return the references for a given branch or tag, respectively. There are two more tests to `GitHub/Tests/Api/GitData/ReferencesTest.php`, `shouldGetAllMatchingBranchRepoReferences` and `shouldGetAllMatchingTagRepoReferences`. Documentation here: https://developer.github.com/v3/git/refs/#list-matching-references Commits ------- fe50ad1 Add matchingBranch() and matchingTags() Methods To References.php 791f563 Add New Tests In ReferencesTest For Our Two New Methods f9f39af Apply Requested Fixes 8107e13 Add Documentation For method matching() in gitdata/references.md 7e5dfc9 Refactor Dual Methods To Single, and Fix Test 61fe18b Remove link from DocBlock 2856710 Add $this->encodeReference() call Inside matching() 1fc9471 Update ReferencesTest.php To Use A More Realistic Parameter d63d9a1 StyleCI Add Period
1 parent 695ef02 commit 11b683c

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

doc/gitdata/references.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
$references = $client->api('gitData')->references()->all('KnpLabs', 'php-github-api');
88
```
99

10+
### List Matching references
11+
```php
12+
$references = $client->api('gitData')->references()->matching('KnpLabs', 'php-github-api', 'heads/branchName'); // use 'tags/tagName' for third argument if ref is tag
13+
```
14+
1015
### Show a reference
1116

1217
```php
@@ -41,4 +46,4 @@ $references = $client->api('gitData')->references()->branches('KnpLabs', 'php-gi
4146
### List all tags
4247
```php
4348
$references = $client->api('gitData')->references()->tags('KnpLabs', 'php-github-api');
44-
```
49+
```

lib/Github/Api/GitData/References.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ public function all($username, $repository)
2525
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs');
2626
}
2727

28+
/**
29+
* Get all matching references for the supplied reference name.
30+
*
31+
* @param string $username
32+
* @param string $repository
33+
* @param string $reference
34+
*
35+
* @return array
36+
*/
37+
public function matching(string $username, string $repository, string $reference): array
38+
{
39+
$reference = $this->encodeReference($reference);
40+
41+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/matching-refs/'.$reference);
42+
}
43+
2844
/**
2945
* Get all branches of a repository.
3046
*

test/Github/Tests/Api/GitData/ReferencesTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ public function shouldGetAllRepoReferences()
7171
$this->assertEquals($expectedValue, $api->all('l3l0', 'l3l0repo'));
7272
}
7373

74+
/**
75+
* @test
76+
*/
77+
public function shouldGetAllMatchingReferences()
78+
{
79+
$expectedValue = [['reference' => 'some data']];
80+
81+
$api = $this->getApiMock();
82+
$api->expects($this->once())
83+
->method('get')
84+
->with('/repos/l3l0/l3l0repo/git/matching-refs/heads/refName')
85+
->will($this->returnValue($expectedValue));
86+
87+
$this->assertEquals($expectedValue, $api->matching('l3l0', 'l3l0repo', 'heads/refName'));
88+
}
89+
7490
/**
7591
* @test
7692
*/

0 commit comments

Comments
 (0)