Skip to content

Commit 95b8083

Browse files
committed
Improve commit SHA retrieval by prioritizing user input when provided
1. Checks for sha input first, If the user explicitly sets sha in the analyze or upload-sarif action, that value is used immediately 2. Falls back to git - If no sha input, runs git rev-parse as before 3. Final fallback to GITHUB_SHA - If git fails, uses the environment variable
1 parent 66bcc86 commit 95b8083

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/git-utils.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ export const getCommitOid = async function (
9696
checkoutPath: string,
9797
ref = "HEAD",
9898
): Promise<string> {
99+
// If the user explicitly provides a SHA via the action input, use that.
100+
// This is important when the checkout path contains a different repository
101+
// than the one where results should be uploaded (e.g., when cloning another
102+
// repo for analysis).
103+
const shaInput = getOptionalInput("sha");
104+
if (shaInput) {
105+
return shaInput;
106+
}
107+
99108
// Try to use git to get the current commit SHA. If that fails then
100109
// log but otherwise silently fall back to using the SHA from the environment.
101110
// The only time these two values will differ is during analysis of a PR when
@@ -107,11 +116,11 @@ export const getCommitOid = async function (
107116
const stdout = await runGitCommand(
108117
checkoutPath,
109118
["rev-parse", ref],
110-
"Continuing with commit SHA from user input or environment.",
119+
"Continuing with commit SHA from environment.",
111120
);
112121
return stdout.trim();
113122
} catch {
114-
return getOptionalInput("sha") || getRequiredEnvParam("GITHUB_SHA");
123+
return getRequiredEnvParam("GITHUB_SHA");
115124
}
116125
};
117126

0 commit comments

Comments
 (0)