Add ignore empty input

This commit is contained in:
Sam 2022-10-25 21:49:30 +00:00
parent 1d46172340
commit db01d1ad6c
6 changed files with 78 additions and 20 deletions

View file

@ -9,6 +9,8 @@ beforeEach(() => {
process.env["INPUT_HIDE_CLASSIFY"] = "OUTDATED"
process.env["INPUT_HIDE_DETAILS"] = "false"
process.env["INPUT_GITHUB_TOKEN"] = "some-token"
process.env["INPUT_IGNORE_EMPTY"] = "false"
process.env["INPUT_FOLLOW_SYMBOLIC_LINKS"] = "false"
})
afterEach(() => {
@ -27,6 +29,8 @@ afterEach(() => {
delete process.env["INPUT_HIDE_DETAILS"]
delete process.env["INPUT_GITHUB_TOKEN"]
delete process.env["INPUT_PATH"]
delete process.env["INPUT_IGNORE_EMPTY"]
delete process.env["INPUT_FOLLOW_SYMBOLIC_LINKS"]
})
test("repo", async () => {
@ -42,7 +46,8 @@ test("repo", async () => {
hideAndRecreate: false,
hideClassify: "OUTDATED",
hideDetails: false,
githubToken: "some-token"
githubToken: "some-token",
ignoreEmpty: false
})
expect(await require("../src/config").getBody()).toEqual("")
})
@ -59,7 +64,8 @@ test("header", async () => {
hideAndRecreate: false,
hideClassify: "OUTDATED",
hideDetails: false,
githubToken: "some-token"
githubToken: "some-token",
ignoreEmpty: false
})
expect(await require("../src/config").getBody()).toEqual("")
})
@ -76,7 +82,8 @@ test("append", async () => {
hideAndRecreate: false,
hideClassify: "OUTDATED",
hideDetails: false,
githubToken: "some-token"
githubToken: "some-token",
ignoreEmpty: false
})
expect(await require("../src/config").getBody()).toEqual("")
})
@ -93,7 +100,8 @@ test("recreate", async () => {
hideAndRecreate: false,
hideClassify: "OUTDATED",
hideDetails: false,
githubToken: "some-token"
githubToken: "some-token",
ignoreEmpty: false
})
expect(await require("../src/config").getBody()).toEqual("")
})
@ -110,7 +118,8 @@ test("delete", async () => {
hideAndRecreate: false,
hideClassify: "OUTDATED",
hideDetails: false,
githubToken: "some-token"
githubToken: "some-token",
ignoreEmpty: false
})
expect(await require("../src/config").getBody()).toEqual("")
})
@ -127,7 +136,8 @@ test("hideOldComment", async () => {
hideAndRecreate: false,
hideClassify: "OUTDATED",
hideDetails: false,
githubToken: "some-token"
githubToken: "some-token",
ignoreEmpty: false
})
expect(await require("../src/config").getBody()).toEqual("")
})
@ -144,7 +154,8 @@ test("hideAndRecreate", async () => {
hideAndRecreate: true,
hideClassify: "OUTDATED",
hideDetails: false,
githubToken: "some-token"
githubToken: "some-token",
ignoreEmpty: false
})
expect(await require("../src/config").getBody()).toEqual("")
})
@ -161,7 +172,8 @@ test("hideClassify", async () => {
hideAndRecreate: false,
hideClassify: "OFF_TOPIC",
hideDetails: false,
githubToken: "some-token"
githubToken: "some-token",
ignoreEmpty: false
})
expect(await require("../src/config").getBody()).toEqual("")
})
@ -178,7 +190,8 @@ test("hideDetails", async () => {
hideAndRecreate: false,
hideClassify: "OUTDATED",
hideDetails: true,
githubToken: "some-token"
githubToken: "some-token",
ignoreEmpty: false
})
expect(await require("../src/config").getBody()).toEqual("")
})
@ -196,7 +209,8 @@ describe("path", () => {
hideAndRecreate: false,
hideClassify: "OUTDATED",
hideDetails: false,
githubToken: "some-token"
githubToken: "some-token",
ignoreEmpty: false
})
expect(await require("../src/config").getBody()).toEqual("hi there\n")
})
@ -214,7 +228,8 @@ describe("path", () => {
hideAndRecreate: false,
hideClassify: "OUTDATED",
hideDetails: false,
githubToken: "some-token"
githubToken: "some-token",
ignoreEmpty: false
})
expect(await require("../src/config").getBody()).toEqual(
"hi there\n\nhey there\n"
@ -234,7 +249,8 @@ describe("path", () => {
hideAndRecreate: false,
hideClassify: "OUTDATED",
hideDetails: false,
githubToken: "some-token"
githubToken: "some-token",
ignoreEmpty: false
})
expect(await require("../src/config").getBody()).toEqual("")
})
@ -253,7 +269,27 @@ test("message", async () => {
hideAndRecreate: false,
hideClassify: "OUTDATED",
hideDetails: false,
githubToken: "some-token"
githubToken: "some-token",
ignoreEmpty: false
})
expect(await require("../src/config").getBody()).toEqual("hello there")
})
test("ignore_empty", async () => {
process.env["INPUT_IGNORE_EMPTY"] = "true"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
header: "",
append: false,
recreate: false,
deleteOldComment: false,
hideOldComment: false,
hideAndRecreate: false,
hideClassify: "OUTDATED",
hideDetails: false,
githubToken: "some-token",
ignoreEmpty: true
})
expect(await require("../src/config").getBody()).toEqual("")
})

View file

@ -40,8 +40,13 @@ inputs:
path:
description: "glob path to file(s) containing comment message"
required: false
follow-symbolic-links:
ignore_empty:
description: "Indicates whether to ignore missing or empty messages"
default: "true"
required: false
follow_symbolic_links:
description: "Indicates whether to follow symbolic links for path"
default: "false"
required: false
number:
description: "pull request number for push event"

12
dist/index.js generated vendored
View file

@ -207,7 +207,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
var _a, _b;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getBody = exports.githubToken = exports.hideOldComment = exports.deleteOldComment = exports.hideClassify = exports.hideAndRecreate = exports.recreate = exports.hideDetails = exports.append = exports.header = exports.repo = exports.pullRequestNumber = void 0;
exports.getBody = exports.ignoreEmpty = exports.githubToken = exports.hideOldComment = exports.deleteOldComment = exports.hideClassify = exports.hideAndRecreate = exports.recreate = exports.hideDetails = exports.append = exports.header = exports.repo = exports.pullRequestNumber = void 0;
const core = __importStar(__nccwpck_require__(2186));
const github_1 = __nccwpck_require__(5438);
const fs_1 = __nccwpck_require__(7147);
@ -230,6 +230,9 @@ exports.hideClassify = core.getInput("hide_classify", {
exports.deleteOldComment = core.getBooleanInput("delete", { required: true });
exports.hideOldComment = core.getBooleanInput("hide", { required: true });
exports.githubToken = core.getInput("GITHUB_TOKEN", { required: true });
exports.ignoreEmpty = core.getBooleanInput("ignore_empty", {
required: true
});
function buildRepo() {
return {
owner: github_1.context.repo.owner,
@ -239,7 +242,9 @@ function buildRepo() {
function getBody() {
return __awaiter(this, void 0, void 0, function* () {
const pathInput = core.getMultilineInput("path", { required: false });
const followSymbolicLinks = core.getInput("follow-symbolic-links").toLocaleUpperCase() !== "FALSE";
const followSymbolicLinks = core.getBooleanInput("follow_symbolic_links", {
required: true
});
if (pathInput && pathInput.length > 0) {
try {
const globber = yield (0, glob_1.create)(pathInput.join("\n"), {
@ -317,6 +322,9 @@ function run() {
}
try {
const body = yield (0, config_1.getBody)();
if (!body && config_1.ignoreEmpty) {
return;
}
if (!config_1.deleteOldComment && !config_1.hideOldComment && !body) {
throw new Error("Either message or path input is required");
}

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -24,6 +24,9 @@ export const hideClassify = core.getInput("hide_classify", {
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 ignoreEmpty = core.getBooleanInput("ignore_empty", {
required: true
})
function buildRepo(): {repo: string; owner: string} {
return {
@ -34,8 +37,9 @@ function buildRepo(): {repo: string; owner: string} {
export async function getBody(): Promise<string> {
const pathInput = core.getMultilineInput("path", {required: false})
const followSymbolicLinks =
core.getInput("follow-symbolic-links").toLocaleUpperCase() !== "FALSE"
const followSymbolicLinks = core.getBooleanInput("follow_symbolic_links", {
required: true
})
if (pathInput && pathInput.length > 0) {
try {
const globber = await create(pathInput.join("\n"), {

View file

@ -12,7 +12,8 @@ import {
hideOldComment,
pullRequestNumber,
recreate,
repo
repo,
ignoreEmpty
} from "./config"
import {
createComment,
@ -32,6 +33,10 @@ async function run(): Promise<undefined> {
try {
const body = await getBody()
if (!body && ignoreEmpty) {
return
}
if (!deleteOldComment && !hideOldComment && !body) {
throw new Error("Either message or path input is required")
}