CLI-248 git hooks#160
CLI-248 git hooks#160kirill-knize-sonarsource wants to merge 1 commit intotask/kk/CLI-244-245-callback-infrastructurefrom
Conversation
SummaryWhat changed: Refactored git hook logic from shell scripts to TypeScript callback handlers. Previously, Why: Maintains feature parity while improving maintainability, testability, and consistency with the callback infrastructure pattern established in CLI-244-245. The implementation is now easier to evolve and test compared to embedded shell scripts. What's new:
What reviewers should knowStart here:
Key implementation details:
For reviewers:
|
e5bc9f8 to
6f2f053
Compare
d2c374f to
6752b74
Compare
6f2f053 to
aa6bc64
Compare
6752b74 to
e69525f
Compare
e69525f to
45c3f51
Compare
45c3f51 to
d4de5d8
Compare
80c4a76 to
4853f25
Compare
d4de5d8 to
6123a4b
Compare
e2211ff to
581f8af
Compare
dc076f4 to
f266954
Compare
581f8af to
00bea22
Compare
| try { | ||
| const exitCode = await scanFiles(binaryPath, stagedFiles, auth); | ||
| if (exitCode === EXIT_CODE_SECRETS_FOUND) { | ||
| throw new CommandFailedError('Secrets detected in staged files'); | ||
| } | ||
| } catch (err) { | ||
| if (err instanceof CommandFailedError) throw err; | ||
| logger.debug(`git pre-commit secrets scan failed: ${(err as Error).message}`); | ||
| throw new CommandFailedError('Secrets scan failed'); | ||
| } |
There was a problem hiding this comment.
Logic duplication: This try-catch block — scanFiles → check EXIT_CODE_SECRETS_FOUND → re-throw as CommandFailedError, with a catch that re-throws CommandFailedError and wraps everything else — is duplicated verbatim in git-pre-push.ts lines 52–61. The only differences are the error message strings ('staged files' vs 'pushed commits') and the debug log prefix.
If the exit-code check or error-wrapping logic ever needs to change (e.g. new exit codes, changed error format, added telemetry), both files must be updated in sync.
Extract a shared helper into secrets-scan.ts (or a new run-secrets.ts), e.g.:
export async function runSecretsOrFail(
binaryPath: string,
files: string[],
auth: ResolvedAuth,
context: string,
): Promise<void> {
try {
const exitCode = await scanFiles(binaryPath, files, auth);
if (exitCode === EXIT_CODE_SECRETS_FOUND) {
throw new CommandFailedError(`Secrets detected in ${context}`);
}
} catch (err) {
if (err instanceof CommandFailedError) throw err;
logger.debug(`${context} secrets scan failed: ${(err as Error).message}`);
throw new CommandFailedError('Secrets scan failed');
}
}Then call await runSecretsOrFail(binaryPath, stagedFiles, auth, 'staged files') and await runSecretsOrFail(binaryPath, files, auth, 'pushed commits') respectively.
- Mark as noise
39242f7 to
4ef81c1
Compare
c4b4665 to
e44c9d3
Compare
e44c9d3 to
d117a3a
Compare
4ef81c1 to
fb38f6a
Compare
f4cbc21 to
468e45c
Compare
41ad13e to
3a9bf2e
Compare
9191141 to
129cc50
Compare
a7e0a09 to
384bf12
Compare
384bf12 to
658ffd5
Compare
658ffd5 to
0da8b82
Compare
0da8b82 to
b72e120
Compare
|
There was a problem hiding this comment.
LGTM! ✅
The logic duplication flagged in the prior review round — the try/catch block that wraps runSecretsBinary, checks EXIT_CODE_SECRETS_FOUND, and re-throws as CommandFailedError — remains identical in both git-pre-commit.ts (lines 48–58) and git-pre-push.ts (lines 52–62). That issue is still open.



No description provided.