Skip to content

Instantly share code, notes, and snippets.

@tcbyrd
Last active May 14, 2018 21:56
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 tcbyrd/f0be16af6afc614fff112924351a1762 to your computer and use it in GitHub Desktop.
Save tcbyrd/f0be16af6afc614fff112924351a1762 to your computer and use it in GitHub Desktop.
Get all pending repo invitations
const octokit = require('@octokit/rest')()
const token = process.env.OCTOKIT_TOKEN
octokit.authenticate({ type: 'token', token })
async function getInvitations (org) {
try {
let result = await octokit.repos.getForOrg({org, per_page: 100})
let repos = result.data
while (octokit.hasNextPage(result)) {
console.log('getting next page')
result = await octokit.getNextPage(result)
repos = repos.concat(result.data)
}
let invites = []
for (const repo of repos) {
console.log(`Processing ${repo.name}`)
invites.push({
repo_name: repo.name,
invites: (await octokit.repos.getInvites({
owner: org,
repo: repo.name
})).data
})
}
return invites
} catch (err) {
console.log(err)
}
}
async function printInvites (org) {
try {
const invites = await getInvitations(org)
for (const repo of invites) {
for (const invite of repo.invites) {
const { invitee, inviter, repository, created_at, permissions } = invite
console.log(`${repository.name}: ${inviter.login} invited ${invitee.login} on ${created_at} with ${permissions} permissions`)
}
}
} catch (err) {
console.log(err)
}
}
printInvites('<org_name>')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment