()
| 103 | |
| 104 | /** Retrieves a Github client instance authenticated as the Angular Robot Github App. */ |
| 105 | export async function getAuthenticatedGithubClient(): Promise<Octokit> { |
| 106 | const GITHUB_APP_PEM = Buffer.from( |
| 107 | process.env['ANGULAR_ROBOT_APP_PRIVATE_KEY']!, |
| 108 | 'base64', |
| 109 | ).toString('utf-8'); |
| 110 | |
| 111 | const applicationGithub = new Octokit({ |
| 112 | authStrategy: createAppAuth, |
| 113 | auth: {appId: process.env['ANGULAR_ROBOT_APP_ID']!, privateKey: GITHUB_APP_PEM}, |
| 114 | }); |
| 115 | /** The specific installation id for the provided repository. */ |
| 116 | const {id: installation_id} = (await applicationGithub.apps.getOrgInstallation({org: 'angular'})) |
| 117 | .data; |
| 118 | /** A temporary github access token. */ |
| 119 | const {token} = ( |
| 120 | await applicationGithub.rest.apps.createInstallationAccessToken({installation_id}) |
| 121 | ).data; |
| 122 | |
| 123 | return new Octokit({auth: token}); |
| 124 | } |
no test coverage detected