Skip to content

Search topics implementation #718

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 3 commits into from
Jul 15, 2018
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