Skip to content

Missing search commits api endpoint #659

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 1 commit into from
Dec 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ Returns a list of issues found by such criteria.
$users = $client->api('search')->users('location:Amsterdam language:php');
```

### Search commits

```php
$commits = $client->api('search')->commits('repo:octocat/Spoon-Knife+css');
```

Returns a list of users found by such criteria.

### Sorting results
Expand All @@ -45,4 +51,5 @@ $repos = $client->api('search')->repositories('...', 'created', 'asc');
$files = $client->api('search')->code('...........', 'indexed', 'desc');
$issues = $client->api('search')->issues('.........', 'comments', 'asc');
$users = $client->api('search')->users('..........', 'followers', 'asc');
$commits = $client->api('search')->commits('..........', 'author-date', 'desc');
```
21 changes: 21 additions & 0 deletions lib/Github/Api/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
class Search extends AbstractApi
{
use AcceptHeaderTrait;

/**
* Search repositories by filter (q).
*
Expand Down Expand Up @@ -73,4 +75,23 @@ public function users($q, $sort = 'updated', $order = 'desc')
{
return $this->get('/search/users', array('q' => $q, 'sort' => $sort, 'order' => $order));
}

/**
* Search commits by filter (q).
*
* @link https://developer.github.com/v3/search/#search-commits
*
* @param string $q the filter
* @param string $sort the sort field
* @param string $order sort order. asc/desc
*
* @return array
*/
public function commits($q, $sort = null, $order = 'desc')
{
//This api is in preview mode, so set the correct accept-header
$this->acceptHeaderValue = 'application/vnd.github.cloak-preview';

return $this->get('/search/commits', array('q' => $q, 'sort' => $sort, 'order' => $order));
}
}
20 changes: 20 additions & 0 deletions test/Github/Tests/Api/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,26 @@ public function shouldSearchUsersRegardingSortAndOrder()
);
}

/**
* @test
*/
public function shouldSearchCommitsRegardingSortAndOrder()
{
$expectedArray = ['total_count' => '0'];

$api = $this->getApiMock();

$api->expects($this->once())
->method('get')
->with('/search/commits', ['q' => 'query text', 'sort' => 'author-date', 'order' => 'asc'])
->will($this->returnValue($expectedArray));

$this->assertEquals(
$expectedArray,
$api->commits('query text', 'author-date', 'asc')
);
}

/**
* @return string
*/
Expand Down