feat: enhance merge-pull-requests-by-title.sh with owner and topic filtering options#160
Merged
joshjohanning merged 7 commits intomainfrom Mar 24, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Enhances gh-cli/merge-pull-requests-by-title.sh to support discovering repositories dynamically (by owner and optional topics) in addition to reading repositories from a file, making the script more flexible for bulk PR merges.
Changes:
- Added
--ownermode to fetch repositories via GitHub API, with optional repeatable--topicfiltering - Reworked argument parsing/help text to support valued options alongside existing flags
- Unified repository iteration to handle both file-based input and owner-fetched input
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (4)
gh-cli/merge-pull-requests-by-title.sh:263
- Repository fetching in
--ownermode silences all API errors by redirecting stderr to/dev/null, but then emits a generic failure message. This makes debugging permission/rate-limit/hostname issues difficult; consider capturing stderr (as you already do later for PR fetching) and include it in the error output.
repo_urls=$(gh api --paginate "/orgs/$search_owner/repos?per_page=100" \
--jq ".[] | $jq_topic_filter" 2>/dev/null)
owner_exit=$?
repo_fetch_exit=$owner_exit
if [ $owner_exit -ne 0 ] || [ -z "$repo_urls" ]; then
repo_urls=$(gh api --paginate "/users/$search_owner/repos?per_page=100" \
--jq ".[] | $jq_topic_filter" 2>/dev/null)
repo_fetch_exit=$?
fi
if [ $repo_fetch_exit -ne 0 ]; then
echo "Error: Failed to fetch repositories for '$search_owner'"
exit 1
gh-cli/merge-pull-requests-by-title.sh:257
repo_urlsis populated with.full_namevalues (owner/repo), not URLs. Renaming this to something likerepo_full_names/repo_nameswould make the later conversion to URLs clearer and avoid confusion with the file-based mode that actually contains URLs.
repo_urls=$(gh api --paginate "/orgs/$search_owner/repos?per_page=100" \
--jq ".[] | $jq_topic_filter" 2>/dev/null)
owner_exit=$?
repo_fetch_exit=$owner_exit
if [ $owner_exit -ne 0 ] || [ -z "$repo_urls" ]; then
repo_urls=$(gh api --paginate "/users/$search_owner/repos?per_page=100" \
--jq ".[] | $jq_topic_filter" 2>/dev/null)
gh-cli/merge-pull-requests-by-title.sh:490
--ownermode hardcodeshttps://github.com/...when constructing repository URLs. This breaks GitHub Enterprise / GH_HOST usage; the repo’s script guidelines call out adding hostname support when applicable. Consider adding a--hostname(defaultgithub.com) or usingGH_HOST, and use it both forgh apicalls and when constructing URLs.
done < <(if [ -n "$search_owner" ]; then
# --owner mode: repo_urls contains owner/repo format, convert to URLs
echo "$repo_urls" | while IFS= read -r repo_name; do
echo "https://github.com/$repo_name"
done
gh-cli/merge-pull-requests-by-title.sh:257
- The new
gh apicalls in--ownermode don’t pass a hostname, which prevents using the script against GHES/GHE.com instances. This repo commonly supports an optional hostname and passes it through togh api --hostname ...; consider adding similar hostname support here to keep behavior consistent acrossgh-cliscripts.
repo_urls=$(gh api --paginate "/orgs/$search_owner/repos?per_page=100" \
--jq ".[] | $jq_topic_filter" 2>/dev/null)
owner_exit=$?
repo_fetch_exit=$owner_exit
if [ $owner_exit -ne 0 ] || [ -z "$repo_urls" ]; then
repo_urls=$(gh api --paginate "/users/$search_owner/repos?per_page=100" \
--jq ".[] | $jq_topic_filter" 2>/dev/null)
…erge-pull-requests-by-title.sh
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
gh-cli/merge-pull-requests-by-title.sh:495
- In
--ownermode, repositories are converted to URLs using a hard-codedhttps://github.com/...base. This can confuse or break workflows when using GitHub Enterprise (or any non-github.com host) and also diverges from the script’s owngh apihost context. Prefer building URLs using a configurable hostname (or avoid URLs entirely here by feedingowner/repovalues directly into the processing loop).
# --owner mode: repo_names contains owner/repo format, convert to URLs
echo "$repo_names" | while IFS= read -r name; do
echo "https://github.com/$name"
done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds significant enhancements to the
merge-pull-requests-by-title.shscript in thegh-clidirectory, making it much more flexible and user-friendly. The main improvement is the introduction of a new mode that allows searching for pull requests by owner (user or organization) and topic(s), in addition to the previous file-based approach. The help text, argument parsing, and input validation have all been updated to support these new features.