Skip to content

Commit 8a1fd57

Browse files
feat(gh-cli): add --no-prompt flag to merge-pull-requests-by-title.sh
Co-authored-by: joshjohanning <19912012+joshjohanning@users.noreply.github.com>
1 parent 48de965 commit 8a1fd57

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

gh-cli/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,17 +1483,20 @@ Creates a (mostly) empty migration for a given organization repository so that i
14831483

14841484
### merge-pull-requests-by-title.sh
14851485

1486-
Finds and merges pull requests matching a title pattern across multiple repositories. Useful for batch merging Dependabot PRs or other automated PRs with similar titles.
1486+
Finds and merges pull requests matching a title pattern across multiple repositories. Useful for batch merging Dependabot PRs or other automated PRs with similar titles. By default, prompts for confirmation before each merge; use `--no-prompt` to skip.
14871487

14881488
```bash
1489-
# Find and merge PRs with exact title match
1489+
# Find and merge PRs with exact title match (prompts for confirmation per PR)
14901490
./merge-pull-requests-by-title.sh repos.txt "chore(deps-dev): bump eslint from 8.0.0 to 9.0.0"
14911491

14921492
# Use wildcard to match partial titles
14931493
./merge-pull-requests-by-title.sh repos.txt "chore(deps-dev): bump eslint*"
14941494

1495-
# With custom commit title
1496-
./merge-pull-requests-by-title.sh repos.txt "chore(deps)*" squash "chore(deps): update dependencies"
1495+
# Merge without confirmation prompt
1496+
./merge-pull-requests-by-title.sh repos.txt "chore(deps)*" squash "" --no-prompt
1497+
1498+
# With custom commit title, no confirmation prompt
1499+
./merge-pull-requests-by-title.sh repos.txt "chore(deps)*" squash "chore(deps): update dependencies" --no-prompt
14971500

14981501
# Dry run to preview
14991502
./merge-pull-requests-by-title.sh repos.txt "chore(deps)*" squash "" --dry-run

gh-cli/merge-pull-requests-by-title.sh

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Finds and merges pull requests matching a title pattern across multiple repositories
44
#
55
# Usage:
6-
# ./merge-pull-requests-by-title.sh <repo_list_file> <pr_title_pattern> [merge_method] [commit_title] [--dry-run] [--bump-patch-version]
6+
# ./merge-pull-requests-by-title.sh <repo_list_file> <pr_title_pattern> [merge_method] [commit_title] [--dry-run] [--bump-patch-version] [--no-prompt]
77
#
88
# Arguments:
99
# repo_list_file - File with repository URLs (one per line)
@@ -12,13 +12,14 @@
1212
# commit_title - Optional: custom commit title for all merged PRs (PR number is auto-appended)
1313
# --dry-run - Optional: preview what would be merged without actually merging
1414
# --bump-patch-version - Optional: clone each matching PR branch, run npm version patch, commit, and push (mutually exclusive with --dry-run and merge)
15+
# --no-prompt - Optional: merge without interactive confirmation (default is to prompt before each merge)
1516
#
1617
# Examples:
17-
# # Find and merge PRs with exact title match
18+
# # Find and merge PRs with exact title match (will prompt for confirmation)
1819
# ./merge-pull-requests-by-title.sh repos.txt "chore(deps-dev): bump eslint-plugin-jest from 29.5.0 to 29.9.0 in the eslint group"
1920
#
20-
# # With custom commit title
21-
# ./merge-pull-requests-by-title.sh repos.txt "chore(deps-dev): bump eslint*" squash "chore(deps): update eslint dependencies"
21+
# # With custom commit title, no confirmation prompt
22+
# ./merge-pull-requests-by-title.sh repos.txt "chore(deps-dev): bump eslint*" squash "chore(deps): update eslint dependencies" --no-prompt
2223
#
2324
# # Dry run to preview
2425
# ./merge-pull-requests-by-title.sh repos.txt "chore(deps)*" squash "" --dry-run
@@ -37,26 +38,30 @@
3738
# - If multiple PRs match in a repo, all will be listed but only the first will be merged (use --dry-run to preview)
3839
# - --bump-patch-version clones each matching PR branch to a temp dir, bumps the npm patch version, commits, and pushes
3940
# - --bump-patch-version is mutually exclusive with --dry-run
41+
# - By default, merge mode prompts for confirmation before each PR merge; use --no-prompt to skip
4042
#
4143
# TODO:
4244
# - Add --delete-branch flag to delete remote branch after merge
4345
# - Add --bypass flag to bypass branch protection requirements
4446

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

47-
# Check for --dry-run and --bump-patch-version flags anywhere in arguments
49+
# Check for --dry-run, --bump-patch-version, and --no-prompt flags anywhere in arguments
4850
dry_run=false
4951
bump_patch_version=false
52+
no_prompt=false
5053
for arg in "$@"; do
5154
if [ "$arg" = "--dry-run" ]; then
5255
dry_run=true
5356
elif [ "$arg" = "--bump-patch-version" ]; then
5457
bump_patch_version=true
58+
elif [ "$arg" = "--no-prompt" ]; then
59+
no_prompt=true
5560
fi
5661
done
5762

5863
if [ $# -lt 2 ]; then
59-
echo "Usage: $0 <repo_list_file> <pr_title_pattern> [merge_method] [commit_title] [--dry-run] [--bump-patch-version]"
64+
echo "Usage: $0 <repo_list_file> <pr_title_pattern> [merge_method] [commit_title] [--dry-run] [--bump-patch-version] [--no-prompt]"
6065
echo ""
6166
echo "Arguments:"
6267
echo " repo_list_file - File with repository URLs (one per line)"
@@ -65,6 +70,7 @@ if [ $# -lt 2 ]; then
6570
echo " commit_title - Optional: custom commit title for merged PRs (PR number is auto-appended)"
6671
echo " --dry-run - Preview what would be merged without actually merging"
6772
echo " --bump-patch-version - Bump npm patch version on each matching PR branch and push (mutually exclusive with --dry-run)"
73+
echo " --no-prompt - Merge without interactive confirmation (default is to prompt before each merge)"
6874
exit 1
6975
fi
7076

@@ -219,12 +225,23 @@ while IFS= read -r repo_url || [ -n "$repo_url" ]; do
219225
if [ "$dry_run" = true ]; then
220226
echo " 🔍 Would merge $repo#$pr_number with: gh pr merge $pr_number --repo $repo ${merge_args[*]}"
221227
((success_count++))
222-
elif gh pr merge "$pr_number" --repo "$repo" "${merge_args[@]}"; then
223-
echo " ✅ Successfully merged $repo#$pr_number"
224-
((success_count++))
225228
else
226-
echo " ❌ Failed to merge $repo#$pr_number"
227-
((fail_count++))
229+
# Prompt for confirmation unless --no-prompt was passed
230+
if [ "$no_prompt" = false ]; then
231+
read -r -p " ❓ Merge $repo#$pr_number? [y/N] " confirm < /dev/tty
232+
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
233+
echo " ⏭️ Skipped $repo#$pr_number"
234+
((skipped_count++))
235+
continue
236+
fi
237+
fi
238+
if gh pr merge "$pr_number" --repo "$repo" "${merge_args[@]}"; then
239+
echo " ✅ Successfully merged $repo#$pr_number"
240+
((success_count++))
241+
else
242+
echo " ❌ Failed to merge $repo#$pr_number"
243+
((fail_count++))
244+
fi
228245
fi
229246
fi
230247
done <<< "$matching_prs"

0 commit comments

Comments
 (0)