Skip to content

feat: enhance merge-pull-requests-by-title.sh with owner and topic filtering options#160

Merged
joshjohanning merged 7 commits intomainfrom
add-filtering-to-merge-pr-script
Mar 24, 2026
Merged

feat: enhance merge-pull-requests-by-title.sh with owner and topic filtering options#160
joshjohanning merged 7 commits intomainfrom
add-filtering-to-merge-pr-script

Conversation

@joshjohanning
Copy link
Copy Markdown
Owner

This pull request adds significant enhancements to the merge-pull-requests-by-title.sh script in the gh-cli directory, 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.

Copilot AI review requested due to automatic review settings March 24, 2026 02:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 --owner mode to fetch repositories via GitHub API, with optional repeatable --topic filtering
  • 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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 6 comments.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 --owner mode 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_urls is populated with .full_name values (owner/repo), not URLs. Renaming this to something like repo_full_names/repo_names would 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

  • --owner mode hardcodes https://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 (default github.com) or using GH_HOST, and use it both for gh api calls 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 api calls in --owner mode 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 to gh api --hostname ...; consider adding similar hostname support here to keep behavior consistent across gh-cli scripts.
  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)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 --owner mode, repositories are converted to URLs using a hard-coded https://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 own gh api host context. Prefer building URLs using a configurable hostname (or avoid URLs entirely here by feeding owner/repo values 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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

@joshjohanning joshjohanning merged commit fb29c05 into main Mar 24, 2026
6 checks passed
@joshjohanning joshjohanning deleted the add-filtering-to-merge-pr-script branch March 24, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants