This documentation covers two Bash scripts:
squashMergePR.bash
: The main script for squash merging pull requests with conventional commit messages.test_squashMergePR.bash
: A testing script to create test cases for the main script.
The squashMergePR.bash
script automates the process of squash merging pull requests (PRs) while ensuring the commit message follows the conventional commit format. It handles various scenarios, including breaking changes and co-authors.
- Fetches PR details using GitHub CLI
- Parses PR title to extract type, scope, and description
- Handles breaking changes and co-authors
- Allows manual editing of the commit message before merging
- Performs squash merge using GitHub CLI
- GitHub CLI (
gh
) installed and authenticated jq
command-line JSON processor installed
./squashMergePR.bash [options] [--pr <PR number>]
--type <type>
: Type of commit (e.g., feat, fix)--scope <scope>
: Scope of the commit (e.g., lib, none)--description <description>
: Description of the commit--body <body>
: Body of the commit message--breaking-change <yes|no>
: Specify if the commit introduces a breaking change--breaking-change-description <desc>
: Description of the breaking change--repo <GitHub repo URL>
: GitHub repository URL--pr <PR number>
: The number of the pull request to merge--coauthor <co-authors>
: Specify co-authors for the commit--help
: Display help message and exit
- The script checks for dependencies (
gh
andjq
) - It authenticates with GitHub CLI if not already done
- It fetches PR details based on the provided PR number
- The PR title is parsed to extract type, scope, and description
- Breaking changes and co-authors are extracted from commit messages
- The user is prompted to review and optionally edit the commit message
- The script performs a squash merge using the GitHub CLI
This document details a comprehensive test script for validating pull request (PR) handling with conventional commits, breaking changes, and co-authors. The script creates various test cases to ensure proper handling of different PR scenarios.
- Git installed and configured
- GitHub CLI (
gh
) installed and authenticated - Bash shell environment
- Repository access with PR creation permissions
VALID_TYPES=("build" "chore" "ci" "docs" "feat" "fix" "perf" "refactor" "style" "test")
VALID_SCOPES=("dev" "comp" "lib" "fd2" "examples" "school" "none")
The script includes a predefined list of co-authors for testing collaboration scenarios:
COAUTHORS=(
"Grant Braught <braught@dickinson.edu>"
"John MacCormick <jmac@dickinson.edu>"
"William Goble <goblew@dickinson.edu>"
"Matt Ferland <ferlandm@dickinson.edu>"
"Boosung Kim <kimbo@dickinson.edu>"
"Ty Chermsirivatana <chermsit@dickinson.edu>"
)
The script includes 15 distinct test cases, each designed to test specific aspects of PR handling:
- Purpose: Tests handling of breaking changes mentioned only in PR description
- Behavior: Creates a PR with breaking change notation in description only
- Expected: System should detect and handle breaking change from PR description
- Purpose: Tests breaking changes in commit messages only
- Behavior: Creates commits with breaking change notations
- Expected: System should extract breaking changes from commit messages
- Purpose: Tests handling of breaking changes in both PR and commits
- Behavior: Includes breaking changes in both PR description and commits
- Expected: System should properly consolidate breaking changes from both sources
- Purpose: Tests co-author handling in PR description
- Behavior: Adds co-author information only in PR description
- Expected: System should correctly attribute co-authorship from PR
- Purpose: Tests co-author handling in commits
- Behavior: Includes co-author information in commit messages
- Expected: System should extract co-author information from commits
- Purpose: Tests co-author handling from multiple sources
- Behavior: Includes co-authors in both PR description and commits
- Expected: System should properly combine co-author information
- Purpose: Tests handling of invalid conventional commit format
- Behavior: Creates PR with invalid type and scope
- Expected: System should detect and handle invalid format appropriately
- Purpose: Tests handling of incomplete conventional commit format
- Behavior: Creates PR without type and scope
- Expected: System should handle missing components gracefully
- Purpose: Tests handling of invalid commit type
- Behavior: Creates PR with invalid type but valid scope
- Expected: System should detect invalid type and respond appropriately
- Purpose: Tests handling of invalid scope
- Behavior: Creates PR with valid type but invalid scope
- Expected: System should detect invalid scope and respond appropriately
- Purpose: Tests handling of missing type
- Behavior: Creates PR without type but with scope
- Expected: System should detect missing type and handle accordingly
- Purpose: Tests handling of missing scope
- Behavior: Creates PR with type but without scope
- Expected: System should handle missing scope appropriately
- Purpose: Tests handling of empty PR titles
- Behavior: Creates PR with empty title
- Expected: System should handle empty titles gracefully
- Purpose: Tests handling of very long PR titles
- Behavior: Creates PR with exceptionally long title
- Expected: System should handle long titles appropriately
- Purpose: Tests handling of special characters
- Behavior: Creates PR with special characters in title
- Expected: System should properly handle special characters
./test_squashMergePR.bash [OPTIONS]
-h, --help
: Display help information-r, --reset
: Reset all test cases (removes branches and directories)-a, --all
: Run all test cases-s, --select CASES
: Run specific test cases (comma-separated list)-R, --random
: Use random co-authors-T, --types
: Use random types/scopes--full-random
: Use both random co-authors and types/scopes
# Run all test cases
./test_squashMergePR.bash -a
# Run specific test cases
./test_squashMergePR.bash -s 1,2,3
# Run with random co-authors
./test_squashMergePR.bash -a -R
# Reset all test cases
./test_squashMergePR.bash -r
Generates PR titles based on test parameters:
- Handles valid/invalid types and scopes
- Supports missing components
- Follows conventional commit format
Creates test PRs with specified parameters:
- Generates branches
- Creates test files
- Makes commits with appropriate messages
- Handles breaking changes and co-authors
- Creates GitHub PR
Manages test case execution:
- Processes test case selection
- Handles random features
- Executes appropriate test cases
Cleans up test environment:
- Removes test branches
- Deletes test directories
- Resets to main branch
-
Test Environment
- Use a dedicated test repository
- Ensure clean state before running tests
- Regular cleanup using reset function
-
Test Execution
- Run all tests before making changes
- Test specific cases after modifications
- Verify results manually
-
Maintenance
- Keep co-author list updated
- Maintain valid types and scopes
- Regular script updates
-
Authentication Issues
- Verify GitHub CLI authentication
- Check repository permissions
- Ensure SSH keys are configured
-
Failed PRs
- Check branch conflicts
- Verify GitHub API access
- Review error messages
-
Clean Up
- Use reset option regularly
- Manual cleanup if needed
- Check remote branches
- Conventional Commits: https://www.conventionalcommits.org/
- GitHub CLI documentation: https://cli.github.com/manual/
- Git documentation: https://git-scm.com/doc