mirror of https://github.com/actions/toolkit
Use readFileSync instead of require (#101)
* Use readFileSync instead of require * error handlingpull/110/head
parent
ac36ca4405
commit
99d3ad0a64
|
@ -1,7 +1,7 @@
|
||||||
// Originally pulled from https://github.com/JasonEtco/actions-toolkit/blob/master/src/context.ts
|
// Originally pulled from https://github.com/JasonEtco/actions-toolkit/blob/master/src/context.ts
|
||||||
import {WebhookPayload} from './interfaces'
|
import {WebhookPayload} from './interfaces'
|
||||||
|
import {readFileSync, existsSync} from 'fs'
|
||||||
/* eslint-disable @typescript-eslint/no-require-imports */
|
import {EOL} from 'os'
|
||||||
|
|
||||||
export class Context {
|
export class Context {
|
||||||
/**
|
/**
|
||||||
|
@ -20,9 +20,20 @@ export class Context {
|
||||||
* Hydrate the context from the environment
|
* Hydrate the context from the environment
|
||||||
*/
|
*/
|
||||||
constructor() {
|
constructor() {
|
||||||
this.payload = process.env.GITHUB_EVENT_PATH
|
this.payload = {}
|
||||||
? require(process.env.GITHUB_EVENT_PATH)
|
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.eventName = process.env.GITHUB_EVENT_NAME as string
|
||||||
this.sha = process.env.GITHUB_SHA as string
|
this.sha = process.env.GITHUB_SHA as string
|
||||||
this.ref = process.env.GITHUB_REF as string
|
this.ref = process.env.GITHUB_REF as string
|
||||||
|
|
Loading…
Reference in New Issue