Last active
May 14, 2018 21:56
-
-
Save tcbyrd/f0be16af6afc614fff112924351a1762 to your computer and use it in GitHub Desktop.
Get all pending repo invitations
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
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