Last active
February 28, 2022 11:53
-
-
Save cbdyzj/82d2885835fecca55c237007da38386e to your computer and use it in GitHub Desktop.
Backup GitHub Public Repositories
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
async function getRepositoryCloneListByPage(name, page = 1) { | |
const response = await fetch(`https://api.github.com/users/${name}/repos?page=${page}`) | |
const result = await response.json() | |
return result.map((it) => { | |
return it.clone_url | |
}) | |
} | |
async function getRepositoryCloneList(name) { | |
let page = 1 | |
let cloneList = [] | |
let currentCloneList | |
do { | |
currentCloneList = await getRepositoryCloneListByPage(name, page) | |
cloneList.push(...currentCloneList) | |
page++ | |
} while (currentCloneList.length); | |
return cloneList | |
} | |
async function cloneRepositoryList(name) { | |
const cloneList = await getRepositoryCloneList(name) | |
if (!cloneList.length) { | |
return | |
} | |
for (const cloneUrl of cloneList) { | |
let done = false | |
while(!done) { | |
try { | |
await $`git clone ${cloneUrl}` | |
done = true | |
} catch(err) { | |
console.log('Error:', err.message, ', Try again...') | |
} | |
} | |
} | |
} | |
await cloneRepositoryList('cbdyzj') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment