Skip to content

chore: normalize commit messages via conventional-commits hook#14

Merged
tannn merged 3 commits intomainfrom
commit-normalize
Mar 3, 2026
Merged

chore: normalize commit messages via conventional-commits hook#14
tannn merged 3 commits intomainfrom
commit-normalize

Conversation

@tannn
Copy link
Owner

@tannn tannn commented Mar 2, 2026

Summary

  • Adds git-hooks/commit-msg — a shell hook that validates commit messages against the Conventional Commits specification
  • Adds scripts/setup-hooks.sh — an idempotent installer that symlinks git-hooks/* into .git/hooks/ with correct permissions
  • Updates README.md with a Development Setup section documenting the commit convention and setup command

What the hook validates

  1. Subject line matches <type>(<scope>): <description> (types: feat|fix|docs|chore|refactor|test|style|perf|ci)
  2. Description starts with a lowercase letter
  3. Subject line ≤ 72 characters
  4. If a body is present, a blank line separates it from the subject

Test plan

  • bash scripts/setup-hooks.sh runs cleanly and reports hook installed
  • Valid message (feat(ui): add dark mode toggle) exits 0
  • Invalid message (Feat: Add dark mode) exits 1 with clear error output
  • git log --oneline main...commit-normalize shows exactly one commit (no unrelated commits)

🤖 Generated with Claude Code


Automated by nightshift

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6d4782a6fa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

COMMIT_MSG=$(head -1 "$COMMIT_MSG_FILE")

TYPES="feat|fix|docs|chore|refactor|test|style|perf|ci"
PATTERN="^(${TYPES})(\([a-z0-9]([a-z0-9-]*[a-z0-9])?\))?!?: [a-z].{1,}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject commit subjects ending with a period

The hook documents a "no trailing period" rule, but the subject regex ^[...]: [a-z].{1,} still accepts messages like fix: add parser. because it never excludes a final .. That means commits the README and error text say should fail are currently allowed, so the new validation is weaker than advertised.

Useful? React with 👍 / 👎.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot fix this


REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
HOOKS_SOURCE="$REPO_ROOT/git-hooks"
HOOKS_DEST="$REPO_ROOT/.git/hooks"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve hook destination from Git config

The installer hardcodes .git/hooks as the destination, but Git uses core.hooksPath when it is configured (often globally). In that setup this script prints "Installed" even though Git will ignore those symlinks, so commit-message enforcement silently does not run for affected developers. Use Git’s resolved hooks path instead of assuming .git/hooks.

Useful? React with 👍 / 👎.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot fix this

Copy link
Contributor

Copilot AI commented Mar 3, 2026

@tannn I've opened a new pull request, #15, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Mar 3, 2026

@tannn I've opened a new pull request, #16, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits March 2, 2026 23:45
* Initial plan

* fix: reject commit subjects ending with a trailing period

Co-authored-by: tannn <831788+tannn@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tannn <831788+tannn@users.noreply.github.com>
* Initial plan

* fix: resolve hook destination from git config core.hooksPath

Co-authored-by: tannn <831788+tannn@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tannn <831788+tannn@users.noreply.github.com>
@tannn tannn merged commit 8638b86 into main Mar 3, 2026
6 checks passed
@tannn tannn deleted the commit-normalize branch March 3, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants