Last active
June 23, 2021 05:37
-
-
Save yue4u/8aa8ba190200fc32bcf617a14a1dc659 to your computer and use it in GitHub Desktop.
Bulk transfer github repos
This file contains hidden or 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 checkRateLimit() { | |
const { data } = await octokit.rest.rateLimit.get(); | |
console.log(data); | |
return; | |
} |
This file contains hidden or 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
import dotenv from "dotenv"; | |
import fs from "fs-extra"; | |
dotenv.config(); | |
import { Octokit } from "octokit"; | |
const octokit = new Octokit({ auth: process.env.PERSONAL_ACCESS_TOKEN }); | |
const repos: any[] = []; | |
const username = "username"; | |
async function main() { | |
for await (const response of octokit.paginate.iterator( | |
octokit.rest.repos.listForAuthenticatedUser, | |
{ | |
username, | |
per_page: 100, | |
type: "owner", | |
} | |
)) { | |
repos.push(response.data); | |
} | |
await fs.writeJSON("repos.json", repos, { | |
encoding: "utf-8", | |
}); | |
} | |
main(); |
This file contains hidden or 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
{ | |
"name": "repo-bulk-transfer", | |
"version": "1.0.0", | |
"main": "index.js", | |
"license": "MIT", | |
"dependencies": { | |
"dotenv": "^10.0.0", | |
"fs-extra": "^10.0.0", | |
"octokit": "^1.0.5" | |
}, | |
"devDependencies": { | |
"@types/fs-extra": "^9.0.11", | |
"ts-node": "^10.0.0", | |
"typescript": "^4.3.2" | |
} | |
} |
This file contains hidden or 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
import repos from "repos.json"; | |
const owner = "owner"; | |
const new_owner = "new_owner"; | |
async function main() { | |
for (const repo of repos) { | |
console.log(`transferring ${repo}`); | |
await octokit.rest.repos.transfer({ | |
owner, | |
repo, | |
new_owner, | |
}); | |
console.log(`editing ${repo} config`); | |
await octokit.request("PATCH /repos/{owner}/{repo}", { | |
repo, | |
// private: true, | |
archived: true, | |
owner: new_owner, | |
}); | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment