From ead4a0a409b2ab7d55d11e32c889758253549149 Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Tue, 12 Nov 2019 14:40:32 -0500 Subject: [PATCH] PR Feedback --- __tests__/restore.test.ts | 7 ++++++- src/restore.ts | 4 ++-- src/utils/actionUtils.ts | 6 +++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index b4dab7e..2de4aa3 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -33,6 +33,11 @@ beforeAll(() => { return actualUtils.isValidEvent(); }); + jest.spyOn(actionUtils, "getSupportedEvents", ).mockImplementation(() => { + const actualUtils = jest.requireActual("../src/utils/actionUtils"); + return actualUtils.getSupportedEvents(); + }); + jest.spyOn(io, "which").mockImplementation(tool => { return Promise.resolve(tool); }); @@ -53,7 +58,7 @@ test("restore with invalid event", async () => { process.env[Events.Key] = invalidEvent; await run(); expect(failedMock).toHaveBeenCalledWith( - `Event Validation Error: The event type ${invalidEvent} is not supported. Only \`push\` and \`pull_request\` events are supported at this time.` + `Event Validation Error: The event type ${invalidEvent} is not supported. Only push, pull_request events are supported at this time.` ); }); diff --git a/src/restore.ts b/src/restore.ts index 977376e..fe6c6f4 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -5,7 +5,7 @@ import * as io from "@actions/io"; import * as path from "path"; import * as cacheHttpClient from "./cacheHttpClient"; -import { Inputs, State } from "./constants"; +import { Events, Inputs, State } from "./constants"; import * as utils from "./utils/actionUtils"; async function run() { @@ -13,7 +13,7 @@ async function run() { // Validate inputs, this can cause task failure if (!utils.isValidEvent()) { core.setFailed( - `Event Validation Error: The event type ${process.env["GITHUB_EVENT_NAME"]} is not supported. Only \`push\` and \`pull_request\` events are supported at this time.` + `Event Validation Error: The event type ${process.env[Events.Key]} is not supported. Only ${utils.getSupportedEvents().join(", ")} events are supported at this time.` ); } diff --git a/src/utils/actionUtils.ts b/src/utils/actionUtils.ts index 31fcdc9..aeaeda9 100644 --- a/src/utils/actionUtils.ts +++ b/src/utils/actionUtils.ts @@ -90,5 +90,9 @@ export function resolvePath(filePath: string): string { // See GitHub Context https://help.github.com/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context export function isValidEvent(): boolean { const githubEvent = process.env[Events.Key] || ""; - return githubEvent === Events.Push || githubEvent === Events.PullRequest; + return getSupportedEvents().includes(githubEvent); +} + +export function getSupportedEvents(): string[] { + return [Events.Push, Events.PullRequest]; }