mirror of
https://github.com/github/codeql-action.git
synced 2026-04-27 01:08:46 +00:00
Address code review feedback
- Add test for Windows-style git version format - Add comment clarifying regex extracts major.minor.patch - Replace dynamic import with static import for semver Co-authored-by: henrymercer <14129055+henrymercer@users.noreply.github.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import * as path from "path";
|
||||
import * as github from "@actions/github";
|
||||
import test, { ExecutionContext } from "ava";
|
||||
import * as yaml from "js-yaml";
|
||||
import * as semver from "semver";
|
||||
import * as sinon from "sinon";
|
||||
|
||||
import * as actionsUtil from "./actions-util";
|
||||
@@ -1065,7 +1066,6 @@ const getOverlayDatabaseModeMacro = test.macro({
|
||||
sinon
|
||||
.stub(gitUtils, "gitVersionAtLeast")
|
||||
.callsFake(async (requiredVersion: string) => {
|
||||
const semver = await import("semver");
|
||||
return semver.gte(setup.gitVersion!, requiredVersion);
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -424,6 +424,20 @@ test("getGitVersion returns undefined for invalid git output", async (t) => {
|
||||
}
|
||||
});
|
||||
|
||||
test("getGitVersion handles Windows-style git output", async (t) => {
|
||||
const runGitCommandStub = sinon
|
||||
.stub(gitUtils as any, "runGitCommand")
|
||||
.resolves("git version 2.40.0.windows.1\n");
|
||||
|
||||
try {
|
||||
const version = await gitUtils.getGitVersion();
|
||||
// Should extract just the major.minor.patch portion
|
||||
t.is(version, "2.40.0");
|
||||
} finally {
|
||||
runGitCommandStub.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test("getGitVersion returns undefined when git command fails", async (t) => {
|
||||
const runGitCommandStub = sinon
|
||||
.stub(gitUtils as any, "runGitCommand")
|
||||
|
||||
+2
-1
@@ -30,7 +30,8 @@ export async function getGitVersion(): Promise<string | undefined> {
|
||||
["--version"],
|
||||
"Failed to get git version.",
|
||||
);
|
||||
// Expected output format: "git version 2.40.0"
|
||||
// Git version output can vary: "git version 2.40.0" or "git version 2.40.0.windows.1"
|
||||
// We capture just the major.minor.patch portion to ensure semver compatibility.
|
||||
const match = stdout.match(/git version (\d+\.\d+\.\d+)/);
|
||||
if (match?.[1]) {
|
||||
return match[1];
|
||||
|
||||
Reference in New Issue
Block a user