Skip to content

Commit bec7903

Browse files
committed
Added search functionality to API for: issues, repos, users
1 parent 725bf7c commit bec7903

File tree

4 files changed

+42
-30
lines changed

4 files changed

+42
-30
lines changed

lib/Github/Api/Issue.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Issue extends Api
1818
* @param string $username the username
1919
* @param string $repo the repo
2020
* @param string $state the issue state, can be open or closed
21-
* @param array $state the additional parameters like milestone, assignee, lables, sort, direction
21+
* @param array $parameters the additional parameters like milestone, assignee, lables, sort, direction
2222
* @return array list of issues found
2323
*/
2424
public function getList($username, $repo, $state = null, $parameters = array())
@@ -35,17 +35,23 @@ public function getList($username, $repo, $state = null, $parameters = array())
3535
}
3636

3737
/**
38-
* Search issues by username, repo, state and search term
38+
* Search issues by username, repo, state and keyword
39+
* @link http://developer.github.com/v3/search/#search-issues
3940
*
4041
* @param string $username the username
4142
* @param string $repo the repo
4243
* @param string $state the issue state, can be open or closed
43-
* @param string $searchTerm the search term to filter issues by
44+
* @param string $keyword the keyword to filter issues by
45+
*
4446
* @return array list of issues found
4547
*/
46-
public function search($username, $repo, $state, $searchTerm)
48+
public function search($username, $repo, $state, $keyword)
4749
{
48-
throw new \BadMethodCallException('Method cannot be implemented using new api version');
50+
if (!in_array($state, array('open', 'closed'))) {
51+
$state = 'open';
52+
}
53+
54+
return $this->get('legacy/issues/search/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($state).'/'.urlencode($keyword));
4955
}
5056

5157
/**
@@ -125,7 +131,7 @@ public function update($username, $repo, $number, array $data)
125131
}
126132

127133
/**
128-
* Repoen an existing issue by username, repo and issue number. Requires authentication.
134+
* Reopen an existing issue by username, repo and issue number. Requires authentication.
129135
* @link http://developer.github.com/v3/issues/
130136
*
131137
* @param string $username the username

lib/Github/Api/Repo.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,32 @@
1313
class Repo extends Api
1414
{
1515
/**
16-
* Search repos by keyword
17-
* http://develop.github.com/p/repo.html
16+
* Search repositories by keyword:
17+
* @link http://developer.github.com/v3/search/#search-repositories
1818
*
19-
* @param string $query the search query
19+
* @param string $keyword the search query
2020
* @param string $language takes the same values as the language drop down on http://github.com/search
21-
* @param int $startPage the page number
22-
* @return array list of repos found
21+
* @param integer $startPage the page number
22+
*
23+
* @return array list of founded repositories
2324
*/
24-
public function search($query, $language = '', $startPage = 1)
25+
public function search($keyword, $language = null, $startPage = 1)
2526
{
26-
throw new \BadMethodCallException('Method cannot be implemented using new api version');
27+
$url = 'legacy/repos/search/'.urlencode($keyword);
28+
29+
$params = array();
30+
if (null !== $language) {
31+
$params['language'] = $language;
32+
}
33+
if (1 !== $startPage) {
34+
$params['start_page'] = $startPage;
35+
}
36+
37+
if (!empty($params)) {
38+
$url .= '?' . http_build_query($params);
39+
}
40+
41+
return $this->get($url);
2742
}
2843

2944
/**
@@ -363,7 +378,7 @@ public function getRepoTeams($username, $repo)
363378
*
364379
* @param string $username the user who owns the repo
365380
* @param string $repo the name of the repo
366-
* @param $path path to file or directory
381+
* @param string $path path to file or directory
367382
*
368383
* @return array information for file | information for each item in directory
369384
*/

lib/Github/Api/User.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
class User extends Api
1414
{
1515
/**
16-
* Search users by username
17-
* http://develop.github.com/p/users.html#searching_for_users
16+
* Search users by username:
17+
* @link http://developer.github.com/v3/search/#search-users
1818
*
19-
* @param string $username the username to search
20-
* @return array list of users found
19+
* @param string $keyword the keyword to search
20+
*
21+
* @return array list of users found
2122
*/
22-
public function search($username)
23+
public function search($keyword)
2324
{
24-
throw new \BadMethodCallException('Method cannot be implemented using new api version');
25+
return $this->get('legacy/user/search/'.urlencode($keyword));
2526
}
2627

2728
/**

test/Github/Tests/Api/RepoTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@
66

77
class RepoTest extends ApiTestCase
88
{
9-
/**
10-
* @expectedException BadMethodCallException
11-
*/
12-
public function testThatSearchIsNotSupported()
13-
{
14-
$api = $this->getApiMock();
15-
16-
$api->search('github api', 'fr', 3);
17-
}
18-
199
/**
2010
* @expectedException BadMethodCallException
2111
*/

0 commit comments

Comments
 (0)