Skip to content

Commit f68f8d1

Browse files
committed
fix: reduce redundant git-call-failed log messages in upload-sarif
Change the log level of the "git call failed." message in `runGitCommand` from `core.info` to `core.debug` so repeated identical failures in non-git working directories no longer flood the normal output. Add a single `core.info` fallback notice in `getCommitOid` so callers still see one actionable message when git is unavailable. Update tests to assert the new debug-level logging. Fixes #3383
1 parent f3f1edb commit f68f8d1

3 files changed

Lines changed: 19 additions & 10 deletions

File tree

lib/entry-points.js

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/git-utils.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ test.serial(
252252
"determineBaseBranchHeadCommitOid not git repository",
253253
async (t) => {
254254
const infoStub = sinon.stub(core, "info");
255+
const debugStub = sinon.stub(core, "debug");
255256

256257
process.env["GITHUB_EVENT_NAME"] = "pull_request";
257258
process.env["GITHUB_SHA"] = "100912429fab4cb230e66ffb11e738ac5194e73a";
@@ -260,32 +261,34 @@ test.serial(
260261
await gitUtils.determineBaseBranchHeadCommitOid(tmpDir);
261262
});
262263

263-
t.deepEqual(1, infoStub.callCount);
264-
t.deepEqual(
265-
infoStub.firstCall.args[0],
266-
"git call failed. Will calculate the base branch SHA on the server. Error: " +
267-
"The checkout path provided to the action does not appear to be a git repository.",
264+
t.deepEqual(0, infoStub.callCount);
265+
t.assert(
266+
debugStub.calledWithMatch(
267+
"git call failed. Will calculate the base branch SHA on the server. Error: " +
268+
"The checkout path provided to the action does not appear to be a git repository.",
269+
),
268270
);
269271
},
270272
);
271273

272274
test.serial("determineBaseBranchHeadCommitOid other error", async (t) => {
273275
const infoStub = sinon.stub(core, "info");
276+
const debugStub = sinon.stub(core, "debug");
274277

275278
process.env["GITHUB_EVENT_NAME"] = "pull_request";
276279
process.env["GITHUB_SHA"] = "100912429fab4cb230e66ffb11e738ac5194e73a";
277280
const result = await gitUtils.determineBaseBranchHeadCommitOid(
278281
path.join(__dirname, "../../i-dont-exist"),
279282
);
280283
t.deepEqual(result, undefined);
281-
t.deepEqual(1, infoStub.callCount);
284+
t.deepEqual(0, infoStub.callCount);
282285
t.assert(
283-
infoStub.firstCall.args[0].startsWith(
286+
debugStub.calledWithMatch(
284287
"git call failed. Will calculate the base branch SHA on the server. Error: ",
285288
),
286289
);
287290
t.assert(
288-
!infoStub.firstCall.args[0].endsWith(
291+
!debugStub.firstCall.args[0].endsWith(
289292
"The checkout path provided to the action does not appear to be a git repository.",
290293
),
291294
);

src/git-utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const runGitCommand = async function (
9292
reason =
9393
"The checkout path provided to the action does not appear to be a git repository.";
9494
}
95-
core.info(`git call failed. ${customErrorMessage} Error: ${reason}`);
95+
core.debug(`git call failed. ${customErrorMessage} Error: ${reason}`);
9696
throw error;
9797
}
9898
};
@@ -119,6 +119,9 @@ export const getCommitOid = async function (
119119
);
120120
return stdout.trim();
121121
} catch {
122+
core.info(
123+
"Could not retrieve commit SHA from git; falling back to environment.",
124+
);
122125
return getOptionalInput("sha") || getRequiredEnvParam("GITHUB_SHA");
123126
}
124127
};

0 commit comments

Comments
 (0)