Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 43 additions & 20 deletions gh-cli/merge-pull-requests-by-title.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,59 @@

merge_methods=("merge" "squash" "rebase")

print_help() {
echo "Find and merge pull requests matching a title pattern across multiple repositories"
echo ""
echo "Usage:"
echo " $0 <repo_list_file> <pr_title_pattern> [merge_method] [commit_title] [flags...]"
echo " $0 --owner <owner> <pr_title_pattern> [--topic <topic>]... [merge_method] [commit_title] [flags...]"
echo ""
echo "Required (one of):"
echo " repo_list_file - File with repository URLs (one per line)"
echo " --owner <owner> - Search repositories for this user or organization"
echo ""
echo "Required:"
echo " pr_title_pattern - Title pattern to match (exact match or use * for wildcard)"
echo ""
echo "Optional positional arguments:"
echo " merge_method - Merge method: merge, squash, or rebase (default: squash)"
echo " commit_title - Custom commit title for merged PRs (PR number is auto-appended; defaults to PR title)"
echo ""
echo "Flags:"
echo " -h, --help - Show this help message and exit"
echo " --topic <topic> - Filter --owner repositories by topic (can be specified multiple times)"
echo " --dry-run - Preview what would be merged without actually merging"
echo " --bump-patch-version - Clone each matching PR branch, run npm version patch, commit, and push"
echo " --enable-auto-merge - Enable auto-merge on matching PRs"
echo " --no-prompt - Merge without interactive confirmation"
Comment on lines +89 to +95
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

--bump-patch-version help text omits a key behavioral detail: when this flag is used without --enable-auto-merge, the script only bumps/commits/pushes and does not merge PRs. Updating the help output to mention this would prevent users from assuming a merge will happen.

Copilot uses AI. Check for mistakes.
echo ""
echo "Flag compatibility:"
echo " --dry-run and --bump-patch-version are mutually exclusive"
echo " --dry-run and --enable-auto-merge are mutually exclusive"
echo " --topic requires --owner"
echo ""
echo "Examples:"
echo " $0 repos.txt \"chore(deps)*\" --dry-run"
echo " $0 repos.txt \"chore(deps)*\" --bump-patch-version --enable-auto-merge"
echo " $0 --owner joshjohanning --topic github-action \"chore(deps)*\" --no-prompt"
}

# Check for flags and valued options
dry_run=false
bump_patch_version=false
enable_auto_merge=false
no_prompt=false
search_owner=""
topics=()
valid_flags=("--dry-run" "--bump-patch-version" "--enable-auto-merge" "--no-prompt" "--owner" "--topic")
valid_flags=("-h" "--help" "--dry-run" "--bump-patch-version" "--enable-auto-merge" "--no-prompt" "--owner" "--topic")
args=("$@")
i=0
while [ $i -lt ${#args[@]} ]; do
arg="${args[$i]}"
if [ "$arg" = "--dry-run" ]; then
if [ "$arg" = "--help" ] || [ "$arg" = "-h" ]; then
print_help
exit 0
elif [ "$arg" = "--dry-run" ]; then
Comment on lines +115 to +123
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

This PR adds new user-facing input flags (-h/--help). The gh-cli/README.md section for this script currently doesn’t mention the help option; please update the README entry to reflect the new flag so usage docs stay in sync.

Copilot generated this review using guidance from repository custom instructions.
dry_run=true
elif [ "$arg" = "--bump-patch-version" ]; then
bump_patch_version=true
Expand Down Expand Up @@ -116,24 +156,7 @@ while [ $i -lt ${#args[@]} ]; do
done

if [ $# -lt 2 ]; then
echo "Usage: $0 <repo_list_file> <pr_title_pattern> [merge_method] [commit_title] [flags...]"
echo " $0 --owner <owner> <pr_title_pattern> [--topic <topic>]... [merge_method] [commit_title] [flags...]"
echo ""
echo "Required (one of):"
echo " repo_list_file - File with repository URLs (one per line)"
echo " --owner <owner> - Search repositories for this user or organization"
echo ""
echo "Required:"
echo " pr_title_pattern - Title pattern to match (use * for wildcard)"
echo ""
echo "Optional:"
echo " merge_method - merge, squash, or rebase (default: squash)"
echo " commit_title - Custom commit title for merged PRs (defaults to PR title)"
echo " --topic <topic> - Filter --owner repositories by topic (repeatable)"
echo " --dry-run - Preview what would be merged (cannot combine with --bump-patch-version or --enable-auto-merge)"
echo " --bump-patch-version - Bump npm patch version on each matching PR branch and push (cannot combine with --dry-run)"
echo " --enable-auto-merge - Enable auto-merge on matching PRs (can combine with --bump-patch-version, cannot combine with --dry-run)"
echo " --no-prompt - Merge without interactive confirmation"
print_help
exit 1
fi

Expand Down
Loading