brew/Library/Homebrew/dev-cmd/pr-publish.rb

62 lines
2.0 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: false
2020-03-22 13:12:48 +11:00
# frozen_string_literal: true
require "cli/parser"
require "utils/github"
module Homebrew
2020-10-20 12:03:48 +02:00
extend T::Sig
2020-03-22 13:12:48 +11:00
module_function
2020-10-20 12:03:48 +02:00
sig { returns(CLI::Parser) }
2020-03-22 13:12:48 +11:00
def pr_publish_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`pr-publish` [<options>] <pull_request> [<pull_request> ...]
2020-03-22 13:12:48 +11:00
Publish bottles for a pull request with GitHub Actions.
Requires write access to the repository.
2020-03-22 13:12:48 +11:00
EOS
switch "--autosquash",
description: "If supported on the target tap, automatically reformat and reword commits "\
"in the pull request to our preferred format."
flag "--message=",
depends_on: "--autosquash",
description: "Message to include when autosquashing revision bumps, deletions, and rebuilds."
flag "--tap=",
description: "Target tap repository (default: `homebrew/core`)."
flag "--workflow=",
description: "Target workflow filename (default: `publish-commit-bottles.yml`)."
2020-07-30 18:40:10 +02:00
named_args min: 1
2020-03-22 13:12:48 +11:00
end
end
def pr_publish
2020-07-30 18:40:10 +02:00
args = pr_publish_args.parse
2020-03-22 13:12:48 +11:00
tap = Tap.fetch(args.tap || CoreTap.instance.name)
workflow = args.workflow || "publish-commit-bottles.yml"
ref = "master"
2020-03-31 10:02:29 +02:00
extra_args = []
extra_args << "--autosquash" if args.autosquash?
extra_args << "--message='#{args.message}'" if args.message.presence
dispatch_args = extra_args.join " "
args.named.uniq.each do |arg|
arg = "#{tap.default_remote}/pull/#{arg}" if arg.to_i.positive?
2020-03-22 13:12:48 +11:00
url_match = arg.match HOMEBREW_PULL_OR_COMMIT_URL_REGEX
_, user, repo, issue = *url_match
odie "Not a GitHub pull request: #{arg}" unless issue
if args.tap.present? && !"#{user}/#{repo}".casecmp(tap.full_name).zero?
odie "Pull request URL is for #{user}/#{repo} but --tap=#{tap.full_name}!"
end
2020-03-22 13:12:48 +11:00
ohai "Dispatching #{tap} pull request ##{issue}"
GitHub.workflow_dispatch_event(user, repo, workflow, ref, pull_request: issue, args: dispatch_args)
2020-03-22 13:12:48 +11:00
end
end
end