Skip to content

Commit 2373a36

Browse files
committed
userRepos: Added possibility to specify options
1 parent 83450c8 commit 2373a36

File tree

7 files changed

+48
-11
lines changed

7 files changed

+48
-11
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ repo.unstar(owner, repository, function(err) {});
263263
var user = github.getUser();
264264
```
265265

266-
List repositories of the authenticated user, including private repositories and repositories in which the user is a collaborator and not an owner.
266+
List repositories of the authenticated user, including private repositories and repositories in which the user is a
267+
collaborator and not an owner.
267268

268269
```js
269270
user.repos(options, function(err, repos) {});
@@ -287,7 +288,8 @@ List unread notifications for the authenticated user.
287288
user.notifications(options, function(err, notifications) {});
288289
```
289290

290-
Show user information for a particular username. Also works for organizations. Pass in a falsy value (null, '', etc) for 'username' to retrieve user information for the currently authorized user.
291+
Show user information for a particular username. Also works for organizations. Pass in a falsy value (null, '', etc)
292+
for 'username' to retrieve user information for the currently authorized user.
291293

292294
```js
293295
user.show(username, function(err, user) {});
@@ -296,7 +298,7 @@ user.show(username, function(err, user) {});
296298
List public repositories for a particular user.
297299

298300
```js
299-
user.userRepos(username, function(err, repos) {});
301+
user.userRepos(username, options, function(err, repos) {});
300302
```
301303

302304
List starred repositories for a particular user.

dist/github.bundle.min.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/github.bundle.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/github.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/github.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/github.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,26 @@
249249
// List user repositories
250250
// -------
251251

252-
this.userRepos = function (username, cb) {
253-
// Github does not always honor the 1000 limit so we want to iterate over the data set.
254-
_requestAllPages('/users/' + username + '/repos?type=all&per_page=100&sort=updated', cb);
252+
this.userRepos = function (username, options, cb) {
253+
if (typeof options === 'function') {
254+
cb = options;
255+
options = {};
256+
}
257+
258+
var url = '/users/' + username + '/repos';
259+
var params = [];
260+
261+
params.push('type=' + encodeURIComponent(options.type || 'all'));
262+
params.push('sort=' + encodeURIComponent(options.sort || 'updated'));
263+
params.push('per_page=' + encodeURIComponent(options.per_page || '100')); // jscs:ignore
264+
265+
if (options.page) {
266+
params.push('page=' + encodeURIComponent(options.page));
267+
}
268+
269+
url += '?' + params.join('&');
270+
271+
_requestAllPages(url, cb);
255272
};
256273

257274
// List user starred repositories

test/test.user.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,27 @@ describe('Github.User', function() {
9494
});
9595

9696
it('should show user\'s repos', function(done) {
97-
// This is odd; userRepos times out on the test user, but user.repos does not.
9897
user.userRepos('aendrew', function(err, repos, xhr) {
9998
should.not.exist(err);
10099
xhr.should.be.instanceof(XMLHttpRequest);
100+
repos.should.be.instanceof(Array);
101+
102+
done();
103+
});
104+
});
105+
106+
it('should show user\'s repos with options', function(done) {
107+
var options = {
108+
type: 'owner',
109+
sort: 'updated',
110+
per_page: 90, // jscs:ignore
111+
page: 1
112+
};
113+
114+
user.userRepos('aendrew', options, function(err, repos, xhr) {
115+
should.not.exist(err);
116+
xhr.should.be.instanceof(XMLHttpRequest);
117+
repos.should.be.instanceof(Array);
101118

102119
done();
103120
});

0 commit comments

Comments
 (0)