diff --git a/packages/github/src/context.ts b/packages/github/src/context.ts index b4230426..a06a8e0a 100644 --- a/packages/github/src/context.ts +++ b/packages/github/src/context.ts @@ -1,7 +1,7 @@ // Originally pulled from https://github.com/JasonEtco/actions-toolkit/blob/master/src/context.ts import {WebhookPayload} from './interfaces' - -/* eslint-disable @typescript-eslint/no-require-imports */ +import {readFileSync, existsSync} from 'fs' +import {EOL} from 'os' export class Context { /** @@ -20,9 +20,20 @@ export class Context { * Hydrate the context from the environment */ constructor() { - this.payload = process.env.GITHUB_EVENT_PATH - ? require(process.env.GITHUB_EVENT_PATH) - : {} + this.payload = {} + if (process.env.GITHUB_EVENT_PATH) { + if (existsSync(process.env.GITHUB_EVENT_PATH)) { + this.payload = JSON.parse( + readFileSync(process.env.GITHUB_EVENT_PATH, {encoding: 'utf8'}) + ) + } else { + process.stdout.write( + `GITHUB_EVENT_PATH ${ + process.env.GITHUB_EVENT_PATH + } does not exist${EOL}` + ) + } + } this.eventName = process.env.GITHUB_EVENT_NAME as string this.sha = process.env.GITHUB_SHA as string this.ref = process.env.GITHUB_REF as string