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