Skip to content

Instantly share code, notes, and snippets.

@richgilbank
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richgilbank/d3dd0ef3bced5c662d8c to your computer and use it in GitHub Desktop.
Save richgilbank/d3dd0ef3bced5c662d8c to your computer and use it in GitHub Desktop.
Git Clone Organization
#! /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