Last active
August 29, 2015 14:08
-
-
Save richgilbank/d3dd0ef3bced5c662d8c to your computer and use it in GitHub Desktop.
Git Clone Organization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/local/bin/node | |
var exec = require('child_process').exec; | |
var readline = require('readline').createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
function Cloner() { | |
var _this = this; | |
readline.question('Enter your personal access token:', _this.onAccessToken.bind(this)); | |
}; | |
Cloner.prototype.onAccessToken = function(accessToken) { | |
readline.close(); | |
var _this = this; | |
var apiCmd = 'curl -sS -u ' + accessToken + ':x-oauth-basic https://api.github.com/orgs/jetcooper/repos'; | |
exec(apiCmd, function(error, stdout, stderr) { | |
_this.repos = JSON.parse(stdout); | |
if(_this.repos.length) { | |
_this.cloneRepo(0); | |
} | |
}); | |
} | |
Cloner.prototype.cloneRepo = function(index) { | |
var _this = this; | |
var repo = _this.repos[index]; | |
process.stdout.write("Cloning " + repo.name + "\n"); | |
exec('git clone ' + repo.ssh_url, function(error, stdout, stderr) { | |
if(error) process.stderr.write("Error cloning " + repo.name + ": " + error + "\n"); | |
if(index < _this.repos.length - 1) _this.cloneRepo(index + 1); | |
}); | |
} | |
module.exports = new Cloner(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment