diff --git a/lib/Github/Api/Search.php b/lib/Github/Api/Search.php index dfc4c24718b..84626ae32db 100644 --- a/lib/Github/Api/Search.php +++ b/lib/Github/Api/Search.php @@ -95,4 +95,21 @@ public function commits($q, $sort = null, $order = 'desc') return $this->get('/search/commits', ['q' => $q, 'sort' => $sort, 'order' => $order]); } + + /** + * Search commits by filter (q). + * + * @link https://developer.github.com/v3/search/#search-topics + * + * @param string $q the filter + * + * @return array + */ + public function topics($q) + { + //This api is in preview mode, so set the correct accept-header + $this->acceptHeaderValue = 'application/vnd.github.mercy-preview+json'; + + return $this->get('/search/topics', ['q' => $q]); + } } diff --git a/test/Github/Tests/Api/SearchTest.php b/test/Github/Tests/Api/SearchTest.php index 60ebb6cd3e1..a44c7b7499e 100644 --- a/test/Github/Tests/Api/SearchTest.php +++ b/test/Github/Tests/Api/SearchTest.php @@ -196,6 +196,26 @@ public function shouldSearchCommitsRegardingSortAndOrder() ); } + /** + * @test + */ + public function shouldSearchTopics() + { + $expectedArray = ['total_count' => '0']; + + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with('/search/topics', ['q' => 'query text']) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals( + $expectedArray, + $api->topics('query text') + ); + } + /** * @return string */