├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .travis.yml ├── .verb.md ├── CHANGELOG.md ├── LICENSE ├── README.md ├── bin └── cli.js ├── examples ├── org.js ├── users-filtered.js └── users.js ├── index.js ├── package.json └── test ├── support └── auth.js └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org/ 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | indent_size = 2 8 | indent_style = space 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | 12 | [{**/{actual,fixtures,expected,templates}/**,*.md}] 13 | trim_trailing_whitespace = false 14 | insert_final_newline = false 15 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "eslint:recommended" 4 | ], 5 | 6 | "env": { 7 | "browser": false, 8 | "es6": true, 9 | "node": true, 10 | "mocha": true 11 | }, 12 | 13 | "parserOptions":{ 14 | "ecmaVersion": 9, 15 | "sourceType": "module", 16 | "ecmaFeatures": { 17 | "modules": true, 18 | "experimentalObjectRestSpread": true 19 | } 20 | }, 21 | 22 | "globals": { 23 | "document": false, 24 | "navigator": false, 25 | "window": false 26 | }, 27 | 28 | "rules": { 29 | "accessor-pairs": 2, 30 | "arrow-spacing": [2, { "before": true, "after": true }], 31 | "block-spacing": [2, "always"], 32 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 33 | "comma-dangle": [2, "never"], 34 | "comma-spacing": [2, { "before": false, "after": true }], 35 | "comma-style": [2, "last"], 36 | "constructor-super": 2, 37 | "curly": [2, "multi-line"], 38 | "dot-location": [2, "property"], 39 | "eol-last": 2, 40 | "eqeqeq": [2, "allow-null"], 41 | "generator-star-spacing": [2, { "before": true, "after": true }], 42 | "handle-callback-err": [2, "^(err|error)$" ], 43 | "indent": [2, 2, { "SwitchCase": 1 }], 44 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 45 | "keyword-spacing": [2, { "before": true, "after": true }], 46 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 47 | "new-parens": 2, 48 | "no-array-constructor": 2, 49 | "no-caller": 2, 50 | "no-class-assign": 2, 51 | "no-cond-assign": 2, 52 | "no-const-assign": 2, 53 | "no-control-regex": 2, 54 | "no-debugger": 2, 55 | "no-delete-var": 2, 56 | "no-dupe-args": 2, 57 | "no-dupe-class-members": 2, 58 | "no-dupe-keys": 2, 59 | "no-duplicate-case": 2, 60 | "no-empty-character-class": 2, 61 | "no-eval": 2, 62 | "no-ex-assign": 2, 63 | "no-extend-native": 2, 64 | "no-extra-bind": 2, 65 | "no-extra-boolean-cast": 2, 66 | "no-extra-parens": [2, "functions"], 67 | "no-fallthrough": 2, 68 | "no-floating-decimal": 2, 69 | "no-func-assign": 2, 70 | "no-implied-eval": 2, 71 | "no-inner-declarations": [2, "functions"], 72 | "no-invalid-regexp": 2, 73 | "no-irregular-whitespace": 2, 74 | "no-iterator": 2, 75 | "no-label-var": 2, 76 | "no-labels": 2, 77 | "no-lone-blocks": 2, 78 | "no-mixed-spaces-and-tabs": 2, 79 | "no-multi-spaces": 2, 80 | "no-multi-str": 2, 81 | "no-multiple-empty-lines": [2, { "max": 1 }], 82 | "no-native-reassign": 0, 83 | "no-negated-in-lhs": 2, 84 | "no-new": 2, 85 | "no-new-func": 2, 86 | "no-new-object": 2, 87 | "no-new-require": 2, 88 | "no-new-wrappers": 2, 89 | "no-obj-calls": 2, 90 | "no-octal": 2, 91 | "no-octal-escape": 2, 92 | "no-proto": 0, 93 | "no-redeclare": 2, 94 | "no-regex-spaces": 2, 95 | "no-return-assign": 2, 96 | "no-self-compare": 2, 97 | "no-sequences": 2, 98 | "no-shadow-restricted-names": 2, 99 | "no-spaced-func": 2, 100 | "no-sparse-arrays": 2, 101 | "no-this-before-super": 2, 102 | "no-throw-literal": 2, 103 | "no-trailing-spaces": 0, 104 | "no-undef": 2, 105 | "no-undef-init": 2, 106 | "no-unexpected-multiline": 2, 107 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 108 | "no-unreachable": 2, 109 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 110 | "no-useless-call": 0, 111 | "no-with": 2, 112 | "one-var": [0, { "initialized": "never" }], 113 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], 114 | "padded-blocks": [0, "never"], 115 | "quotes": [2, "single", "avoid-escape"], 116 | "radix": 2, 117 | "semi": [2, "always"], 118 | "semi-spacing": [2, { "before": false, "after": true }], 119 | "space-before-blocks": [2, "always"], 120 | "space-before-function-paren": [2, "never"], 121 | "space-in-parens": [2, "never"], 122 | "space-infix-ops": 2, 123 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 124 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], 125 | "use-isnan": 2, 126 | "valid-typeof": 2, 127 | "wrap-iife": [2, "any"], 128 | "yoda": [2, "never"] 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | *.* text eol=lf 3 | *.css text eol=lf 4 | *.html text eol=lf 5 | *.js text eol=lf 6 | *.json text eol=lf 7 | *.less text eol=lf 8 | *.md text eol=lf 9 | *.yml text eol=lf 10 | 11 | *.jpg binary 12 | *.gif binary 13 | *.png binary 14 | *.jpeg binary -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # always ignore files 2 | *.DS_Store 3 | .idea 4 | .vscode 5 | *.sublime-* 6 | 7 | # test related, or directories generated by tests 8 | test/actual 9 | actual 10 | coverage 11 | .nyc* 12 | 13 | # npm 14 | node_modules 15 | npm-debug.log 16 | 17 | # yarn 18 | yarn.lock 19 | yarn-error.log 20 | 21 | # misc 22 | _gh_pages 23 | _draft 24 | _drafts 25 | bower_components 26 | vendor 27 | temp 28 | tmp 29 | TODO.md 30 | package-lock.json -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | os: 3 | - linux 4 | - osx 5 | language: node_js 6 | node_js: 7 | - node 8 | - '9' 9 | - '8' 10 | - '7' 11 | - '6' 12 | - '5' 13 | - '4' 14 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | ## Release history 2 | 3 | See the [changelog](./CHANGELOG.md) for updates. 4 | 5 | ## Usage 6 | 7 | This library is a tiny wrapper around [github-base][], see that project's readme for more information about available options and authentication choices. 8 | 9 | {%= apidocs("index.js") %} 10 | 11 | See the [GitHub API documentation for repositories](https://developer.github.com/v3/repos/) for more details about the objects returned for each repository. 12 | 13 | 14 | ## Options 15 | 16 | | **Option** | **Type** | **Default** | **Description** | 17 | | --- | --- | --- | --- | 18 | | `filterOrgs` | `function` | undefined | Function for filtering organizations from the result. | 19 | | `filterRepos` | `function` | undefined | Function for filtering repositories from the result. | 20 | | `sort` | `boolean` | `true` | By default, the returned list is sorted by repository `name` | 21 | 22 | ## CLI 23 | 24 | ```sh 25 | $ repos 26 | ``` 27 | 28 | - `names` - one or more comma-separated user names or orgs 29 | - `dest` - destination path to use, default is `repos.json` 30 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Release history 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 6 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 7 | 8 |
9 | Guiding Principles 10 | 11 | - Changelogs are for humans, not machines. 12 | - There should be an entry for every single version. 13 | - The same types of changes should be grouped. 14 | - Versions and sections should be linkable. 15 | - The latest version comes first. 16 | - The release date of each versions is displayed. 17 | - Mention whether you follow Semantic Versioning. 18 | 19 |
20 | 21 |
22 | Types of changes 23 | 24 | Changelog entries are classified using the following labels _(from [keep-a-changelog](http://keepachangelog.com/)_): 25 | 26 | - `Added` for new features. 27 | - `Changed` for changes in existing functionality. 28 | - `Deprecated` for soon-to-be removed features. 29 | - `Removed` for now removed features. 30 | - `Fixed` for any bug fixes. 31 | - `Security` in case of vulnerabilities. 32 | 33 |
34 | 35 | 36 | ## [2.0.0] - 2018-08-19 37 | 38 | - Use the `orgs` library. 39 | 40 | ## [1.0.0] - 2017-09-12 41 | 42 | - Complete refactor 43 | 44 | ## [0.1.0] - 2014-04-04 45 | 46 | - first commit 47 | 48 | [2.0.0]: https://github.com/jonschlinkert/repos/compare/v1.0.0...v2.0.0 49 | [1.0.0]: https://github.com/jonschlinkert/repos/compare/v0.1.0...v1.0.0 50 | [keep-a-changelog]: https://github.com/olivierlacan/keep-a-changelog 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2018, Jon Schlinkert. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # repos [![NPM version](https://img.shields.io/npm/v/repos.svg?style=flat)](https://www.npmjs.com/package/repos) [![NPM monthly downloads](https://img.shields.io/npm/dm/repos.svg?style=flat)](https://npmjs.org/package/repos) [![NPM total downloads](https://img.shields.io/npm/dt/repos.svg?style=flat)](https://npmjs.org/package/repos) 2 | 3 | > Tiny wrapper around github-base for getting publicly available information for a repository, or all of the repositories for one or more users or orgs, from the GitHub API. 4 | 5 | Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. 6 | 7 | ## Install 8 | 9 | Install with [npm](https://www.npmjs.com/): 10 | 11 | ```sh 12 | $ npm install --save repos 13 | ``` 14 | 15 | ## Release history 16 | 17 | See the [changelog](./CHANGELOG.md) for updates. 18 | 19 | ## Usage 20 | 21 | This library is a tiny wrapper around [github-base](https://github.com/jonschlinkert/github-base), see that project's readme for more information about available options and authentication choices. 22 | 23 | **Params** 24 | 25 | * `users` **{String|Array}**: One or more users or organization names. 26 | * `options` **{Object}**: See available [options](#options). 27 | * `returns` **{Promise}** 28 | 29 | **Example** 30 | 31 | ```js 32 | const repos = require('repos'); 33 | const options = { 34 | // see github-base for other authentication options 35 | token: 'YOUR_GITHUB_AUTH_TOKEN' 36 | }; 37 | repos(['doowb', 'jonschlinkert'], options) 38 | .then(function(repos) { 39 | // array of repository objects 40 | console.log(repos); 41 | }) 42 | .catch(console.error) 43 | ``` 44 | 45 | See the [GitHub API documentation for repositories](https://developer.github.com/v3/repos/) for more details about the objects returned for each repository. 46 | 47 | ## Options 48 | 49 | | **Option** | **Type** | **Default** | **Description** | 50 | | --- | --- | --- | --- | 51 | | `filterOrgs` | `function` | undefined | Function for filtering organizations from the result. | 52 | | `filterRepos` | `function` | undefined | Function for filtering repositories from the result. | 53 | | `sort` | `boolean` | `true` | By default, the returned list is sorted by repository `name` | 54 | 55 | ## CLI 56 | 57 | ```sh 58 | $ repos 59 | ``` 60 | 61 | * `names` - one or more comma-separated user names or orgs 62 | * `dest` - destination path to use, default is `repos.json` 63 | 64 | ## About 65 | 66 |
67 | Contributing 68 | 69 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 70 | 71 |
72 | 73 |
74 | Running Tests 75 | 76 | Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: 77 | 78 | ```sh 79 | $ npm install && npm test 80 | ``` 81 | 82 |
83 | 84 |
85 | Building docs 86 | 87 | _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ 88 | 89 | To generate the readme, run the following command: 90 | 91 | ```sh 92 | $ npm install -g verbose/verb#dev verb-generate-readme && verb 93 | ``` 94 | 95 |
96 | 97 | ### Related projects 98 | 99 | You might also be interested in these projects: 100 | 101 | * [gists](https://www.npmjs.com/package/gists): Methods for working with the GitHub Gist API. Node.js/JavaScript | [homepage](https://github.com/jonschlinkert/gists "Methods for working with the GitHub Gist API. Node.js/JavaScript") 102 | * [github-base](https://www.npmjs.com/package/github-base): Low-level methods for working with the GitHub API in node.js/JavaScript. | [homepage](https://github.com/jonschlinkert/github-base "Low-level methods for working with the GitHub API in node.js/JavaScript.") 103 | * [github-content](https://www.npmjs.com/package/github-content): Easily download files from github raw user content. | [homepage](https://github.com/doowb/github-content "Easily download files from github raw user content.") 104 | * [github-contributors](https://www.npmjs.com/package/github-contributors): Generate a markdown or JSON list of contributors for a project using the GitHub API. | [homepage](https://github.com/jonschlinkert/github-contributors "Generate a markdown or JSON list of contributors for a project using the GitHub API.") 105 | * [topics](https://www.npmjs.com/package/topics): Get and update GitHub repository topics. | [homepage](https://github.com/jonschlinkert/topics "Get and update GitHub repository topics.") 106 | 107 | ### Author 108 | 109 | **Jon Schlinkert** 110 | 111 | * [GitHub Profile](https://github.com/jonschlinkert) 112 | * [Twitter Profile](https://twitter.com/jonschlinkert) 113 | * [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) 114 | 115 | ### License 116 | 117 | Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert). 118 | Released under the [MIT License](LICENSE). 119 | 120 | *** 121 | 122 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on August 19, 2018._ -------------------------------------------------------------------------------- /bin/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const repos = require('../'); 4 | const argv = require('minimist')(process.argv.slice(2)); 5 | const write = require('write'); 6 | 7 | repos(argv._[0].split(','), argv) 8 | .then(res => { 9 | let filepath = argv._[1] || 'repos.json'; 10 | write(filepath, JSON.stringify(res, null, 2), err => { 11 | if (err) { 12 | console.error(err); 13 | process.exit(1); 14 | } 15 | console.log(`File was written to: ${filepath}`); 16 | process.exit(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /examples/org.js: -------------------------------------------------------------------------------- 1 | const write = require('write'); 2 | const auth = require('../test/support/auth'); 3 | const repos = require('../'); 4 | 5 | repos('micromatch', auth) 6 | .then(res => { 7 | write.sync('micromatch.json', JSON.stringify(res, null, 2)); 8 | return res; 9 | }) 10 | .catch(console.error); 11 | -------------------------------------------------------------------------------- /examples/users-filtered.js: -------------------------------------------------------------------------------- 1 | const repos = require('../'); 2 | const auth = require('../test/support/auth'); 3 | 4 | const names = ['doowb', 'jonschlinkert']; 5 | const options = { 6 | // filter out orgs we didn't create 7 | filterOrgs: org => !/(gulp|grunt)/.test(org.login), 8 | // filter out our own names and/or libraries we didn't create 9 | filterRepos(repo, acc) { 10 | return !acc.names.includes(repo.name) 11 | && !names.includes(repo.name) 12 | && !['archived', 'private', 'fork'].some(key => repo[key] === true) 13 | } 14 | }; 15 | 16 | repos(names, { ...auth, ...options }) 17 | .then(res => { 18 | console.log('REPOS:', res.length); 19 | console.log('STARS:', res.reduce((n, repo) => (n += repo.watchers), 0)); 20 | // REPOS: 1,509 21 | // STARS: 27,064 22 | }) 23 | .catch(err => console.log(err)); 24 | -------------------------------------------------------------------------------- /examples/users.js: -------------------------------------------------------------------------------- 1 | const write = require('write'); 2 | const auth = require('../test/support/auth'); 3 | const repos = require('../'); 4 | 5 | repos(['doowb', 'jonschlinkert'], auth) 6 | .then(res => { 7 | write.sync('repos.json', JSON.stringify(res, null, 2)); 8 | return res; 9 | }) 10 | .catch(console.error); 11 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const GitHub = require('github-base'); 4 | const orgs = require('orgs'); 5 | 6 | /** 7 | * Get repositories for one or more users. 8 | * 9 | * ```js 10 | * const repos = require('repos'); 11 | * const options = { 12 | * // see github-base for other authentication options 13 | * token: 'YOUR_GITHUB_AUTH_TOKEN' 14 | * }; 15 | * repos(['doowb', 'jonschlinkert'], options) 16 | * .then(function(repos) { 17 | * // array of repository objects 18 | * console.log(repos); 19 | * }) 20 | * .catch(console.error) 21 | * ``` 22 | * @param {String|Array} `users` One or more users or organization names. 23 | * @param {Object} `options` See available [options](#options). 24 | * @return {Promise} 25 | * @api public 26 | */ 27 | 28 | module.exports = async (users, options) => { 29 | if (isObject(users)) { 30 | return new GitHub(users).paged('/user/repos'); 31 | } 32 | 33 | if (typeof users === 'string') { 34 | users = [users]; 35 | } 36 | 37 | if (!Array.isArray(users)) { 38 | return Promise.reject(new TypeError('expected users to be a string or array')); 39 | } 40 | 41 | const acc = { repos: [], names: [] }; 42 | const opts = Object.assign({}, options); 43 | const noop = () => true; 44 | const filterRepos = opts.filterRepos || noop; 45 | const filterOrgs = opts.filterOrgs || noop; 46 | 47 | // don't pass custom options to module dependencies 48 | delete opts.filterRepos; 49 | delete opts.filterOrgs; 50 | 51 | const github = new GitHub(opts); 52 | const arr = await orgs(users, opts); 53 | 54 | for (const org of arr) { 55 | if (filterOrgs(org) !== true) continue; 56 | 57 | const rep = await github.paged(`/${type(org)}/${org.login}/repos`); 58 | 59 | for (const page of rep.pages) { 60 | for (const repo of page.body) { 61 | if (filterRepos(repo, acc) === true) { 62 | acc.names.push(repo.name); 63 | acc.repos.push(repo); 64 | } 65 | } 66 | } 67 | } 68 | 69 | if (opts.sort !== false) { 70 | return acc.repos.sort(compare('name')); 71 | } 72 | 73 | return acc.repos; 74 | }; 75 | 76 | function isObject(val) { 77 | return val !== null && typeof val === 'object' && !Array.isArray(val); 78 | } 79 | 80 | function compare(prop) { 81 | return (a, b) => (a[prop] < b[prop] ? -1 : a[prop] > b[prop] ? 1 : 0); 82 | } 83 | 84 | function type(org) { 85 | return org.type === 'User' ? 'users' : 'orgs'; 86 | } 87 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "repos", 3 | "description": "Tiny wrapper around github-base for getting publicly available information for a repository, or all of the repositories for one or more users or orgs, from the GitHub API.", 4 | "version": "2.0.0", 5 | "homepage": "https://github.com/jonschlinkert/repos", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "repository": "jonschlinkert/repos", 8 | "bugs": { 9 | "url": "https://github.com/jonschlinkert/repos/issues" 10 | }, 11 | "license": "MIT", 12 | "files": [ 13 | "bin", 14 | "index.js" 15 | ], 16 | "main": "index.js", 17 | "bin": { 18 | "repos": "bin/cli.js" 19 | }, 20 | "engines": { 21 | "node": ">=4" 22 | }, 23 | "scripts": { 24 | "test": "mocha" 25 | }, 26 | "dependencies": { 27 | "github-base": "^1.0.0", 28 | "minimist": "^1.2.0", 29 | "orgs": "^1.0.0", 30 | "write": "^1.0.3" 31 | }, 32 | "devDependencies": { 33 | "data-store": "^1.0.0", 34 | "mocha": "^3.5.3", 35 | "gulp-format-md": "^1.0.0" 36 | }, 37 | "keywords": [ 38 | "all", 39 | "allpublic", 40 | "api", 41 | "commits", 42 | "create", 43 | "del", 44 | "delete", 45 | "destroy", 46 | "download", 47 | "edit", 48 | "fork", 49 | "forks", 50 | "get", 51 | "github", 52 | "isstarred", 53 | "list", 54 | "paginate", 55 | "paginated", 56 | "patch", 57 | "post", 58 | "put", 59 | "repos", 60 | "repositories", 61 | "repository", 62 | "request", 63 | "revision", 64 | "star", 65 | "starred", 66 | "unstar" 67 | ], 68 | "verb": { 69 | "toc": false, 70 | "layout": "default", 71 | "tasks": [ 72 | "readme" 73 | ], 74 | "plugins": [ 75 | "gulp-format-md" 76 | ], 77 | "related": { 78 | "list": [ 79 | "gists", 80 | "github-base", 81 | "github-content", 82 | "github-contributors", 83 | "topics" 84 | ] 85 | }, 86 | "lint": { 87 | "reflinks": true 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /test/support/auth.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const opts = {alias: {password: 'p', username: 'u'}}; 4 | const argv = require('minimist')(process.argv.slice(2), opts); 5 | const Store = require('data-store'); 6 | const store = new Store('repos-tests'); 7 | let auth = store.get('auth'); 8 | 9 | if (!auth) { 10 | auth = {}; 11 | 12 | if (argv.token) { 13 | auth.token = argv.token; 14 | } else { 15 | auth.username = argv.username || argv._[0] || process.env.GITHUB_USERNAME; 16 | auth.password = argv.password || argv._[1] || process.env.GITHUB_PASSWORD; 17 | } 18 | } 19 | 20 | if (auth.token || (auth.username && auth.password)) { 21 | store.set('auth', auth); 22 | } else { 23 | console.error('please specify authentication details'); 24 | console.error('--token, -t'); 25 | console.error('=== or ==='); 26 | console.error('--username, -u (or first argument)'); 27 | console.error('--password, -p (or second argument)'); 28 | process.exit(1); 29 | } 30 | 31 | module.exports = auth; 32 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('mocha'); 4 | const assert = require('assert'); 5 | const auth = require('./support/auth.js'); 6 | const repos = require('../'); 7 | 8 | describe('repos', function() { 9 | this.timeout(10000); 10 | 11 | it('should catch error when invalid args are passed', () => { 12 | return repos().catch(err => assert(err)); 13 | }); 14 | 15 | it('should catch error when bad credentials are passed', () => { 16 | return repos('micromatch', { token: 'foo' }) 17 | .catch(err => { 18 | assert.equal(err.message, 'Bad credentials'); 19 | }); 20 | }); 21 | 22 | it('should get repos for the specified org', () => { 23 | return repos('micromatch', auth) 24 | .then(res => { 25 | assert(Array.isArray(res)); 26 | assert(res.some(ele => ele.name === 'to-regex-range')); 27 | assert(res.some(ele => ele.name === 'nanomatch')); 28 | assert(res.some(ele => ele.name === 'extglob')); 29 | }); 30 | }); 31 | 32 | it('should get repos for an array of usernames', () => { 33 | return repos(['micromatch', 'breakdance'], auth) 34 | .then(res => { 35 | assert(Array.isArray(res)); 36 | assert(res.length > 2); 37 | }); 38 | }); 39 | }); 40 | --------------------------------------------------------------------------------