This repository contains a simple bash script allows a simplified workflow for handling pull request squash merges that adhere to conventional commit formatting.
squashMergePR.bash- Main script for squash merging PRs with conventional commit messagestestSquashMerge.bash- Test case generator for creating various PR scenarios
Automates squash merging of pull requests while ensuring commit messages follow conventional commit format. Handles breaking changes, co-authors, and various edge cases.
- Fetches PR details using GitHub CLI
- Parses PR titles to extract type, scope, and description
- Handles breaking changes and co-authors from both PR descriptions and commit messages
- Interactive commit message editing before merge
- Validates conventional commit format components
- Supports both HTTPS and SSH GitHub repository URLs
- GitHub CLI (
gh) installed and authenticated jqcommand-line JSON processor- Git repository with GitHub remote
./squashMergePR.bash [options] [--pr <PR number>]--type <type>: Commit type (feat, fix, docs, etc.)--scope <scope>: Commit scope (comp, lib, dev, etc.)--description <description>: Commit description--body <body>: Commit message body--breaking-change <yes|no>: Breaking change flag--breaking-change-description <desc>: Breaking change description--repo <GitHub repo URL>: Repository URL--pr <PR number>: Pull request number--coauthor <co-authors>: Co-authors for the commit--help: Display help message
build, chore, ci, docs, feat, fix, perf, refactor, style, test
dev, comp, lib, fd2, examples, school, none
Creates test PRs with various scenarios to validate the main script functionality.
- Breaking change in PR description only
- Breaking change in commit messages only
- Breaking changes in both locations
- Co-authors in PR description only
- Co-authors in commit messages only
- Co-authors in both locations
- Invalid type and scope
- Missing type and scope
- Invalid type only
- Invalid scope only
- Missing type only
- Missing scope only
- Empty title
- Very long title
- Special characters in title
./testSquashMerge.bash [OPTIONS]-h, --help: Display help-r, --reset: Reset all test cases-a, --all: Run all test cases-s, --select CASES: Run specific test cases (comma-separated)-R, --random: Use random co-authors-T, --types: Use random types/scopes--full-random: Use both random co-authors and types/scopes
The project uses BATS (Bash Automated Testing System) for comprehensive testing.
test/
├── bats/ # BATS core (submodule)
├── test_helper/
│ ├── bats-support/ # BATS support library (submodule)
│ └── bats-assert/ # BATS assert library (submodule)
├── test_helper.bash # Test helper functions
├── test_squashMergePR.bats # Main script tests
└── run_tests.sh # Test runner script
# Run tests (For some reason, it needs to run in the test directory. I'm likely missing out on some trivial relative import I can make static but until then!)
cd test && ./run_tests.sh# Clone repository
git clone <repository-url>
cd <repository-name>
# Initialize submodules
git submodule update --init --recursive
# Make scripts executable
chmod +x squashMergePR.bash testSquashMerge.bash test/run_tests.sh# Install GitHub CLI
# Follow instructions at: https://cli.github.com/
# Authenticate
gh auth login- Navigate to your Git repository
- Run the script with a PR number:
./squashMergePR.bash --pr 123
- Review the generated commit message
- Choose to accept, edit, or cancel
- Script performs the squash merge
- Create test cases using the test script:
./testSquashMerge.bash -s 1,2,3
- Test the main script against generated PRs
- Run the test suite to ensure functionality:
cd test/ && ./run_tests.sh
The scripts handle various error conditions:
- Missing dependencies (gh, jq)
- Invalid PR numbers or states
- Malformed repository URLs
- Invalid conventional commit formats
- Network connectivity issues
- Add test cases to appropriate
.batsfiles - Follow existing test patterns
- Run test suite to verify changes
- Update documentation as needed
- Update relevant functions
- Add corresponding tests
- Run full test suite
- Update README if interface changes