import { getOctokit } from '@actions/github' ; import * as core from '@actions/core' ; const emailErrorMessage = 'Unable to find author\'s email. Either ensure that the token\'s Github Account has the email ' + 'privacy feature disabled for at least one email or use the `author-email` input to provide one.' ; const nameErrorMessage = 'Unable to find author\'s name. Either ensure that the token\'s Github Account has a valid name ' + 'set in its profile or use the `author-name` input to provide one.' ; param { string } token returns { Promise < AuthUser > } export async function getAuthUser ( token ) { const github = getOctokit ( token ) ; try { const auth = await github . rest . users . getAuthenticated ( ) ; const { login , email , name } = auth . data ; core . info ( '✓ User information retrieved from Github' ) ; core . debug ( `- Login: ${ login }` ) ; core . debug ( `- Email: ${ email ?? 'no email found' }` ) ; core . debug ( `- Name: ${ name ?? 'no name found' }` ) ; return { login : ( ) => { if ( ! login ) { throw new Error ( 'Unable to retrieve user information from Github' ) ; } return login ; } , email : ( ) => { if ( ! email ) { throw new Error ( emailErrorMessage ) ; } return email ; } , name : ( ) => { if ( ! name ) { throw new Error ( nameErrorMessage ) ; } return name ; } , } ; } catch ( error ) { core . debug ( `- User information retrieve Error: ${ ( error as Error ) . message }` ) ; return { login : ( ) => 'github-actions[bot]' , email : ( ) => '41898282+github-actions[bot]@users.noreply.github.com' , name : ( ) => 'github-actions[bot]' , } ; } } interface AuthUser { email : ( ) => string ; login : ( ) => string ; name : ( ) => string ; }