Created
June 27, 2019 20:36
-
-
Save tibdex/d6b63cc82356f8270d03ba56d85c7235 to your computer and use it in GitHub Desktop.
List all repositories that a GitHub App can access.
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
const { App } = require("@octokit/app"); // ^3.0.0 | |
const Octokit = require("@octokit/rest"); // ^16.25.0 | |
const APP_ID = 1337; | |
const PRIVATE_KEY = `-----BEGIN RSA PRIVATE KEY----- | |
... | |
your private key content | |
... | |
-----END RSA PRIVATE KEY-----`; | |
const listAccessibleRepos = async ({ appId, privateKey }) => { | |
const app = new App({ id: appId, privateKey }); | |
const jwt = await app.getSignedJsonWebToken(); | |
const octokit = new Octokit({ auth: `Bearer ${jwt}` }); | |
const options = octokit.apps.listInstallations.endpoint.merge(); | |
const data = await octokit.paginate(options); | |
const installationIds = data.map(({ id }) => id); | |
const allUrls = await Promise.all( | |
installationIds.map(async installationId => { | |
const installationAccessToken = await app.getInstallationAccessToken({ | |
installationId, | |
}); | |
const installationOctokit = new Octokit({ | |
auth: `token ${installationAccessToken}`, | |
previews: ["machine-man-preview"], | |
}); | |
const { | |
data: { repositories }, | |
} = await installationOctokit.apps.listRepos(); | |
const urls = repositories.map(({ html_url }) => html_url); | |
return urls; | |
}), | |
); | |
console.log(allUrls); | |
}; | |
listAccessibleRepos({ appId: APP_ID, privateKey: PRIVATE_KEY }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment