├── .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 | const githubRepos = require('github-repositories'); 4 | const githubTokenUser = require('github-token-user'); 5 | 6 | const deleteRepo = (repo, token) => ghGot.delete(`repos/${repo.full_name}`, {token}).then(() => repo); 7 | 8 | module.exports = opts => { 9 | opts = opts || {}; 10 | 11 | if (!opts.token) { 12 | return Promise.reject(new Error('Token is required to authenticate with Github')); 13 | } 14 | 15 | return githubTokenUser(opts.token) 16 | .then(data => githubRepos(data.login, {token: opts.token})) 17 | .then(data => data.filter(x => x.fork)) 18 | .then(data => Promise.all(data.map(x => deleteRepo(x, opts.token)))); 19 | }; 20 | -------------------------------------------------------------------------------- /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-remove-forks", 3 | "version": "2.0.0", 4 | "description": "Remove all forked repositories", 5 | "license": "MIT", 6 | "repository": "kevva/github-remove-forks", 7 | "author": { 8 | "name": "Kevin Mårtensson", 9 | "email": "kevinmartensson@gmail.com", 10 | "url": "https://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 | "cli", 24 | "forks", 25 | "github", 26 | "repo", 27 | "repository" 28 | ], 29 | "dependencies": { 30 | "gh-got": "^5.0.0", 31 | "github-repositories": "3.0.0", 32 | "github-token-user": "^3.0.0" 33 | }, 34 | "devDependencies": { 35 | "ava": "*", 36 | "nock": "^9.0.13", 37 | "xo": "*" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # github-remove-forks [![Build Status](https://travis-ci.org/kevva/github-remove-forks.svg?branch=master)](https://travis-ci.org/kevva/github-remove-forks) 2 | 3 | > Remove all forked repositories 4 | 5 | 6 | ## Install 7 | 8 | ``` 9 | $ npm install --save github-remove-forks 10 | ``` 11 | 12 | 13 | ## Usage 14 | 15 | ```js 16 | const githubRemoveForks = require('github-remove-forks'); 17 | 18 | githubRemoveForks({token: '523ef691191'}).then(data => { 19 | console.log('Successfully remove all forked repositories'); 20 | }); 21 | ``` 22 | 23 | 24 | ## API 25 | 26 | ### githubRemoveForks(options) 27 | 28 | Returns a promise for an `Array` with the removed repositories. 29 | 30 | #### options 31 | 32 | ##### token 33 | 34 | *Required*
35 | Type: `string` 36 | 37 | Token to authenticate with. If you don't have a token you can generate a new one [here](https://github.com/settings/tokens/new). 38 | 39 | 40 | ## Related 41 | 42 | - [github-remove-all-releases](https://github.com/stevemao/github-remove-all-releases) - Remove all releases of a GitHub repo 43 | 44 | 45 | ## License 46 | 47 | MIT © [Kevin Mårtensson](https://github.com/kevva) 48 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable camelcase */ 2 | import nock from 'nock'; 3 | import test from 'ava'; 4 | import m from './'; 5 | 6 | test.before(() => { 7 | nock('https://api.github.com', {reqheaders: {authorization: `token ${process.env.GH_TOKEN}`}}) 8 | .persist() 9 | .get('/user') 10 | .reply(200, {login: 'kevva'}) 11 | .get('/users/kevva/repos') 12 | .query(true) 13 | .reply(200, [{ 14 | full_name: 'kevva/playground', 15 | fork: false 16 | }, { 17 | full_name: 'kevva/github-remove-forks', 18 | fork: true 19 | }, { 20 | full_name: 'kevva/unicorn', 21 | fork: true 22 | }]) 23 | .delete('/repos/kevva/github-remove-forks') 24 | .reply(200, { 25 | full_name: 'kevva/github-remove-forks', 26 | fork: true 27 | }) 28 | .delete('/repos/kevva/unicorn') 29 | .reply(200, { 30 | full_name: 'kevva/unicorn', 31 | fork: true 32 | }); 33 | }); 34 | 35 | test(async t => { 36 | const [githubRemoveForks, unicorn, ...repos] = await m({token: process.env.GH_TOKEN}); 37 | 38 | t.is(repos.length, 0); 39 | t.is(githubRemoveForks.full_name, 'kevva/github-remove-forks'); 40 | t.is(unicorn.full_name, 'kevva/unicorn'); 41 | }); 42 | --------------------------------------------------------------------------------