Address comments from PR

This commit is contained in:
Andrew Eisenberg 2023-08-29 12:11:32 -07:00
parent d721f69753
commit 09940b4bb9
5 changed files with 30 additions and 23 deletions

24
lib/actions-util.js generated
View file

@ -75,7 +75,7 @@ const getCommitOid = async function (checkoutPath, ref = "HEAD") {
// the merge commit, which must mean that git is available.
// Even if this does go wrong, it's not a huge problem for the alerts to
// reported on the merge commit.
let output = "";
let stderr = "";
try {
let commitOid = "";
await new toolrunner.ToolRunner(await safeWhich.safeWhich("git"), ["rev-parse", ref], {
@ -85,7 +85,7 @@ const getCommitOid = async function (checkoutPath, ref = "HEAD") {
commitOid += data.toString();
},
stderr: (data) => {
output += data.toString();
stderr += data.toString();
},
},
cwd: checkoutPath,
@ -93,11 +93,13 @@ const getCommitOid = async function (checkoutPath, ref = "HEAD") {
return commitOid.trim();
}
catch (e) {
if (output.includes("not a git repository")) {
core.info("Could not determine current commit SHA using git. Continuing with data from user input or environment. The checkout path provided to the action does not appear to be a git repository.");
if (stderr.includes("not a git repository")) {
core.info("Could not determine current commit SHA using git. Continuing with data from user input or environment. " +
"The checkout path provided to the action does not appear to be a git repository.");
}
else {
core.info(`Could not determine current commit SHA using git. Continuing with data from user input or environment. Failed to call git to determine merge base. Continuing with data from environment: ${output}`);
core.info(`Could not determine current commit SHA using git. Continuing with data from user input or environment. ` +
`Failed to call git to determine merge base. Continuing with data from environment: ${stderr}`);
}
return (0, exports.getOptionalInput)("sha") || (0, util_1.getRequiredEnvParam)("GITHUB_SHA");
}
@ -113,7 +115,7 @@ const determineMergeBaseCommitOid = async function (checkoutPathOverride) {
}
const mergeSha = (0, util_1.getRequiredEnvParam)("GITHUB_SHA");
const checkoutPath = checkoutPathOverride ?? (0, exports.getOptionalInput)("checkout_path");
let output = "";
let stderr = "";
try {
let commitOid = "";
let baseOid = "";
@ -135,7 +137,7 @@ const determineMergeBaseCommitOid = async function (checkoutPathOverride) {
}
},
stderr: (data) => {
output += data.toString();
stderr += data.toString();
},
},
cwd: checkoutPath,
@ -149,11 +151,13 @@ const determineMergeBaseCommitOid = async function (checkoutPathOverride) {
return undefined;
}
catch (e) {
if (output.includes("not a git repository")) {
core.info("The checkout path provided to the action does not appear to be a git repository. Continuing with data from environment.");
if (stderr.includes("not a git repository")) {
core.info("The checkout path provided to the action does not appear to be a git repository. " +
"Will calculate the merge base on the server.");
}
else {
core.info(`Failed to call git to determine merge base. Continuing with data from environment: ${output}`);
core.info(`Failed to call git to determine merge base. Will calculate the merge base on ` +
`the server. Reason: ${stderr}`);
}
return undefined;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -2,7 +2,6 @@ import * as fs from "fs";
import * as path from "path";
import * as core from "@actions/core";
import * as toolRunner from "@actions/exec/lib/toolrunner";
import test from "ava";
import * as sinon from "sinon";

View file

@ -63,7 +63,7 @@ export const getCommitOid = async function (
// the merge commit, which must mean that git is available.
// Even if this does go wrong, it's not a huge problem for the alerts to
// reported on the merge commit.
let output = "";
let stderr = "";
try {
let commitOid = "";
await new toolrunner.ToolRunner(
@ -76,7 +76,7 @@ export const getCommitOid = async function (
commitOid += data.toString();
},
stderr: (data) => {
output += data.toString();
stderr += data.toString();
},
},
cwd: checkoutPath,
@ -84,13 +84,15 @@ export const getCommitOid = async function (
).exec();
return commitOid.trim();
} catch (e) {
if (output.includes("not a git repository")) {
if (stderr.includes("not a git repository")) {
core.info(
"Could not determine current commit SHA using git. Continuing with data from user input or environment. The checkout path provided to the action does not appear to be a git repository.",
"Could not determine current commit SHA using git. Continuing with data from user input or environment. " +
"The checkout path provided to the action does not appear to be a git repository.",
);
} else {
core.info(
`Could not determine current commit SHA using git. Continuing with data from user input or environment. Failed to call git to determine merge base. Continuing with data from environment: ${output}`,
`Could not determine current commit SHA using git. Continuing with data from user input or environment. ` +
`Failed to call git to determine merge base. Continuing with data from environment: ${stderr}`,
);
}
@ -112,7 +114,7 @@ export const determineMergeBaseCommitOid = async function (
const mergeSha = getRequiredEnvParam("GITHUB_SHA");
const checkoutPath =
checkoutPathOverride ?? getOptionalInput("checkout_path");
let output = "";
let stderr = "";
try {
let commitOid = "";
@ -137,7 +139,7 @@ export const determineMergeBaseCommitOid = async function (
}
},
stderr: (data) => {
output += data.toString();
stderr += data.toString();
},
},
cwd: checkoutPath,
@ -154,13 +156,15 @@ export const determineMergeBaseCommitOid = async function (
}
return undefined;
} catch (e) {
if (output.includes("not a git repository")) {
if (stderr.includes("not a git repository")) {
core.info(
"The checkout path provided to the action does not appear to be a git repository. Continuing with data from environment.",
"The checkout path provided to the action does not appear to be a git repository. " +
"Will calculate the merge base on the server.",
);
} else {
core.info(
`Failed to call git to determine merge base. Continuing with data from environment: ${output}`,
`Failed to call git to determine merge base. Will calculate the merge base on ` +
`the server. Reason: ${stderr}`,
);
}
return undefined;