github-repositories
Advanced tools
+25
-21
@@ -5,30 +5,34 @@ 'use strict'; | ||
| module.exports = (name, options) => { | ||
| options = options || {}; | ||
| const fetchRepos = async (url, options = {}, repos = [], page = 1) => { | ||
| const {body: currentRepos, headers: {link}} = await ghGot(url, { | ||
| ...options, | ||
| query: { | ||
| direction: options.direction, | ||
| page, | ||
| per_page: 100, // eslint-disable-line camelcase | ||
| sort: options.sort | ||
| } | ||
| }); | ||
| let page = 1; | ||
| let returnValue = []; | ||
| if (typeof name !== 'string') { | ||
| return Promise.reject(new TypeError(`Expected \`name\` to be of type \`string\` but received type \`${typeof name}\``)); | ||
| if (link && link.includes('next')) { | ||
| return fetchRepos(url, options, repos.concat(currentRepos), page + 1); | ||
| } | ||
| return isGithubUserOrOrg(name, options).then(userType => { | ||
| const type = (userType === 'User') ? 'users' : 'orgs'; | ||
| return repos.concat(currentRepos); | ||
| }; | ||
| return (function loop() { | ||
| const url = `${type}/${name}/repos?&per_page=100&page=${page}`; | ||
| module.exports = async (name, options = {}) => { | ||
| options = { | ||
| sort: 'full_name', | ||
| ...options | ||
| }; | ||
| return ghGot(url, options).then(response => { | ||
| returnValue = returnValue.concat(response.body); | ||
| if (typeof name !== 'string') { | ||
| throw new TypeError(`Expected \`name\` to be of type \`string\` but received type \`${typeof name}\``); | ||
| } | ||
| if (response.headers.link && response.headers.link.includes('next')) { | ||
| page++; | ||
| return loop(); | ||
| } | ||
| const type = (await isGithubUserOrOrg(name, options) === 'User') ? 'users' : 'orgs'; | ||
| const url = `${type}/${name}/repos`; | ||
| return returnValue; | ||
| }); | ||
| })(); | ||
| }); | ||
| return fetchRepos(url, options); | ||
| }; |
+7
-13
| { | ||
| "name": "github-repositories", | ||
| "version": "3.1.0", | ||
| "version": "4.0.0", | ||
| "description": "Get all Github repos from a user or an organization", | ||
@@ -12,5 +12,4 @@ "license": "MIT", | ||
| }, | ||
| "bin": "cli.js", | ||
| "engines": { | ||
| "node": ">=4" | ||
| "node": ">=10" | ||
| }, | ||
@@ -21,8 +20,5 @@ "scripts": { | ||
| "files": [ | ||
| "index.js", | ||
| "cli.js" | ||
| "index.js" | ||
| ], | ||
| "keywords": [ | ||
| "cli-app", | ||
| "cli", | ||
| "api", | ||
@@ -34,11 +30,9 @@ "github", | ||
| "dependencies": { | ||
| "chalk": "^1.0.0", | ||
| "gh-got": "^3.0.0", | ||
| "is-github-user-or-org": "^1.0.0", | ||
| "meow": "^3.3.0" | ||
| "gh-got": "^8.1.0", | ||
| "is-github-user-or-org": "^1.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "ava": "^0.25.0", | ||
| "xo": "^0.20.3" | ||
| "ava": "^2.4.0", | ||
| "xo": "^0.25.3" | ||
| } | ||
| } |
+14
-22
@@ -41,2 +41,16 @@ # github-repositories [](https://travis-ci.org/kevva/github-repositories) | ||
| ##### sort | ||
| Type: `string`<br> | ||
| Default: `full_name` | ||
| Can be one of `created`, `updated`, `pushed`, `full_name`. | ||
| ##### direction | ||
| Type: `string`<br> | ||
| Default: `asc` when using `full_name`, otherwise `desc` | ||
| Can be one of `asc` or `desc`. | ||
| ##### token | ||
@@ -60,23 +74,1 @@ | ||
| Can be set globally with the `GITHUB_ENDPOINT` environment variable. | ||
| ## CLI | ||
| ``` | ||
| $ npm install --global github-repositories | ||
| ``` | ||
| ``` | ||
| $ github-repositories --help | ||
| Usage | ||
| $ github-repositories kevva | ||
| $ github-repositories kevva --token 523ef69119eadg12 | ||
| Options | ||
| -f, --forks Only list forks | ||
| -r, --repos Only display repository names | ||
| -s, --sources Only list sources | ||
| -t, --token GitHub authentication token | ||
| -u, --urls Only display URLs | ||
| ``` |
-70
| #!/usr/bin/env node | ||
| 'use strict'; | ||
| const chalk = require('chalk'); | ||
| const meow = require('meow'); | ||
| const githubRepos = require('.'); | ||
| const cli = meow(` | ||
| Usage | ||
| $ github-repositories kevva | ||
| $ github-repositories kevva --token 523ef69119eadg12 | ||
| Options | ||
| -f, --forks Only list forks | ||
| -r, --repos Only display repository names | ||
| -s, --sources Only list sources | ||
| -t, --token GitHub authentication token | ||
| -u, --urls Only display URL | ||
| `, { | ||
| boolean: [ | ||
| 'forks', | ||
| 'repos', | ||
| 'sources', | ||
| 'urls' | ||
| ], | ||
| string: [ | ||
| 'token' | ||
| ], | ||
| alias: { | ||
| h: 'help', | ||
| f: 'forks', | ||
| r: 'repos', | ||
| s: 'sources', | ||
| t: 'token', | ||
| u: 'urls', | ||
| v: 'version' | ||
| } | ||
| }); | ||
| if (cli.input.length === 0) { | ||
| console.error('User required'); | ||
| process.exit(1); | ||
| } | ||
| githubRepos(cli.input[0], cli.flags).then(repositories => { | ||
| for (const repository of repositories) { | ||
| if (cli.flags.forks && !repository.fork) { | ||
| return; | ||
| } | ||
| if (cli.flags.sources && repository.fork) { | ||
| return; | ||
| } | ||
| if (!cli.flags.forks && !cli.flags.sources && repository.fork) { | ||
| repository.name += chalk.dim(' (fork)'); | ||
| } | ||
| if (cli.flags.repos) { | ||
| console.log(repository.name); | ||
| return; | ||
| } | ||
| if (cli.flags.urls) { | ||
| console.log(repository.html_url); | ||
| return; | ||
| } | ||
| console.log(`${repository.name} ${chalk.dim(repository.html_url)}`); | ||
| } | ||
| }); |
2
-50%4168
-26.15%4
-20%30
-65.12%73
-9.88%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated