From f9e9d7789661eb082810094763d1843c746fb09d Mon Sep 17 00:00:00 2001 From: hugoalh Date: Fri, 1 Nov 2024 17:55:27 +0800 Subject: [PATCH] Update dependencies --- _parameter.ts | 90 --------------------------------------------------- deno.jsonc | 5 ++- mod.ts | 46 +++++++++++++------------- 3 files changed, 26 insertions(+), 115 deletions(-) delete mode 100644 _parameter.ts diff --git a/_parameter.ts b/_parameter.ts deleted file mode 100644 index 63b588f7..00000000 --- a/_parameter.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { isStringSingleLine } from "ISSTRINGSINGLELINE"; -export interface GitHubActionsInputOptions { - defaultValue?: T; - /** - * Whether the input is require. - * @default false - */ - require?: boolean; -} -/** - * Get the raw value of an input. - * - * > **🛡️ Require Permission** - * > - * > - Environment Variable (`allow-env`) - * @param {string} key Key of the input. - * @returns {string} Raw value of the input. - */ -function getInputRaw(key: string): string { - if (!isStringSingleLine(key)) { - throw new SyntaxError(`\`${key}\` is not a valid GitHub Actions input key!`); - } - return Deno.env.get(`INPUT_${key.replaceAll(" ", "_").toUpperCase()}`) ?? ""; -} -/** - * Get the value of an input. - * - * > **🛡️ Require Permission** - * > - * > - Environment Variable (`allow-env`) - * @param {string} key Key of the input. - * @param {GitHubActionsInputOptions} [options={}] Options. - * @returns {string} Value of the input. - */ -export function getInput(key: string, options: GitHubActionsInputOptions = {}): string { - const value: string = getInputRaw(key); - if (value.length === 0) { - if (options.require) { - throw new ReferenceError(`Input \`${key}\` is not defined!`); - } - return options.defaultValue ?? ""; - } - return value; -} -/** - * Get the boolean value of an input. - * - * > **🛡️ Require Permission** - * > - * > - Environment Variable (`allow-env`) - * @param {string} key Key of the input. - * @param {GitHubActionsInputOptions} [options={}] Options. - * @returns {boolean} Boolean value of the input. - */ -export function getInputBoolean(key: string, options: GitHubActionsInputOptions = {}): boolean { - const value: string = getInputRaw(key); - if (value.length === 0) { - if (options.require) { - throw new ReferenceError(`Input \`${key}\` is not defined!`); - } - return options.defaultValue ?? false; - } - if (/^[Ff]alse$|^FALSE$/.test(value)) { - return false; - } - if (/^[Tt]rue$|^TRUE$/.test(value)) { - return true; - } - throw new SyntaxError(`\`${value}\` (input \`${key}\`) is not a valid boolean!`); -} -/** - * Get the number value of an input. - * - * > **🛡️ Require Permission** - * > - * > - Environment Variable (`allow-env`) - * @param {string} key Key of the input. - * @param {GitHubActionsInputOptions} [options={}] Options. - * @returns {number} Number value of the input. - */ -export function getInputNumber(key: string, options: GitHubActionsInputOptions = {}): number { - const value: string = getInputRaw(key); - if (value.length === 0) { - if (options.require) { - throw new ReferenceError(`Input \`${key}\` is not defined!`); - } - return options.defaultValue ?? 0; - } - return Number(value); -} diff --git a/deno.jsonc b/deno.jsonc index 6d39c522..80e2c7eb 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -12,9 +12,8 @@ "COLOR": "npm:color@4.2.3", "COLORNAMESPACELISTCOMMUNITY": "npm:color-name-list@10.28.0/dist/colornames.esm.js", "EXFETCH": "jsr:@hugoalh/exfetch@0.5.1", - "GHACTIONS": "jsr:@hugoalh/github-actions-core@0.2.1", - "ISJSON": "jsr:@hugoalh/is-json@1.0.2", - "ISSTRINGSINGLELINE":"jsr:@hugoalh/is-string-singleline@1.0.2", + "GHACTIONS": "jsr:@hugoalh/github-actions-core@0.3.0", + "ISJSON": "jsr:@hugoalh/is-json@1.0.4", "REGEXPURL": "npm:url-regex-safe@4.0.0", "STD/assert": "jsr:@std/assert@1.0.6", "STD/fs": "jsr:@std/fs@1.0.4", diff --git a/mod.ts b/mod.ts index d36ffd3f..7384d799 100644 --- a/mod.ts +++ b/mod.ts @@ -7,18 +7,18 @@ import { writeDebug, writeError } from "GHACTIONS/log"; -import { setOutput } from "GHACTIONS/parameter"; +import { + getInput, + getInputBoolean, + getInputNumber, + setOutput +} from "GHACTIONS/parameter"; import type { JSONArray, JSONObject, } from "ISJSON"; import { parse as yamlParse } from "STD/yaml/parse"; import { StringTruncator } from "STRINGOVERFLOW"; -import { - getInput, - getInputBoolean, - getInputNumber -} from "./_parameter.ts"; import { resolveContent, resolveEmbeds, @@ -42,11 +42,11 @@ writeDebug(`Environment Variables:\n\t${Object.entries(Deno.env.toObject()).map( }).join("\n\t")}`); console.log("Parse input."); try { - const truncateEnable: boolean = getInputBoolean("truncate_enable", { defaultValue: true }); + const truncateEnable: boolean = getInputBoolean("truncate_enable", { fallback: false }) ?? true; const stringTruncator: StringTruncator | undefined = truncateEnable ? new StringTruncator(128, { - ellipsisMark: getInput("truncate_ellipsis", { defaultValue: "..." }), - //@ts-ignore Validate by package. - ellipsisPosition: getInput("truncate_position", { defaultValue: "end" }) + ellipsisMark: getInput("truncate_ellipsis", { fallback: false }), + //@ts-ignore Validate by the module. + ellipsisPosition: getInput("truncate_position", { fallback: false }) }) : undefined; const key: string = resolveKey(getInput("key", { require: true })); addSecretMask(key); @@ -57,20 +57,20 @@ try { }), stringTruncator); const embeds: JSONArray | undefined = resolveEmbeds(yamlParse(getInput("embeds")), stringTruncator); const poll: JSONObject | undefined = resolvePoll({ - allowMultiSelect: getInputBoolean("poll_allow_multiselect", { defaultValue: false }), + allowMultiSelect: getInputBoolean("poll_allow_multiselect"), answers: yamlParse(getInput("poll_answers")), - duration: getInputNumber("poll_duration", { defaultValue: -1 }), + duration: getInputNumber("poll_duration", { fallback: false }) ?? -1, question: getInput("poll_question") }); const files: FormData | undefined = await resolveFiles(getInput("files").split(splitterNewLine).map((file: string) => { return file.trim(); }).filter((file: string): boolean => { return (file.length > 0); - }), getInputBoolean("files_glob", { defaultValue: true })); + }), getInputBoolean("files_glob", { fallback: false }) ?? true); const allowedMentions: JSONObject = resolveMentions({ - parseEveryone: getInputBoolean("allowed_mentions_parse_everyone", { defaultValue: true }), - parseRoles: getInputBoolean("allowed_mentions_parse_roles", { defaultValue: true }), - parseUsers: getInputBoolean("allowed_mentions_parse_users", { defaultValue: true }), + parseEveryone: getInputBoolean("allowed_mentions_parse_everyone", { fallback: false }) ?? true, + parseRoles: getInputBoolean("allowed_mentions_parse_roles", { fallback: false }) ?? true, + parseUsers: getInputBoolean("allowed_mentions_parse_users", { fallback: false }) ?? true, roles: getInput("allowed_mentions_roles").split(splitterCommonDelimiter).map((value: string): string => { return value.trim(); }).filter((value: string): boolean => { @@ -90,8 +90,8 @@ try { }).filter((value: string): boolean => { return (value.length > 0); })); - const notification: boolean = getInputBoolean("notification", { defaultValue: true }); - const wait: boolean = getInputBoolean("wait", { defaultValue: true }); + const notification: boolean = getInputBoolean("notification", { fallback: false }) ?? true; + const wait: boolean = getInputBoolean("wait", { fallback: false }) ?? true; if ( (typeof content === "undefined" && typeof embeds === "undefined" && typeof files === "undefined" && typeof poll === "undefined") || (( @@ -170,10 +170,12 @@ try { throw new Error(`Unexpected web request issue: ${reason?.message ?? reason}`); }); const responseText = await response.text(); - setOutput("response", responseText); - setOutput("status_code", String(response.status)); - setOutput("status_ok", String(response.ok)); - setOutput("status_text", response.statusText); + setOutput({ + "response": responseText, + "status_code": String(response.status), + "status_ok": String(response.ok), + "status_text": response.statusText + }); if (!response.ok) { throw new Error(`Unexpected response status \`${response.status} ${response.statusText}\`: ${responseText}`); }