Skip to content

Commit 25b95a6

Browse files
committed
feature(search): return all pages from a search
Closes #302
1 parent 15c68a5 commit 25b95a6

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

lib/Requestable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class Requestable {
203203
_requestAllPages(path, options, cb, results) {
204204
results = results || [];
205205

206-
return this._request('GET', path, null)
206+
return this._request('GET', path, options)
207207
.then((response) => {
208208
results.push.apply(results, response.data);
209209

lib/Search.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,20 @@ class Search extends Requestable {
2424
this.__defaults = this._getOptionsWithDefaults(defaults);
2525
}
2626

27+
/**
28+
* Available search options
29+
* @see https://developer.github.com/v3/search/#parameters
30+
* @typedef {Object} Search.Params
31+
* @param {string} q - the query to make
32+
* @param {string} sort - the sort field, one of `stars`, `forks`, or `updated`.
33+
* Default is [best match](https://developer.github.com/v3/search/#ranking-search-results)
34+
* @param {string} order - the ordering, either `asc` or `desc`
35+
*/
2736
/**
2837
* Perform a search on the GitHub API
2938
* @private
3039
* @param {string} path - the scope of the search
31-
* @param {Object} [withOptions] - additional parameters for the search
40+
* @param {Search.Params} [withOptions] - additional parameters for the search
3241
* @param {Requestable.callback} [cb] - will receive the results of the search
3342
* @return {Promise} - the promise for the http request
3443
*/
@@ -38,13 +47,13 @@ class Search extends Requestable {
3847
Object.keys(withOptions).forEach((prop) => requestOptions[prop] = withOptions[prop]);
3948

4049
log(`searching ${path} with options:`, requestOptions);
41-
return this._request('GET', `/search/${path}`, requestOptions, cb);
50+
return this._requestAllPages(`/search/${path}`, requestOptions, cb);
4251
}
4352

4453
/**
4554
* Search for repositories
4655
* @see https://developer.github.com/v3/search/#search-repositories
47-
* @param {Object} [options] - additional parameters for the search
56+
* @param {Search.Params} [options] - additional parameters for the search
4857
* @param {Requestable.callback} [cb] - will receive the results of the search
4958
* @return {Promise} - the promise for the http request
5059
*/
@@ -55,7 +64,7 @@ class Search extends Requestable {
5564
/**
5665
* Search for code
5766
* @see https://developer.github.com/v3/search/#search-code
58-
* @param {Object} [options] - additional parameters for the search
67+
* @param {Search.Params} [options] - additional parameters for the search
5968
* @param {Requestable.callback} [cb] - will receive the results of the search
6069
* @return {Promise} - the promise for the http request
6170
*/
@@ -66,7 +75,7 @@ class Search extends Requestable {
6675
/**
6776
* Search for issues
6877
* @see https://developer.github.com/v3/search/#search-issues
69-
* @param {Object} [options] - additional parameters for the search
78+
* @param {Search.Params} [options] - additional parameters for the search
7079
* @param {Requestable.callback} [cb] - will receive the results of the search
7180
* @return {Promise} - the promise for the http request
7281
*/
@@ -77,7 +86,7 @@ class Search extends Requestable {
7786
/**
7887
* Search for users
7988
* @see https://developer.github.com/v3/search/#search-users
80-
* @param {Object} [options] - additional parameters for the search
89+
* @param {Search.Params} [options] - additional parameters for the search
8190
* @param {Requestable.callback} [cb] - will receive the results of the search
8291
* @return {Promise} - the promise for the http request
8392
*/

test/search.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('Search', function() {
3333

3434
it('should search issues', function(done) {
3535
let search = github.search({
36-
q: 'windows label:bug language:python state:open',
36+
q: 'windows pip label:bug language:python state:open ',
3737
sort: 'created',
3838
order: 'asc'
3939
});

0 commit comments

Comments
 (0)