Skip to content

Commit 73335fc

Browse files
committed
fix(hooks): restore Linear issue reference blocking in commit-msg.mts
The bash-to-TypeScript migration of commit-msg dropped the Linear issue reference blocking. Add scanLinearReferences() to _helpers.mts (matching the original team-key regex and linear.app URL check) and invoke it from commit-msg.mts to block commits containing internal tracker references.
1 parent f5e6d06 commit 73335fc

2 files changed

Lines changed: 59 additions & 3 deletions

File tree

.git-hooks/_helpers.mts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,41 @@ export const scanLoggerLeaks = (text: string): LineHit[] => {
382382
return hits
383383
}
384384

385+
// ── Linear issue reference scanner ──────────────────────────────────
386+
//
387+
// Linear tracking lives in Linear; keep commit history tool-agnostic.
388+
// Team keys enumerated from the Socket workspace. PATCH listed before
389+
// PAT so the engine matches the longer prefix first.
390+
391+
const LINEAR_TEAM_KEYS =
392+
'ASK|AUTO|BOT|CE|CORE|DAT|DES|DEV|ENG|INFRA|LAB|MAR|MET|OPS|PAR|PATCH|PAT|PLAT|REA|SALES|SBOM|SEC|SMO|SUP|TES|TI|WEB'
393+
394+
const LINEAR_ISSUE_RE = new RegExp(
395+
`(?:^|[^A-Za-z0-9_])((?:${LINEAR_TEAM_KEYS})-[0-9]+)(?:$|[^A-Za-z0-9_])`,
396+
)
397+
const LINEAR_URL_RE = /linear\.app\/[A-Za-z0-9/_-]+/
398+
399+
// Scans commit-message text for Linear issue references (team-key
400+
// patterns like SMO-590 and linear.app URLs). Ignores git comment
401+
// lines (lines starting with `#`).
402+
export const scanLinearReferences = (text: string): string[] => {
403+
const hits: string[] = []
404+
for (const line of text.split('\n')) {
405+
if (line.startsWith('#')) {
406+
continue
407+
}
408+
const issueMatch = line.match(LINEAR_ISSUE_RE)
409+
if (issueMatch) {
410+
hits.push(issueMatch[1]!)
411+
}
412+
const urlMatch = line.match(LINEAR_URL_RE)
413+
if (urlMatch) {
414+
hits.push(urlMatch[0])
415+
}
416+
}
417+
return hits.slice(0, 5)
418+
}
419+
385420
// ── AI attribution scanner ─────────────────────────────────────────
386421

387422
const AI_ATTRIBUTION_RE =

.git-hooks/commit-msg.mts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/usr/bin/env node
22
// Socket Security Commit-msg Hook
33
//
4-
// Two responsibilities:
4+
// Three responsibilities:
55
// 1. Block commits that introduce API keys / .env files (security
66
// layer that runs even when pre-commit is bypassed via
77
// `--no-verify`).
8-
// 2. Auto-strip AI attribution lines from the commit message before
8+
// 2. Block commits whose message references Linear issues (keep
9+
// commit history tool-agnostic).
10+
// 3. Auto-strip AI attribution lines from the commit message before
911
// git records the commit.
1012
//
1113
// Wired via .husky/commit-msg, which invokes this with the path to the
@@ -23,6 +25,7 @@ import {
2325
out,
2426
red,
2527
readFileForScan,
28+
scanLinearReferences,
2629
scanSocketApiKeys,
2730
shouldSkipFile,
2831
stripAiAttribution,
@@ -67,8 +70,26 @@ const main = (): number => {
6770
}
6871
}
6972

70-
// Auto-strip AI attribution lines from the commit message.
73+
// Block Linear issue references in the commit message.
7174
const commitMsgFile = process.argv[2]
75+
if (commitMsgFile && existsSync(commitMsgFile)) {
76+
const msgText = readFileSync(commitMsgFile, 'utf8')
77+
const linearHits = scanLinearReferences(msgText)
78+
if (linearHits.length > 0) {
79+
out(red('✗ Commit message references Linear issue(s):'))
80+
for (const hit of linearHits) {
81+
out(` ${hit}`)
82+
}
83+
out(
84+
red(
85+
'Linear tracking lives in Linear. Remove the reference from the commit message.',
86+
),
87+
)
88+
errors++
89+
}
90+
}
91+
92+
// Auto-strip AI attribution lines from the commit message.
7293
if (commitMsgFile && existsSync(commitMsgFile)) {
7394
const original = readFileSync(commitMsgFile, 'utf8')
7495
const { cleaned, removed } = stripAiAttribution(original)

0 commit comments

Comments
 (0)