From 07705104362e0049b55aa846f3c285ed4c1b1e08 Mon Sep 17 00:00:00 2001 From: sarisia Date: Sun, 11 Aug 2024 18:03:53 +0000 Subject: [PATCH] add ack_no_webhook input --- .github/workflows/test.yml | 4 +++- action.yml | 4 ++++ src/input.ts | 8 +++++--- test/input.test.ts | 9 ++++----- test/main.test.ts | 3 ++- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cebc5da0..2839b024 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,9 @@ jobs: packages: read contents: read steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + - uses: actions/checkout@v1 + with: + ref: output-payload - uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 with: diff --git a/action.yml b/action.yml index e9df6b9d..ef14f3e0 100644 --- a/action.yml +++ b/action.yml @@ -58,6 +58,10 @@ inputs: description: "Avoid appending timestamp" required: false default: "false" + ack_no_webhook: + description: "Suppress warning when webhook is not set" + required: false + default: "false" outputs: payload: diff --git a/src/input.ts b/src/input.ts index 1841e1f3..7313f01b 100644 --- a/src/input.ts +++ b/src/input.ts @@ -15,6 +15,7 @@ export interface Inputs { nocontext: boolean noprefix: boolean notimestamp: boolean + ack_no_webhook: boolean } interface StatusOption { @@ -70,12 +71,13 @@ export function getInputs(): Inputs { avatar_url: core.getInput('avatar_url').trim(), nocontext: nocontext, noprefix: noprefix, - notimestamp: stob(core.getInput('notimestamp')) + notimestamp: stob(core.getInput('notimestamp')), + ack_no_webhook: stob(core.getInput('ack_no_webhook')) } // validate - if (!inputs.webhooks.length) { - throw new Error("no webhook is given") + if (!inputs.webhooks.length && !inputs.ack_no_webhook) { + logWarning("No webhook is given. If this is intended, you can suppress this warning by setting `ack_no_webhook` to `true`.") } if (!(inputs.status in statusOpts)) { throw new Error(`invalid status value: ${inputs.status}`) diff --git a/test/input.test.ts b/test/input.test.ts index 15b9120a..f74fa7ca 100644 --- a/test/input.test.ts +++ b/test/input.test.ts @@ -16,6 +16,7 @@ describe("getInputs()", () => { process.env['INPUT_NOPREFIX'] = 'false' process.env['INPUT_NODETAIL'] = 'false' process.env['INPUT_NOTIMESTAMP'] = 'false' + process.env['INPUT_ACKNOWEBHOOK'] = 'false' // no defaults in action.yml, but need for passing validation process.env['DISCORD_WEBHOOK'] = "https://env.webhook.invalid" @@ -34,11 +35,7 @@ describe("getInputs()", () => { expect(got.color).toBe(undefined) expect(got.username).toBe('') expect(got.avatar_url).toBe('') - }) - - test("no webhooks", () => { - delete process.env['DISCORD_WEBHOOK'] - expect(getInputs).toThrow("no webhook is given") + expect(got.ack_no_webhook).toBe(false) }) test("invalid status", () => { @@ -130,6 +127,7 @@ describe("getInputs()", () => { process.env['INPUT_COLOR'] = '0xffffff' process.env['INPUT_USERNAME'] = 'jest test' process.env['INPUT_AVATAR_URL'] = '\n\n\nhttps://avatar.webhook.invalid\n' + process.env['INPUT_ACK_NO_WEBHOOK'] = 'true' const got = getInputs() expect(got.noprefix).toBe(true) @@ -146,5 +144,6 @@ describe("getInputs()", () => { expect(got.color).toBe(0xffffff) expect(got.username).toBe('jest test') expect(got.avatar_url).toBe('https://avatar.webhook.invalid') + expect(got.noprefix).toBe(true) }) }) diff --git a/test/main.test.ts b/test/main.test.ts index b9508ba0..a3c87d3d 100644 --- a/test/main.test.ts +++ b/test/main.test.ts @@ -44,7 +44,8 @@ describe('getPayload(Inputs)', () => { color: undefined, url: '', username: '', - avatar_url: '' + avatar_url: '', + ack_no_webhook: false } test("default", () => {