git-blame-blame
v0.3.0
Published
Find who approved the PR that introduced a bug
Downloads
610
Readme
git-blame-blame
Find who approved the PR that introduced a buggy line of code.
Description
git-blame-blame goes one step further than git blame. It not only identifies the commit that introduced a line of code, but also finds the pull request associated with that commit and lists everyone who approved it.
Install
npm install -g git-blame-blameRequirements
- A GitHub personal access token with
reposcope - Set the
GITHUB_TOKENenvironment variable (or use the--tokenflag)
export GITHUB_TOKEN=ghp_your_token_hereUsage
git-blame-blame <file:line> [options]
git-blame-blame <tracked-path> --bus-factor
git-blame-blame <tracked-path> --export csvExamples
$ git-blame-blame src/auth.js:42
src/auth.js:42
Line: "return token === undefined ? guest : user"
Commit: abc1234 by alice <[email protected]> (2024-03-15)
Subject: fix: handle unauthenticated users
PR #234: "fix: handle unauthenticated users"
URL: https://github.com/org/repo/pull/234
Approved: bob, carol$ git-blame-blame src/auth.js:42 --json
{
"file": "src/auth.js",
"line": 42,
"lineContent": "return token === undefined ? guest : user",
"commit": {
"sha": "abc1234...",
"shortSha": "abc1234",
"authorName": "alice",
"authorEmail": "[email protected]",
"date": "2024-03-15",
"subject": "fix: handle unauthenticated users"
},
"pr": {
"number": 234,
"title": "fix: handle unauthenticated users",
"url": "https://github.com/org/repo/pull/234"
},
"approvals": [
{ "login": "bob", "email": null },
{ "login": "carol", "email": null }
]
}$ git-blame-blame src/ --bus-factor
Bus Factor Analysis:
Critical (bus factor = 1):
src/core/engine.ts only alice maintains this (847 lines)
At Risk (bus factor = 2):
src/api/routes.ts carol 60% + alice 40%
Healthy (bus factor >= 3):
src/utils/helpers.ts alice 40%, bob 35%, carol 25%
Overall repo bus factor: 1
Recommendation: alice is the single point of failure for 1 file$ git-blame-blame src/ --export csv > blame-report.csv
$ git-blame-blame src/ --export json > blame-report.jsonOptions
| Flag | Description |
|------|-------------|
| -t, --token <token> | GitHub personal access token (overrides GITHUB_TOKEN) |
| -r, --repo <owner/repo> | GitHub repository (auto-detected from git remote if omitted) |
| --json | Output results as JSON |
| --since <date> | Limit tracked-path analysis to code added or modified since this date |
| --team <file> | Show tracked-path contributions grouped by a team roster |
| --bus-factor | Show per-file bus factor using contributors with more than 20% of blamed lines |
| --export <csv|json> | Export tracked-path blame analysis as structured data |
| -V, --version | Show version number |
| -h, --help | Show help |
How it works
git-blame-blame runs a 4-step pipeline:
- git blame — Runs
git log -Lon the specified file and line to identify the commit that introduced that line of code. - Find commit — Looks up the commit SHA in your repository to get author info, date, and commit message.
- Find PR — Queries the GitHub API to find which pull request contains that commit.
- Get approvals — Fetches all reviews for that PR and returns the list of approvers.
Development
# Clone and install
git clone https://github.com/yourusername/git-blame-blame
cd git-blame-blame
pnpm install
# Run in dev mode
pnpm dev src/auth.js:42
# Build
pnpm buildVS Code Extension
A minimal VS Code extension scaffold lives in vscode/.
See vscode/README.md for setup and usage instructions.
License
MIT
