Skip to content

Commit 1654be3

Browse files
acrobatNyholm
authored andcommitted
Missing search commits api endpoint (#659)
1 parent 4ffb1d3 commit 1654be3

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

doc/search.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ Returns a list of issues found by such criteria.
3434
$users = $client->api('search')->users('location:Amsterdam language:php');
3535
```
3636

37+
### Search commits
38+
39+
```php
40+
$commits = $client->api('search')->commits('repo:octocat/Spoon-Knife+css');
41+
```
42+
3743
Returns a list of users found by such criteria.
3844

3945
### Sorting results
@@ -45,4 +51,5 @@ $repos = $client->api('search')->repositories('...', 'created', 'asc');
4551
$files = $client->api('search')->code('...........', 'indexed', 'desc');
4652
$issues = $client->api('search')->issues('.........', 'comments', 'asc');
4753
$users = $client->api('search')->users('..........', 'followers', 'asc');
54+
$commits = $client->api('search')->commits('..........', 'author-date', 'desc');
4855
```

lib/Github/Api/Search.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
*/
1111
class Search extends AbstractApi
1212
{
13+
use AcceptHeaderTrait;
14+
1315
/**
1416
* Search repositories by filter (q).
1517
*
@@ -73,4 +75,23 @@ public function users($q, $sort = 'updated', $order = 'desc')
7375
{
7476
return $this->get('/search/users', array('q' => $q, 'sort' => $sort, 'order' => $order));
7577
}
78+
79+
/**
80+
* Search commits by filter (q).
81+
*
82+
* @link https://developer.github.com/v3/search/#search-commits
83+
*
84+
* @param string $q the filter
85+
* @param string $sort the sort field
86+
* @param string $order sort order. asc/desc
87+
*
88+
* @return array
89+
*/
90+
public function commits($q, $sort = null, $order = 'desc')
91+
{
92+
//This api is in preview mode, so set the correct accept-header
93+
$this->acceptHeaderValue = 'application/vnd.github.cloak-preview';
94+
95+
return $this->get('/search/commits', array('q' => $q, 'sort' => $sort, 'order' => $order));
96+
}
7697
}

test/Github/Tests/Api/SearchTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,26 @@ public function shouldSearchUsersRegardingSortAndOrder()
176176
);
177177
}
178178

179+
/**
180+
* @test
181+
*/
182+
public function shouldSearchCommitsRegardingSortAndOrder()
183+
{
184+
$expectedArray = ['total_count' => '0'];
185+
186+
$api = $this->getApiMock();
187+
188+
$api->expects($this->once())
189+
->method('get')
190+
->with('/search/commits', ['q' => 'query text', 'sort' => 'author-date', 'order' => 'asc'])
191+
->will($this->returnValue($expectedArray));
192+
193+
$this->assertEquals(
194+
$expectedArray,
195+
$api->commits('query text', 'author-date', 'asc')
196+
);
197+
}
198+
179199
/**
180200
* @return string
181201
*/

0 commit comments

Comments
 (0)