import { v1 as SecretManagerV1 } from '@google-cloud/secret-manager' ; import { Octokit } from '@octokit/rest' ; export const SECRET_NAME_FOR_COMMENT_PERMISSION = 'dpebot-public-repo' ; export async function getAuthenticatedOctokit ( projectId , secretName ) { const secretsClient = new SecretManagerV1 . SecretManagerServiceClient ( ) ; const name = `projects/${ projectId }/secrets/${ secretName }/versions/latest` ; const [ version ] = await secretsClient . accessSecretVersion ( { name , } ) ; const payload = version ?. payload ?. data ?. toString ( ) || '' ; if ( payload === '' ) { throw Error ( 'did not retrieve a payload from SecretManager.' ) ; } return new Octokit ( { auth : payload } ) ; }