forked from Homebrew/brew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pr-automerge.rb
81 lines (70 loc) 路 2.75 KB
/
pr-automerge.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
# typed: false
# frozen_string_literal: true
require "cli/parser"
require "utils/github"
module Homebrew
extend T::Sig
module_function
sig { returns(CLI::Parser) }
def pr_automerge_args
Homebrew::CLI::Parser.new do
description <<~EOS
Find pull requests that can be automatically merged using `brew pr-publish`.
EOS
flag "--tap=",
description: "Target tap repository (default: `homebrew/core`)."
flag "--workflow=",
description: "Workflow file to use with `brew pr-publish`."
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`, `automerge-skip`)."
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 "--no-autosquash",
description: "Instruct `brew pr-publish` to skip automatically reformatting and rewording commits " \
"in the pull request to the preferred format."
switch "--ignore-failures",
description: "Include pull requests that have failing status checks."
named_args :none
end
end
def pr_automerge
args = pr_automerge_args.parse
without_labels = args.without_labels || [
"do not merge",
"new formula",
"automerge-skip",
]
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 << "--no-autosquash" if args.no_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
end