Port Homebrew::DevCmd::PrAutomerge
This commit is contained in:
parent
d15f99514c
commit
972e853ec0
@ -1,87 +1,86 @@
|
|||||||
# typed: true
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "abstract_command"
|
||||||
require "cli/parser"
|
require "cli/parser"
|
||||||
require "utils/github"
|
require "utils/github"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module DevCmd
|
||||||
|
class PrAutomerge < AbstractCommand
|
||||||
|
cmd_args 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`, " \
|
||||||
|
"`pre-release`, `CI-published-bottle-commits`)."
|
||||||
|
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 "--autosquash",
|
||||||
|
description: "Instruct `brew pr-publish` to automatically reformat and reword commits " \
|
||||||
|
"in the pull request to the preferred format."
|
||||||
|
switch "--no-autosquash",
|
||||||
|
description: "Instruct `brew pr-publish` to skip automatically reformatting and rewording commits " \
|
||||||
|
"in the pull request to the preferred format.",
|
||||||
|
disable: true, # odisabled: remove this switch with 4.3.0
|
||||||
|
hidden: true
|
||||||
|
switch "--ignore-failures",
|
||||||
|
description: "Include pull requests that have failing status checks."
|
||||||
|
|
||||||
sig { returns(CLI::Parser) }
|
named_args :none
|
||||||
def pr_automerge_args
|
end
|
||||||
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`, " \
|
|
||||||
"`pre-release`, `CI-published-bottle-commits`)."
|
|
||||||
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 "--autosquash",
|
|
||||||
description: "Instruct `brew pr-publish` to automatically reformat and reword commits " \
|
|
||||||
"in the pull request to the preferred format."
|
|
||||||
switch "--no-autosquash",
|
|
||||||
description: "Instruct `brew pr-publish` to skip automatically reformatting and rewording commits " \
|
|
||||||
"in the pull request to the preferred format.",
|
|
||||||
disable: true, # odisabled: remove this switch with 4.3.0
|
|
||||||
hidden: true
|
|
||||||
switch "--ignore-failures",
|
|
||||||
description: "Include pull requests that have failing status checks."
|
|
||||||
|
|
||||||
named_args :none
|
sig { override.void }
|
||||||
end
|
def run
|
||||||
end
|
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)
|
||||||
|
|
||||||
def pr_automerge
|
query = "is:pr is:open repo:#{tap.full_name} draft:false"
|
||||||
args = pr_automerge_args.parse
|
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}"
|
||||||
|
|
||||||
without_labels = args.without_labels || [
|
prs = GitHub.search_issues query
|
||||||
"do not merge",
|
if prs.blank?
|
||||||
"new formula",
|
ohai "No matching pull requests!"
|
||||||
"automerge-skip",
|
return
|
||||||
"pre-release",
|
end
|
||||||
"CI-published-bottle-commits",
|
|
||||||
]
|
|
||||||
tap = Tap.fetch(args.tap || CoreTap.instance.name)
|
|
||||||
|
|
||||||
query = "is:pr is:open repo:#{tap.full_name} draft:false"
|
ohai "#{prs.count} matching pull #{Utils.pluralize("request", prs.count)}:"
|
||||||
query += args.ignore_failures? ? " -status:pending" : " status:success"
|
pr_urls = []
|
||||||
query += " review:approved" unless args.without_approval?
|
prs.each do |pr|
|
||||||
query += " label:\"#{args.with_label}\"" if args.with_label
|
puts "#{tap.full_name unless tap.core_tap?}##{pr["number"]}: #{pr["title"]}"
|
||||||
without_labels&.each { |label| query += " -label:\"#{label}\"" }
|
pr_urls << pr["html_url"]
|
||||||
odebug "Searching: #{query}"
|
end
|
||||||
|
|
||||||
prs = GitHub.search_issues query
|
publish_args = ["pr-publish"]
|
||||||
if prs.blank?
|
publish_args << "--tap=#{tap}" if tap
|
||||||
ohai "No matching pull requests!"
|
publish_args << "--workflow=#{args.workflow}" if args.workflow
|
||||||
return
|
publish_args << "--autosquash" if args.autosquash?
|
||||||
end
|
if args.publish?
|
||||||
|
safe_system HOMEBREW_BREW_FILE, *publish_args, *pr_urls
|
||||||
ohai "#{prs.count} matching pull #{Utils.pluralize("request", prs.count)}:"
|
else
|
||||||
pr_urls = []
|
ohai "Now run:", " brew #{publish_args.join " "} \\\n #{pr_urls.join " \\\n "}"
|
||||||
prs.each do |pr|
|
end
|
||||||
puts "#{tap.full_name unless tap.core_tap?}##{pr["number"]}: #{pr["title"]}"
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "cmd/shared_examples/args_parse"
|
require "cmd/shared_examples/args_parse"
|
||||||
|
require "dev-cmd/pr-automerge"
|
||||||
|
|
||||||
RSpec.describe "brew pr-automerge" do
|
RSpec.describe Homebrew::DevCmd::PrAutomerge do
|
||||||
it_behaves_like "parseable arguments"
|
it_behaves_like "parseable arguments"
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user