Class: Homebrew::DevCmd::PrAutomerge

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/pr-automerge.rb

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, #initialize, parser

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#runvoid

This method returns an undefined value.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'dev-cmd/pr-automerge.rb', line 43

def run
  without_labels = args.without_labels || [
    "do not merge",
    "new formula",
    "automerge-skip",
    "pre-release",
    "CI-published-bottle-commits",
  ]
  tap = Tap.fetch(args.tap || CoreTap.instance.name)

  query = "is:pr is:open repo:#{tap.full_name} draft:false"
  query += args.ignore_failures? ? " -status:pending" : " status:success"
  query += " review:approved" unless args.without_approval?
  query += " label:\"#{args.with_label}\"" if 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.count} matching pull #{Utils.pluralize("request", prs.count)}:"
  pr_urls = []
  prs.each do |pr|
    puts "#{tap.full_name unless tap.core_tap?}##{pr["number"]}: #{pr["title"]}"
    pr_urls << pr["html_url"]
  end

  publish_args = ["pr-publish"]
  publish_args << "--tap=#{tap}" if tap
  publish_args << "--workflow=#{args.workflow}" if args.workflow
  publish_args << "--autosquash" if args.autosquash?
  if args.publish?
    safe_system HOMEBREW_BREW_FILE, *publish_args, *pr_urls
  else
    ohai "Now run:", "  brew #{publish_args.join " "} \\\n    #{pr_urls.join " \\\n    "}"
  end
end