Remove unused CODESCANNING_EVENT_NAME environment variable

This commit is contained in:
Henry Mercer
2023-05-31 15:37:11 +01:00
parent 9d2dd7cfea
commit bf419682de
12 changed files with 32 additions and 55 deletions

View File

@@ -214,6 +214,7 @@ test("initializeEnvironment", (t) => {
});
test("isAnalyzingDefaultBranch()", async (t) => {
process.env["GITHUB_EVENT_NAME"] = "push";
process.env["CODE_SCANNING_IS_ANALYZING_DEFAULT_BRANCH"] = "true";
t.deepEqual(await actionsutil.isAnalyzingDefaultBranch(), true);
process.env["CODE_SCANNING_IS_ANALYZING_DEFAULT_BRANCH"] = "false";
@@ -264,14 +265,3 @@ test("isAnalyzingDefaultBranch()", async (t) => {
getAdditionalInputStub.restore();
});
});
test("workflowEventName()", async (t) => {
process.env["GITHUB_EVENT_NAME"] = "push";
t.deepEqual(actionsutil.workflowEventName(), "push");
process.env["GITHUB_EVENT_NAME"] = "dynamic";
t.deepEqual(actionsutil.workflowEventName(), "dynamic");
process.env["CODESCANNING_EVENT_NAME"] = "push";
t.deepEqual(actionsutil.workflowEventName(), "push");
});

View File

@@ -108,7 +108,7 @@ export const getCommitOid = async function (
export const determineMergeBaseCommitOid = async function (): Promise<
string | undefined
> {
if (workflowEventName() !== "pull_request") {
if (getWorkflowEventName() !== "pull_request") {
return undefined;
}
@@ -576,21 +576,18 @@ export async function sendStatusReport<S extends StatusReportBase>(
}
}
export function workflowEventName() {
// If the original event is dynamic CODESCANNING_EVENT_NAME will contain the right info (push/pull_request)
if (process.env["GITHUB_EVENT_NAME"] === "dynamic") {
const value = process.env["CODESCANNING_EVENT_NAME"];
if (value === undefined || value.length === 0) {
return process.env["GITHUB_EVENT_NAME"];
}
return value;
}
return process.env["GITHUB_EVENT_NAME"];
/**
* Returns the name of the event that triggered this workflow.
*
* This will be "dynamic" for default setup workflow runs.
*/
export function getWorkflowEventName() {
return getRequiredEnvParam("GITHUB_EVENT_NAME");
}
// Was the workflow run triggered by a `push` event, for example as opposed to a `pull_request` event.
function workflowIsTriggeredByPushEvent() {
return workflowEventName() === "push";
return getWorkflowEventName() === "push";
}
// Is dependabot the actor that triggered the current workflow run.
@@ -647,7 +644,7 @@ export async function isAnalyzingDefaultBranch(): Promise<boolean> {
const event = getWorkflowEvent();
let defaultBranch = event?.repository?.default_branch;
if (process.env.GITHUB_EVENT_NAME === "schedule") {
if (getWorkflowEventName() === "schedule") {
defaultBranch = removeRefsHeadsPrefix(getRequiredEnvParam("GITHUB_REF"));
}

View File

@@ -99,7 +99,7 @@ export async function downloadTrapCaches(
let baseSha = "unknown";
const eventPath = process.env.GITHUB_EVENT_PATH;
if (
actionsUtil.workflowEventName() === "pull_request" &&
actionsUtil.getWorkflowEventName() === "pull_request" &&
eventPath !== undefined
) {
const event = JSON.parse(fs.readFileSync(path.resolve(eventPath), "utf-8"));

View File

@@ -293,7 +293,7 @@ export function buildPayload(
base_sha: undefined as undefined | string,
};
if (actionsUtil.workflowEventName() === "pull_request") {
if (actionsUtil.getWorkflowEventName() === "pull_request") {
if (
commitOid === util.getRequiredEnvParam("GITHUB_SHA") &&
mergeBaseCommitOid