-
Notifications
You must be signed in to change notification settings - Fork 0
add conventional commit validation hooks #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Coverage report for
|
St.❔ |
Category | Percentage | Covered / Total |
|---|---|---|---|
| 🟢 | Statements | 86.58% | 1135/1311 |
| 🟡 | Branches | 70.31% | 450/640 |
| 🟢 | Functions | 86.62% | 123/142 |
| 🟢 | Lines | 87.35% | 1119/1281 |
Test suite run success
276 tests passing in 31 suites.
Report generated by 🧪jest coverage report action from af8dc11
🔒 CodeQL Security Analysis ResultsCodeQL analysis has been completed for this pull request. Language: javascript 📊 View detailed results: Check the Security tab for complete findings. 💡 Next steps:
This comment was generated automatically by CodeQL Analysis |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds conventional commit validation hooks to enforce standardized commit message format across the repository. The hooks validate commit messages locally before they're pushed, while the CI/CD workflow validates them during deployment to ensure consistency with semantic versioning.
Key Changes:
- Added Git hooks (commit-msg) to validate conventional commit format locally
- Updated deployment workflow to enforce conventional commit format in CI/CD
- Added installation scripts for both Unix-like systems and Windows
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| hooks/install-hooks.sh | Installation script for Git hooks on Linux/macOS/Git Bash |
| hooks/install-hooks.bat | Installation script for Git hooks on Windows Command Prompt |
| hooks/commit-msg | Git hook that validates commit messages against conventional commit format |
| hooks/README.md | Documentation for the Git hooks, installation instructions, and commit message format |
| .github/workflows/deploy-to-dev.yaml | Updated deployment workflow to validate conventional commits and fail if commits don't follow the required format |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| commit_msg=$(cat "$commit_msg_file") | ||
|
|
||
| # Conventional commit pattern | ||
| conventional_pattern='^(feat|fix|docs|chore|refactor|test|perf|ci|build|style|revert)(\(.+\))?!?: .{1,}' |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit-msg hook accepts commit types perf, ci, build, and style, but the semantic-release configuration in the workflow (lines 47-53 of deploy-to-dev.yaml) doesn't include these types in its release rules. This means commits with these types will pass the local hook validation but won't trigger a version bump, causing the CI/CD pipeline to fail with the error "Conventional commits found but semantic-release did not generate a version."
Either add these types to the semantic-release configuration or remove them from this pattern.
| MINOR=$((MINOR + 1)) | ||
| PATCH=0 | ||
| # Check if any commit follows conventional commit format | ||
| if echo "$COMMITS_SINCE_TAG" | grep -qE "^(feat|fix|docs|chore|refactor|test|perf|ci|build|style)(\(.+\))?:"; then |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern is missing the revert type that is included in the commit-msg hook (line 11 of hooks/commit-msg) and documentation (line 46 of hooks/README.md). This creates an inconsistency where commits with type revert would pass the local hook validation but fail this check.
Add |revert to the pattern if revert should be supported, or remove it from the hook and documentation if it shouldn't be.
| if echo "$COMMITS_SINCE_TAG" | grep -qE "^(feat|fix|docs|chore|refactor|test|perf|ci|build|style)(\(.+\))?:"; then | |
| if echo "$COMMITS_SINCE_TAG" | grep -qE "^(feat|fix|docs|chore|refactor|test|perf|ci|build|style|revert)(\(.+\))?:"; then |
| echo "Allowed types:" | ||
| echo " feat: A new feature (minor version bump)" | ||
| echo " fix: A bug fix (patch version bump)" | ||
| echo " docs: Documentation only changes (patch version bump)" | ||
| echo " chore: Changes that don't modify src or test files (patch version bump)" | ||
| echo " refactor: A code change that neither fixes a bug nor adds a feature (patch version bump)" | ||
| echo " test: Adding missing tests or correcting existing tests (patch version bump)" | ||
| echo " perf: A code change that improves performance (patch version bump)" | ||
| echo " ci: Changes to CI configuration files and scripts (patch version bump)" | ||
| echo " build: Changes that affect the build system or dependencies (patch version bump)" | ||
| echo " style: Changes that don't affect code meaning (white-space, formatting) (patch version bump)" | ||
| echo " revert: Reverts a previous commit (patch version bump)" |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit-msg hook lists 11 commit types (including revert, perf, ci, build, style) that will pass validation, but the semantic-release configuration in the workflow only supports 6 types. This means commits using the additional types will pass the local hook but fail in CI/CD with the error "Conventional commits found but semantic-release did not generate a version."
Update this help text to only list the commit types that are configured in semantic-release (feat, fix, docs, chore, refactor, test) or add the missing types to the semantic-release configuration.
| commit_msg=$(cat "$commit_msg_file") | ||
|
|
||
| # Conventional commit pattern | ||
| conventional_pattern='^(feat|fix|docs|chore|refactor|test|perf|ci|build|style|revert)(\(.+\))?!?: .{1,}' |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern .{1,} will match any single character (including just whitespace), which allows commits like feat: or fix: x with minimal or no meaningful description. Consider using a more restrictive pattern like .{3,} or [^\s].{2,} to ensure a minimum meaningful description length.
| conventional_pattern='^(feat|fix|docs|chore|refactor|test|perf|ci|build|style|revert)(\(.+\))?!?: .{1,}' | |
| conventional_pattern='^(feat|fix|docs|chore|refactor|test|perf|ci|build|style|revert)(\(.+\))?!?: [^\s].{2,}' |
| echo "Example: 'feat: add new authentication feature'" | ||
| echo "" | ||
| echo "Recent commits:" | ||
| echo "$COMMITS_SINCE_TAG" |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable COMMITS_SINCE_TAG should be quoted when used in the echo on line 98 to preserve newlines and formatting. Change to echo "$COMMITS_SINCE_TAG" to ensure multiline commit messages are displayed correctly.
|
|
||
| # Optional: Check minimum description length | ||
| description=$(echo "$commit_msg" | head -n 1 | sed -E 's/^[^:]+: //') | ||
| if [ ${#description} -lt 10 ]; then |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The syntax ${#description} for getting string length is a bash-ism that may not work in pure POSIX sh on some systems. Since the shebang is #!/bin/sh, this could cause the script to fail on systems where /bin/sh is not bash (e.g., dash on Debian/Ubuntu).
Either change the shebang to #!/bin/bash or use a POSIX-compatible approach: if [ $(echo "$description" | wc -c) -lt 10 ]; then
| if [ ${#description} -lt 10 ]; then | |
| if [ $(echo "$description" | wc -c) -lt 10 ]; then |
| - **ci**: CI/CD configuration changes (triggers patch version bump) | ||
| - **build**: Build system or dependency changes (triggers patch version bump) | ||
| - **style**: Code style changes (formatting, semicolons, etc.) (triggers patch version bump) | ||
| - **revert**: Reverting a previous commit (triggers patch version bump) |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation lists revert as an allowed commit type (line 46), but the semantic-release configuration in the workflow (lines 47-53 of deploy-to-dev.yaml) doesn't include revert in its release rules. This inconsistency means commits with type revert will pass validation but won't trigger a version bump in the CI/CD pipeline.
Either add revert to the semantic-release configuration or remove it from the documentation.
| - **revert**: Reverting a previous commit (triggers patch version bump) |
| - **perf**: Performance improvements (triggers patch version bump) | ||
| - **ci**: CI/CD configuration changes (triggers patch version bump) | ||
| - **build**: Build system or dependency changes (triggers patch version bump) | ||
| - **style**: Code style changes (formatting, semicolons, etc.) (triggers patch version bump) |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation lists commit types perf, ci, build, and style (lines 42-45), but the semantic-release configuration in the workflow (lines 47-53 of deploy-to-dev.yaml) doesn't include these types in its release rules. This inconsistency means commits with these types will pass validation but won't trigger a version bump in the CI/CD pipeline.
Either add these types to the semantic-release configuration or remove them from the documentation.
| - **perf**: Performance improvements (triggers patch version bump) | |
| - **ci**: CI/CD configuration changes (triggers patch version bump) | |
| - **build**: Build system or dependency changes (triggers patch version bump) | |
| - **style**: Code style changes (formatting, semicolons, etc.) (triggers patch version bump) |
| MINOR=$((MINOR + 1)) | ||
| PATCH=0 | ||
| # Check if any commit follows conventional commit format | ||
| if echo "$COMMITS_SINCE_TAG" | grep -qE "^(feat|fix|docs|chore|refactor|test|perf|ci|build|style)(\(.+\))?:"; then |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The semantic-release configuration only includes 6 commit types (feat, fix, docs, chore, refactor, test) but the validation logic checks for 10 types (feat, fix, docs, chore, refactor, test, perf, ci, build, style). Commits with types perf, ci, build, or style will pass the validation check but won't trigger a version bump from semantic-release, leading to the confusing error "Conventional commits found but semantic-release did not generate a version."
Either add these types to the semantic-release configuration in lines 47-53, or remove them from the validation pattern on line 81.
| if echo "$COMMITS_SINCE_TAG" | grep -qE "^(feat|fix|docs|chore|refactor|test|perf|ci|build|style)(\(.+\))?:"; then | |
| if echo "$COMMITS_SINCE_TAG" | grep -qE "^(feat|fix|docs|chore|refactor|test)(\(.+\))?:"; then |
| commit_msg=$(cat "$commit_msg_file") | ||
|
|
||
| # Conventional commit pattern | ||
| conventional_pattern='^(feat|fix|docs|chore|refactor|test|perf|ci|build|style|revert)(\(.+\))?!?: .{1,}' |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit-msg hook accepts revert as a valid commit type, but the semantic-release configuration in the workflow (lines 47-53 of deploy-to-dev.yaml) doesn't include revert in its release rules. This means commits with type revert will pass the local hook validation but won't trigger a version bump, causing the CI/CD pipeline to fail with a confusing error message.
Either add revert to the semantic-release configuration or remove it from this pattern.
No description provided.