<commit_before># frozen_string_literal: true

require "cli/parser"
require "utils/github"

module Homebrew
  module_function

  def pr_automerge_args
    Homebrew::CLI::Parser.new do
      usage_banner <<~EOS
        `pr-automerge` [<options>]

        Find pull requests that can be automatically merged using `brew pr-publish`.
      EOS
      flag   "--tap=",
             description: "Target tap repository (default: `homebrew/core`)."
      flag   "--with-label=",
             description: "Pull requests must have this label."
      comma_array "--without-labels=",
                  description: "Pull requests must not have these labels (default: `do not merge`, `new formula`)."
      switch "--without-approval",
             description: "Pull requests do not require approval to be merged."
      switch "--publish",
             description: "Run `brew pr-publish` on matching pull requests."
      switch "--ignore-failures",
             description: "Include pull requests that have failing status checks."
      switch :verbose
      switch :debug
      max_named 0
    end
  end

  def pr_automerge
    pr_automerge_args.parse

    without_labels = Homebrew.args.without_labels || ["do not merge", "new formula"]
    tap = Tap.fetch(Homebrew.args.tap || CoreTap.instance.name)

    query = "is:pr is:open repo:#{tap.full_name}"
    query += Homebrew.args.ignore_failures? ? " -status:pending" : " status:success"
    query += " review:approved" unless Homebrew.args.without_approval?
    query += " label:\"#{with_label}\"" if Homebrew.args.with_label
    without_labels&.each { |label| query += " -label:\"#{label}\"" }
    odebug "Searching: #{query}"

    prs = GitHub.search_issues query
    if prs.blank?
      ohai "No matching pull requests!"
      return
    end

    ohai "#{prs.size} matching pull requests:"
    pr_urls = []
    prs.each do |pr|
      puts "#{tap.full_name unless tap.core_tap?}##{pr["number"]}: #{pr["title"]}"
      pr_urls << pr["html_url"]
    end

    if args.publish?
      publish_args = ["pr-publish"]
      publish_args << "--tap=#{args.tap}" if args.tap
      safe_system HOMEBREW_BREW_FILE, *publish_args, *pr_urls
    else
      ohai "Now run:", "  brew pr-publish \\\n    #{pr_urls.join " \\\n    "}"
    end
  end
end<commit_msg>pr-automerge: pass proper tap variable<commit_after># frozen_string_literal: true

require "cli/parser"
require "utils/github"

module Homebrew
  module_function

  def pr_automerge_args
    Homebrew::CLI::Parser.new do
      usage_banner <<~EOS
        `pr-automerge` [<options>]

        Find pull requests that can be automatically merged using `brew pr-publish`.
      EOS
      flag   "--tap=",
             description: "Target tap repository (default: `homebrew/core`)."
      flag   "--with-label=",
             description: "Pull requests must have this label."
      comma_array "--without-labels=",
                  description: "Pull requests must not have these labels (default: `do not merge`, `new formula`)."
      switch "--without-approval",
             description: "Pull requests do not require approval to be merged."
      switch "--publish",
             description: "Run `brew pr-publish` on matching pull requests."
      switch "--ignore-failures",
             description: "Include pull requests that have failing status checks."
      switch :verbose
      switch :debug
      max_named 0
    end
  end

  def pr_automerge
    pr_automerge_args.parse

    without_labels = Homebrew.args.without_labels || ["do not merge", "new formula"]
    tap = Tap.fetch(Homebrew.args.tap || CoreTap.instance.name)

    query = "is:pr is:open repo:#{tap.full_name}"
    query += Homebrew.args.ignore_failures? ? " -status:pending" : " status:success"
    query += " review:approved" unless Homebrew.args.without_approval?
    query += " label:\"#{with_label}\"" if Homebrew.args.with_label
    without_labels&.each { |label| query += " -label:\"#{label}\"" }
    odebug "Searching: #{query}"

    prs = GitHub.search_issues query
    if prs.blank?
      ohai "No matching pull requests!"
      return
    end

    ohai "#{prs.size} matching pull requests:"
    pr_urls = []
    prs.each do |pr|
      puts "#{tap.full_name unless tap.core_tap?}##{pr["number"]}: #{pr["title"]}"
      pr_urls << pr["html_url"]
    end

    if args.publish?
      publish_args = ["pr-publish"]
      publish_args << "--tap=#{tap}" if tap
      safe_system HOMEBREW_BREW_FILE, *publish_args, *pr_urls
    else
      ohai "Now run:", "  brew pr-publish \\\n    #{pr_urls.join " \\\n    "}"
    end
  end
end
{'fraction_non_alphanumeric': 0.1292147052425495, 'fraction_numerical': 0.00043506634761801175, 'mean_word_length': 2.7020933977455717, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3734235', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1397, 'n_words': 389}