
Git Commit Writer — Draft conventional commits
Reads your staged git changes and writes a Conventional Commit message: type, scope, imperative subject, a file-by-file body, and a BREAKING CHANGE footer when a public function or option was removed. Warns when one commit mixes unrelated folders, and lints any message as a commit-msg hook. Deterministic; changes nothing unless you ask.
#エンジニアリング
評価
さらに評価が必要です
販売数
0
利用方法
ダウンロード
The problem
Commit messages are written last, when you are tired of the change. The result is update stuff, fix, or a header that says feat for a bug fix. Nobody can scan the history, and tools that read Conventional Commits (changelog generators, release bots) cannot use it. On a team that stages into one working tree, a second problem hides inside the first: files from someone else's task slip into your commit and nothing says so.
How it works
- Reads the staged diff with
git diff --cached(or a diff you pass in with--diff-file). - Parses every file: status (added, deleted, renamed, modified), lines added and removed, and which function each changed line sits in.
- Decides the type from what changed:
- only tests, docs, CI files, build files or config changed:
test,docs,ci,build,chore - a new file or a new function appears:
feat - added lines mention a fix, bug, crash or typo:
fix - added lines mention caching or speed:
perf - only comments were added:
docs; only whitespace moved:style - existing code changed inside a function:
refactor; values changed outside any function:chore
- only tests, docs, CI files, build files or config changed:
- Decides the scope from the folder every file shares (
src/,lib/andapp/are skipped), or from the file name when one root file changed. - Writes the subject from what it found:
add slugify in words,remove legacy_trim and --verbose,rename a.py to b.py. The header is cut at a word boundary to fit--max-subject(default 72). - Detects breaking changes: a public function that disappeared (a name that is gone from the diff, not merely moved), a removed
add_argument("--flag"), or a changed file containingBREAKING CHANGE:. It adds!to the header and one footer line per reason. - Checks the staging: three or more top-level folders, more than 30 files, three or more kinds of change (source, build, config) mixed together, or files outside the
--onlypatterns you expect.
The result is deterministic: the same diff always gives the same message.
Usage
# print a message for what is staged right now
python3 scripts/commit_writer.py
# read a diff file (or - for stdin) instead of git
python3 scripts/commit_writer.py --diff-file changes.patch
# commit with the generated message
python3 scripts/commit_writer.py --commit
# lint a message, or a message file (this is what the hook runs)
python3 scripts/commit_writer.py --lint "feat(api): add retry"
python3 scripts/commit_writer.py --lint-file .git/COMMIT_EDITMSG
# install a commit-msg hook that rejects bad messages
python3 scripts/commit_writer.py --install-hook
| option | meaning |
|---|---|
--repo PATH |
the git repository (default: current folder) |
--diff-file PATH |
read a unified diff from a file, or - for stdin |
--type T |
force the type (feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert) |
--scope S |
force the scope |
--ref ID |
add a Refs: ID footer, such as an issue number |
--suffix ID |
append (ID) to the header, such as a task id |
--breaking |
mark the commit as breaking even if nothing was detected |
--only PATTERN |
expected path pattern (repeat it); other staged files raise a warning |
--max-subject N |
header length limit (default 72) |
--json |
print the full analysis: type, scope, reason, files, breaking reasons, warnings |
Limits (read these)
- The type is a heuristic, not a judgment.
fixis chosen when the added lines mention a fix, bug or crash; a bug fix with no such word is reported asrefactororchore. Thereasonfield in--jsonsays why a type was chosen. Pass--typewhen you know better. - It names what changed, not why. The subject is built from file and function names. Edit it, or add a body that explains the reason.
- Breaking detection reads names, not behaviour. A removed public function or option is found; a changed return value is not. Functions starting with
_are treated as private. - Function names come from
def,function,func,fn,classandexportlines. Other languages still work for files, scope and type, with fewer symbols in the subject. - It never touches your repository unless you pass
--commitor--install-hook, makes no network calls, and sends nothing anywhere.


