From 4bb66c12e8afa79d838fd9f0b4c86021050c33eb Mon Sep 17 00:00:00 2001 From: Jonathan Chang Date: Sun, 22 Mar 2020 13:12:06 +1100 Subject: [PATCH 1/3] utils/github: add repository_dispatch API --- Library/Homebrew/utils/github.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 4e0e42e9eb..7c3b36d284 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -431,6 +431,13 @@ module GitHub comments.any? { |comment| comment["body"].eql?(body) } end + def dispatch(user, repo, event, **payload) + url = "#{API_URL}/repos/#{user}/#{repo}/dispatches" + open_api(url, data: { event_type: event, client_payload: payload }, + request_method: :POST, + scopes: CREATE_ISSUE_FORK_OR_PR_SCOPES) + end + def api_errors [GitHub::AuthenticationFailedError, GitHub::HTTPNotFoundError, GitHub::RateLimitExceededError, GitHub::Error, JSON::ParserError].freeze From 86f245effb8746edae1655ece5038bd8cfaaf908 Mon Sep 17 00:00:00 2001 From: Jonathan Chang Date: Sun, 22 Mar 2020 13:12:48 +1100 Subject: [PATCH 2/3] dev-cmd: new pr-publish command --- Library/Homebrew/dev-cmd/pr-publish.rb | 36 +++++++++++++++++++ .../Homebrew/test/dev-cmd/pr-publish_spec.rb | 7 ++++ 2 files changed, 43 insertions(+) create mode 100644 Library/Homebrew/dev-cmd/pr-publish.rb create mode 100644 Library/Homebrew/test/dev-cmd/pr-publish_spec.rb diff --git a/Library/Homebrew/dev-cmd/pr-publish.rb b/Library/Homebrew/dev-cmd/pr-publish.rb new file mode 100644 index 0000000000..c2a81d9e9e --- /dev/null +++ b/Library/Homebrew/dev-cmd/pr-publish.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require "cli/parser" +require "utils/github" + +module Homebrew + module_function + + def pr_publish_args + Homebrew::CLI::Parser.new do + usage_banner <<~EOS + `pr-publish` + + Publishes bottles for a pull request with GitHub Actions. + Requires write access to the repository. + EOS + switch :verbose + end + end + + def pr_publish + pr_publish_args.parse + + odie "You need to specify a pull request number!" if Homebrew.args.named.empty? + + args.named.each do |arg| + arg = "#{CoreTap.instance.default_remote}/pull/#{arg}" if arg.to_i.positive? + url_match = arg.match HOMEBREW_PULL_OR_COMMIT_URL_REGEX + _, user, repo, issue = *url_match + tap = Tap.fetch(user, repo) if repo.match?(HOMEBREW_OFFICIAL_REPO_PREFIXES_REGEX) + odie "Not a GitHub pull request: #{arg}" unless issue + ohai "Dispatching #{tap} pull request ##{issue}" + GitHub.dispatch(user, repo, "Publish ##{issue}", pull_request: issue) + end + end +end diff --git a/Library/Homebrew/test/dev-cmd/pr-publish_spec.rb b/Library/Homebrew/test/dev-cmd/pr-publish_spec.rb new file mode 100644 index 0000000000..f0b8e25cd6 --- /dev/null +++ b/Library/Homebrew/test/dev-cmd/pr-publish_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require "cmd/shared_examples/args_parse" + +describe "Homebrew.pr_publish_args" do + it_behaves_like "parseable arguments" +end From e08ffb351525087f2d1e34e848785927c75fc344 Mon Sep 17 00:00:00 2001 From: Jonathan Chang Date: Sun, 22 Mar 2020 13:34:48 +1100 Subject: [PATCH 3/3] manpages: update for brew pr-publish --- docs/Manpage.md | 5 +++++ manpages/brew.1 | 3 +++ 2 files changed, 8 insertions(+) diff --git a/docs/Manpage.md b/docs/Manpage.md index 8d41ee6b33..4c7c6f89b3 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -880,6 +880,11 @@ Generate Homebrew's manpages. * `--link`: This is now done automatically by `brew update`. +### `pr-publish` *`pull_request`* + +Publishes bottles for a pull request with GitHub Actions. Requires write access +to the repository. + ### `prof` *`command`* Run Homebrew with the Ruby profiler, e.g. `brew prof readall`. diff --git a/manpages/brew.1 b/manpages/brew.1 index bfd405ff00..f286c8d09d 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1120,6 +1120,9 @@ Return a failing status code if changes are detected in the manpage outputs\. Th \fB\-\-link\fR This is now done automatically by \fBbrew update\fR\. . +.SS "\fBpr\-publish\fR \fIpull_request\fR" +Publishes bottles for a pull request with GitHub Actions\. Requires write access to the repository\. +. .SS "\fBprof\fR \fIcommand\fR" Run Homebrew with the Ruby profiler, e\.g\. \fBbrew prof readall\fR\. .