Skip to content

Commit 10534c7

Browse files
committedSep 30, 2019
Add sort option
1 parent 2e31a28 commit 10534c7

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed
 

‎index.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
const ghGot = require('gh-got');
33
const isGithubUserOrOrg = require('is-github-user-or-org');
44

5-
const fetchRepos = async (url, options, repos = [], page = 1) => {
5+
const fetchRepos = async (url, options = {}, repos = [], page = 1) => {
66
const {body: currentRepos, headers: {link}} = await ghGot(url, {
77
...options,
8-
query: {page, per_page: 100} // eslint-disable-line camelcase
8+
query: {
9+
page,
10+
per_page: 100, // eslint-disable-line camelcase
11+
sort: options.sort
12+
}
913
});
1014

1115
if (link && link.includes('next')) {
@@ -16,6 +20,11 @@ const fetchRepos = async (url, options, repos = [], page = 1) => {
1620
};
1721

1822
module.exports = async (name, options = {}) => {
23+
options = {
24+
sort: 'full_name',
25+
...options
26+
};
27+
1928
if (typeof name !== 'string') {
2029
throw new TypeError(`Expected \`name\` to be of type \`string\` but received type \`${typeof name}\``);
2130
}

‎readme.md

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ Username or organization to fetch repos from.
3838

3939
Type: `object`
4040

41+
##### sort
42+
43+
Type: `string`<br>
44+
Default: `full_name`
45+
46+
Can be one of `created`, `updated`, `pushed`, `full_name`.
47+
4148
##### token
4249

4350
Type: `string`

‎test.js

+5
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ test('two requests should return same data', async t => {
3131
t.truthy(second.length);
3232
t.deepEqual(first, second);
3333
});
34+
35+
test('`sort` option', async t => {
36+
const repos = await githubRepositories('kevva', {sort: 'created'});
37+
t.is(repos[repos.length - 1].name, 'download');
38+
});

0 commit comments

Comments
 (0)
Please sign in to comment.