Skip to content

Commit 245f959

Browse files
committed
fix: drop require
1 parent 724766a commit 245f959

File tree

4 files changed

+42
-18
lines changed

4 files changed

+42
-18
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212
sourceType: 'module'
1313
},
1414
plugins: ['@typescript-eslint'],
15+
ignorePatterns: ['lib/*'],
1516
rules: {
1617
'prettier/prettier': 'warn',
1718
'no-cond-assign': [2, 'except-parens'],

lib/index.js

Lines changed: 21 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
matchGitArgs,
1717
outputs,
1818
parseBool,
19+
readJSON,
1920
setOutput
2021
} from './util'
2122

@@ -187,8 +188,9 @@ async function checkInputs() {
187188
}
188189

189190
const eventPath = process.env.GITHUB_EVENT_PATH,
190-
event = eventPath && require(eventPath),
191-
isPR = process.env.GITHUB_EVENT_NAME?.includes('pull_request'),
191+
event = eventPath && readJSON(eventPath)
192+
193+
const isPR = process.env.GITHUB_EVENT_NAME?.includes('pull_request'),
192194
defaultBranch = isPR
193195
? (event?.pull_request?.head?.ref as string)
194196
: process.env.GITHUB_REF?.substring(11)

src/util.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as core from '@actions/core'
2+
import fs from 'fs'
23

34
export type Input =
45
| 'add'
@@ -49,6 +50,21 @@ export function parseBool(value: any) {
4950
} catch {}
5051
}
5152

53+
export function readJSON(filePath: string) {
54+
let fileContent: string
55+
try {
56+
fileContent = fs.readFileSync(filePath, { encoding: 'utf8' })
57+
} catch {
58+
throw `Couldn't read file. File path: ${filePath}`
59+
}
60+
61+
try {
62+
return JSON.parse(fileContent)
63+
} catch {
64+
throw `Couldn't parse file to JSON. File path: ${filePath}`
65+
}
66+
}
67+
5268
export function setOutput(name: Output, value: 'true' | 'false') {
5369
core.debug(`Setting output: ${name}=${value}`)
5470
outputs[name] = value

0 commit comments

Comments
 (0)