Created
September 19, 2021 00:00
-
-
Save maraisr/b071cdbb4b295daa1b81a2c757fceb1c to your computer and use it in GitHub Desktop.
Clean Forks on GitHub
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
import { Octokit } from '@octokit/rest'; | |
const client = new Octokit({ | |
auth: process.env.GITHUB_TOKEN, | |
}); | |
const repos = await client.repos.listForUser({ | |
username: 'maraisr', | |
per_page: 200, | |
}); | |
console.log(`repo count: ${repos.data.length}`); | |
const forks = repos.data.filter((i) => i.fork); | |
console.log(`forks count: ${forks.data?.length ?? 0}`); | |
const fork_prs = await Promise.all( | |
forks.map(async (repo) => { | |
const prs = await client.pulls.list({ | |
owner: repo.owner.login, | |
repo: repo.name, | |
per_page: 200, | |
}); | |
return { repo, prs: prs.data }; | |
}) | |
); | |
const promises = []; | |
for (const fork of fork_prs) { | |
const has_open = fork.prs.find((i) => i.state === 'open'); | |
console.log(`fork open prs: ${fork.prs.filter((i) => i.state === 'open').length}`); | |
if (has_open) { | |
console.log(`[OPEN] ${has_open.html_url}`); | |
} else { | |
console.log(`[DELETE] ${fork.repo.html_url}`); | |
promises.push( | |
client.repos.delete({ | |
owner: fork.repo.owner.login, | |
repo: fork.repo.name, | |
}) | |
); | |
} | |
} | |
await Promise.all(promises); |
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
{ | |
"type": "module", | |
"dependencies": { | |
"@octokit/rest": "^18.10.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment