Skip to content
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
17 changes: 17 additions & 0 deletions lib/Github/Api/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
20 changes: 20 additions & 0 deletions test/Github/Tests/Api/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down