branch-validator-pro
v1.1.1
Published
Professional Git branch and commit validator for consistent naming conventions. Validates format and ensures proper ticket ID patterns without external API dependencies. Perfect for teams worldwide.
Maintainers
Keywords
Readme
🔍 Branch Validator Pro
A lightweight Node.js package that validates Git branch names and commit messages following consistent conventions and best practices.
🚀 Overview
Branch Validator Pro enforces consistent Git naming conventions across your team, ensuring code quality and maintainability through automated validation of branch names and commit messages.
✨ Features
- ✅ Git branch name validation with proper prefixes (feature/, bugfix/, hotfix/, release/, chore/)
- ✅ Commit message validation following consistent patterns
- ✅ Command-line interface for easy integration
- ✅ Programmatic API for custom implementations
- ✅ Git hook integration for automated validation
- ✅ Zero dependencies for minimal footprint
📦 Installation
Global Installation (Recommended)
npm install -g branch-validator-proLocal Installation
npm install branch-validator-pro🎯 Quick Start
Basic Usage
# Validate branch names
validate-git branch feature/TASK-1234-add-user-authentication
validate-git branch bugfix/TASK-5678-fix-login-bug
validate-git branch hotfix/TASK-9012-critical-security-patch
# Validate commit messages
validate-git commit TASK-1234-add-user-authentication
validate-git commit TASK-5678-fix-login-bugOutput
✅ Branch name is valid: feature/TASK-1234-add-user-authentication
✅ Commit message is valid: TASK-1234-fix-login-bug📖 Programmatic Usage
const { validateBranchName, validateCommitMessage } = require('branch-validator-pro');
// Validate branch name
const branchResult = validateBranchName('feature/TASK-1234-new-feature');
console.log(branchResult.valid); // true/false
console.log(branchResult.message); // validation message
// Validate commit message
const commitResult = validateCommitMessage('TASK-1234-new-feature');
console.log(commitResult.valid); // true/false
console.log(commitResult.message); // validation message📋 Validation Rules
Branch Names
- Must start with one of these prefixes:
feature/- for new featuresbugfix/- for bug fixeshotfix/- for critical fixesrelease/- for release brancheschore/- for maintenance tasks
- Must contain a ticket pattern:
TASK-XXXX(where XXXX is a number) - Description must be lowercase
- Use dashes (-) only, no spaces or underscores
- Pattern:
^[a-z]+/TASK-\d+-[a-z0-9-]+$
Valid Examples:
feature/TASK-1234-add-payment-gatewaybugfix/TASK-5678-fix-validation-errorhotfix/TASK-9012-security-patch
Invalid Examples:
feature/add-payment(missing ticket)Feature/TASK-1234-payment(uppercase prefix)feature/TASK-1234_payment_gateway(underscores not allowed)feature/TASK-1234-Payment Gateway(spaces not allowed)
Commit Messages
- Must follow the pattern:
TASK-XXXX-description - Use lowercase letters, numbers, and dashes only
- No spaces or underscores allowed
- Pattern:
^TASK-\d+-[a-z0-9-]+$
Valid Examples:
TASK-1234-implement-user-registrationTASK-5678-fix-database-connectionTASK-9012-update-security-headers
Invalid Examples:
TASK-1234 implement user registration(spaces not allowed)TASK-1234_implement_user_registration(underscores not allowed)implement user registration(missing ticket)
🪝 Git Hook Integration
Integrate this validator with Git hooks for automatic validation on every commit.
Pre-commit Hook
Create .git/hooks/pre-commit:
#!/bin/bash
branch_name=$(git symbolic-ref --short HEAD)
validate-git branch "$branch_name"
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Branch name validation failed!"
exit 1
fiCommit Message Hook
Create .git/hooks/commit-msg:
#!/bin/bash
commit_msg=$(cat $1)
validate-git commit "$commit_msg"
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Commit message validation failed!"
exit 1
fiMake hooks executable:
chmod +x .git/hooks/pre-commit
chmod +x .git/hooks/commit-msg🔌 API Reference
validateBranchName(branchName)
Validates a Git branch name against the defined rules.
Parameters:
branchName(string): The branch name to validate
Returns:
valid(boolean): Whether the branch name is validmessage(string): Validation result message
validateCommitMessage(commitMessage)
Validates a commit message against the defined rules.
Parameters:
commitMessage(string): The commit message to validate
Returns:
valid(boolean): Whether the commit message is validmessage(string): Validation result message
🚪 Exit Codes
0: Validation successful1: Validation failed or invalid usage
📝 Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Commit your changes:
git commit -m "your-feature-description" - Push to the branch:
git push origin feature/your-feature - Submit a pull request
📄 License
MIT License - see LICENSE file for details.
👤 Author
✨ Sanjib Roy
A passionate developer focused on building tools that enhance developer productivity and code quality.
Connect with me:
- 🌐 GitHub: @snbroy
- 💼 LinkedIn: Sanjib Roy
- 📧 Email: [email protected]
- 📱 Mobile: +91 8918132291
💬 Support
For issues or questions, please reach out:
- 📧 Email: [email protected]
- 📱 Mobile: +91 8918132291
- 🐛 Open an issue on GitHub
📚 Changelog
v1.0.0
- Initial release
- Branch name validation
- Commit message validation
- CLI interface
- Programmatic API
- Git hook integration support
