Skip to content

Commit 2e31a28

Browse files
committedSep 30, 2019
Require Node.js 10
1 parent ddff311 commit 2e31a28

File tree

5 files changed

+22
-129
lines changed

5 files changed

+22
-129
lines changed
 

‎.travis.yml

-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@ language: node_js
33
node_js:
44
- '12'
55
- '10'
6-
- '8'
7-
- '6'
8-
- '4'

‎cli.js

-70
This file was deleted.

‎index.js

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

5-
module.exports = (name, options) => {
6-
options = options || {};
7-
8-
let page = 1;
9-
let returnValue = [];
5+
const fetchRepos = async (url, options, repos = [], page = 1) => {
6+
const {body: currentRepos, headers: {link}} = await ghGot(url, {
7+
...options,
8+
query: {page, per_page: 100} // eslint-disable-line camelcase
9+
});
1010

11-
if (typeof name !== 'string') {
12-
return Promise.reject(new TypeError(`Expected \`name\` to be of type \`string\` but received type \`${typeof name}\``));
11+
if (link && link.includes('next')) {
12+
return fetchRepos(url, options, repos.concat(currentRepos), page + 1);
1313
}
1414

15-
return isGithubUserOrOrg(name, options).then(userType => {
16-
const type = (userType === 'User') ? 'users' : 'orgs';
17-
18-
return (function loop() {
19-
const url = `${type}/${name}/repos?&per_page=100&page=${page}`;
15+
return repos.concat(currentRepos);
16+
};
2017

21-
return ghGot(url, options).then(response => {
22-
returnValue = returnValue.concat(response.body);
18+
module.exports = async (name, options = {}) => {
19+
if (typeof name !== 'string') {
20+
throw new TypeError(`Expected \`name\` to be of type \`string\` but received type \`${typeof name}\``);
21+
}
2322

24-
if (response.headers.link && response.headers.link.includes('next')) {
25-
page++;
26-
return loop();
27-
}
23+
const type = (await isGithubUserOrOrg(name, options) === 'User') ? 'users' : 'orgs';
24+
const url = `${type}/${name}/repos`;
2825

29-
return returnValue;
30-
});
31-
})();
32-
});
26+
return fetchRepos(url, options);
3327
};

‎package.json

+6-12
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,27 @@
99
"email": "kevinmartensson@gmail.com",
1010
"url": "github.com/kevva"
1111
},
12-
"bin": "cli.js",
1312
"engines": {
14-
"node": ">=4"
13+
"node": ">=10"
1514
},
1615
"scripts": {
1716
"test": "xo && ava"
1817
},
1918
"files": [
20-
"index.js",
21-
"cli.js"
19+
"index.js"
2220
],
2321
"keywords": [
24-
"cli-app",
25-
"cli",
2622
"api",
2723
"github",
2824
"repo",
2925
"repositories"
3026
],
3127
"dependencies": {
32-
"chalk": "^1.0.0",
33-
"gh-got": "^3.0.0",
34-
"is-github-user-or-org": "^1.0.0",
35-
"meow": "^3.3.0"
28+
"gh-got": "^8.1.0",
29+
"is-github-user-or-org": "^1.0.0"
3630
},
3731
"devDependencies": {
38-
"ava": "^0.25.0",
39-
"xo": "^0.20.3"
32+
"ava": "^2.4.0",
33+
"xo": "^0.25.3"
4034
}
4135
}

‎readme.md

-22
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,3 @@ Default: `https://api.github.com/`
5656
To support [GitHub Enterprise](https://enterprise.github.com/).
5757

5858
Can be set globally with the `GITHUB_ENDPOINT` environment variable.
59-
60-
61-
## CLI
62-
63-
```
64-
$ npm install --global github-repositories
65-
```
66-
67-
```
68-
$ github-repositories --help
69-
70-
Usage
71-
$ github-repositories kevva
72-
$ github-repositories kevva --token 523ef69119eadg12
73-
74-
Options
75-
-f, --forks Only list forks
76-
-r, --repos Only display repository names
77-
-s, --sources Only list sources
78-
-t, --token GitHub authentication token
79-
-u, --urls Only display URLs
80-
```

0 commit comments

Comments
 (0)
Please sign in to comment.