Use glob for path param

This was done such that multiple files
can be loaded that match given glob
patterns. Existing behaviour is preserved
for exact match.
This commit is contained in:
Sam 2022-10-25 00:49:33 +00:00
parent 437c49a57c
commit 1d46172340
10 changed files with 2660 additions and 55 deletions

View file

@ -2,6 +2,7 @@ import * as core from "@actions/core"
import {ReportedContentClassifiers} from "@octokit/graphql-schema"
import {context} from "@actions/github"
import {readFileSync} from "fs"
import {create} from "@actions/glob"
export const pullRequestNumber =
context?.payload?.pull_request?.number ||
@ -24,8 +25,6 @@ export const deleteOldComment = core.getBooleanInput("delete", {required: true})
export const hideOldComment = core.getBooleanInput("hide", {required: true})
export const githubToken = core.getInput("GITHUB_TOKEN", {required: true})
export const body = buildBody()
function buildRepo(): {repo: string; owner: string} {
return {
owner: context.repo.owner,
@ -33,11 +32,19 @@ function buildRepo(): {repo: string; owner: string} {
}
}
function buildBody(): string {
const path = core.getInput("path", {required: false})
if (path) {
export async function getBody(): Promise<string> {
const pathInput = core.getMultilineInput("path", {required: false})
const followSymbolicLinks =
core.getInput("follow-symbolic-links").toLocaleUpperCase() !== "FALSE"
if (pathInput && pathInput.length > 0) {
try {
return readFileSync(path, "utf-8")
const globber = await create(pathInput.join("\n"), {
followSymbolicLinks,
matchDirectories: false
})
return (await globber.glob())
.map(path => readFileSync(path, "utf-8"))
.join("\n")
} catch (error) {
if (error instanceof Error) {
core.setFailed(error.message)

View file

@ -2,7 +2,7 @@ import * as core from "@actions/core"
import * as github from "@actions/github"
import {
append,
body,
getBody,
deleteOldComment,
githubToken,
header,
@ -30,6 +30,8 @@ async function run(): Promise<undefined> {
}
try {
const body = await getBody()
if (!deleteOldComment && !hideOldComment && !body) {
throw new Error("Either message or path input is required")
}