Last active
July 1, 2016 13:14
-
-
Save genecyber/4f65505953ec26b3bf56 to your computer and use it in GitHub Desktop.
Fork all repos for user into 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
var ForkYou = function(username, password, userToFork, forkIntoOrg, page) { | |
if (page === undefined) { | |
page = 1 | |
} | |
var USER = userToFork | |
var ORG = forkIntoOrg | |
$.ajax({ | |
url: "https://api.github.com/users/" + USER + "/repos?per_page=100&page=" + page | |
}) | |
.done(function(response) { | |
//console.info("response",response[0]) | |
var loop = function(index) { | |
var source = response[index].forks_url | |
console.log("FORKME", source) | |
$.ajax({ | |
type: 'POST', | |
beforeSend: function(xhr) { | |
xhr.setRequestHeader('Authorization', make_base_auth(username, password)); | |
}, | |
url: response[index].forks_url + "?org=" + ORG | |
}).done(function(out) { | |
console.log("My kids don't go to skool",out) | |
}) | |
index++ | |
if (index < response.length) { | |
return loop(index) | |
} | |
else if (index === 100) { | |
page++ | |
console.log("next page please",page) | |
return ForkYou(username, password, userToFork, forkIntoOrg, page) | |
} | |
} | |
loop(0) | |
}).done(function(){ | |
CheckIt(username, password, userToFork, page) | |
}) | |
} | |
var CheckIt = function(username, password, userToFork, page) { | |
if (page === undefined) { | |
page = 1 | |
} | |
var USER = userToFork | |
var SCRIPT = "" | |
$.ajax({ | |
url: "https://api.github.com/users/" + USER + "/repos?per_page=100&page=" + page | |
}) | |
.done(function(response) { | |
//console.info("response",response[0]) | |
var loop = function(index) { | |
var source = response[index].clone_url | |
SCRIPT = SCRIPT + "git clone "+source+" ;" | |
console.log(SCRIPT) | |
index++ | |
if (index < response.length) { | |
return loop(index) | |
} | |
else if (index === 100) { | |
page++ | |
console.log("next page please",page) | |
return ForkYou(username, password, userToFork, page) | |
} | |
} | |
loop(0) | |
}).done(function(){console.log("DONE ",SCRIPT)}) | |
} | |
function make_base_auth(user, password) { | |
var tok = user + ':' + password; | |
var hash = btoa(tok); | |
return "Basic " + hash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example Usage
ForkYou("username","myPass","CoolRepository","MyNewOrg")