├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── index.js ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.js text eol=lf 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '6' 5 | - '4' 6 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const ghGot = require('gh-got'); 3 | 4 | module.exports = (query, opts) => { 5 | opts = opts || {}; 6 | 7 | if (typeof query !== 'string') { 8 | return Promise.reject(new TypeError(`Expected a \`string\`, got \`${typeof query}\``)); 9 | } 10 | 11 | let url = `search/repositories?q=${query}`; 12 | 13 | if (opts.sort === 'forks' || opts.sort === 'stars' || opts.sort === 'updated') { 14 | url += `&sort=${opts.sort}`; 15 | } 16 | 17 | return ghGot(url, opts).then(res => res.body); 18 | }; 19 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Kevin Mårtensson 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 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "github-search-repos", 3 | "version": "3.0.0", 4 | "description": "Search GitHub repositories", 5 | "license": "MIT", 6 | "repository": "kevva/github-search-repos", 7 | "author": { 8 | "name": "Kevin Mårtensson", 9 | "email": "kevinmartensson@gmail.com", 10 | "url": "github.com/kevva" 11 | }, 12 | "engines": { 13 | "node": ">=4" 14 | }, 15 | "scripts": { 16 | "test": "xo && ava" 17 | }, 18 | "files": [ 19 | "index.js" 20 | ], 21 | "keywords": [ 22 | "api", 23 | "github", 24 | "repos", 25 | "search", 26 | "token" 27 | ], 28 | "dependencies": { 29 | "gh-got": "^5.0.0" 30 | }, 31 | "devDependencies": { 32 | "ava": "*", 33 | "xo": "*" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # github-search-repos [![Build Status](https://travis-ci.org/kevva/github-search-repos.svg?branch=master)](https://travis-ci.org/kevva/github-search-repos) 2 | 3 | > Search GitHub repositories 4 | 5 | 6 | ## Install 7 | 8 | ``` 9 | $ npm install --save github-search-repos 10 | ``` 11 | 12 | 13 | ## Usage 14 | 15 | ```js 16 | const githubSearchRepos = require('github-search-repos'); 17 | 18 | githubSearchRepos('gulp+language:javascript').then(data => { 19 | console.log(data.items); 20 | //=> [{id: 11167738, name: 'gulp', full_name: 'gulpjs/gulp', ...}, ...] 21 | }); 22 | ``` 23 | 24 | ## API 25 | 26 | ### githubSearchRepos(query, [options]) 27 | 28 | #### query 29 | 30 | Type: `string` 31 | 32 | [Search query.](https://help.github.com/articles/search-syntax/) 33 | 34 | #### options 35 | 36 | ##### token 37 | 38 | Type: `string` 39 | 40 | Token to authenticate with. Use this to increase the request count. Github supports up to 5 unauthenticated request per minute. 41 | 42 | If you don't have a token you can generate a new one [here](https://github.com/settings/tokens/new). 43 | 44 | ##### sort 45 | 46 | Type: `string` 47 | 48 | Sort results by either `stars` , `forks` or `updated`. By default, results are sorted by best match. 49 | 50 | 51 | ## Related 52 | 53 | * [github-search-repos-cli](https://github.com/kevva/github-search-repos-cli) - CLI for this module 54 | 55 | 56 | ## License 57 | 58 | MIT © [Kevin Mårtensson](https://github.com/kevva) 59 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import m from './'; 3 | 4 | test('search for repositories', async t => { 5 | const data = await m('gulp+language:javascript', {token: process.env.GITHUB_TOKEN}); 6 | 7 | t.falsy(data.incomplete_results); 8 | t.truthy(data.items.length); 9 | t.is(data.items[0].name, 'gulp'); 10 | }); 11 | 12 | test('accepts a string', async t => { 13 | await t.throws(m({}), 'Expected a `string`, got `object`'); 14 | }); 15 | --------------------------------------------------------------------------------