Merge pull request #7344 from jonchang/pr-automerge
dev-cmd: add pr-automerge
This commit is contained in:
		
						commit
						ac5ea023cf
					
				
							
								
								
									
										63
									
								
								Library/Homebrew/dev-cmd/pr-automerge.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								Library/Homebrew/dev-cmd/pr-automerge.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,63 @@
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
require "cli/parser"
 | 
			
		||||
require "utils/github"
 | 
			
		||||
 | 
			
		||||
module Homebrew
 | 
			
		||||
  module_function
 | 
			
		||||
 | 
			
		||||
  def pr_automerge_args
 | 
			
		||||
    Homebrew::CLI::Parser.new do
 | 
			
		||||
      usage_banner <<~EOS
 | 
			
		||||
        `pr-automerge` [<options>]
 | 
			
		||||
 | 
			
		||||
        Finds pull requests that can be automatically merged using `brew pr-publish`.
 | 
			
		||||
      EOS
 | 
			
		||||
      flag "--tap=",
 | 
			
		||||
           description: "Target repository tap (default: `homebrew/core`)"
 | 
			
		||||
      flag "--with-label=",
 | 
			
		||||
           description: "Pull requests must have this label (default: `ready to merge`)"
 | 
			
		||||
      flag "--without-label=",
 | 
			
		||||
           description: "Pull requests must not have this label (default: `do not merge`)"
 | 
			
		||||
      switch "--publish",
 | 
			
		||||
             description: "Run `brew pr-publish` on matching pull requests."
 | 
			
		||||
      switch "--ignore-failures",
 | 
			
		||||
             description: "Include pull requests that have failing status checks."
 | 
			
		||||
      switch :debug
 | 
			
		||||
      switch :verbose
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def pr_automerge
 | 
			
		||||
    pr_automerge_args.parse
 | 
			
		||||
 | 
			
		||||
    ENV["HOMEBREW_FORCE_HOMEBREW_ON_LINUX"] = "1" unless OS.mac?
 | 
			
		||||
    with_label = Homebrew.args.with_label || "ready to merge"
 | 
			
		||||
    without_label = Homebrew.args.without_label || "do not merge"
 | 
			
		||||
    tap = Tap.fetch(Homebrew.args.tap || CoreTap.instance.name)
 | 
			
		||||
 | 
			
		||||
    query = "is:pr is:open repo:#{tap.full_name} label:\"#{with_label}\" -label:\"#{without_label}\""
 | 
			
		||||
    query += args.ignore_failures? ? " -status:pending" : " status:success"
 | 
			
		||||
    odebug "Searching: #{query}"
 | 
			
		||||
 | 
			
		||||
    prs = GitHub.search_issues query
 | 
			
		||||
    if prs.blank?
 | 
			
		||||
      ohai "No matching pull requests!"
 | 
			
		||||
      return
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    ohai "#{prs.size} matching pull requests:"
 | 
			
		||||
    pr_urls = []
 | 
			
		||||
    prs.each do |pr|
 | 
			
		||||
      puts "#{tap.full_name unless tap.core_tap?}##{pr["number"]}: #{pr["title"]}"
 | 
			
		||||
      pr_urls << pr["html_url"]
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    if args.publish?
 | 
			
		||||
      safe_system "#{HOMEBREW_PREFIX}/bin/brew", "pr-publish", *pr_urls
 | 
			
		||||
    else
 | 
			
		||||
      ohai "Now run:"
 | 
			
		||||
      puts "  brew pr-publish \\\n    #{pr_urls.join " \\\n    "}"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										7
									
								
								Library/Homebrew/test/dev-cmd/pr-automerge_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								Library/Homebrew/test/dev-cmd/pr-automerge_spec.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
require "cmd/shared_examples/args_parse"
 | 
			
		||||
 | 
			
		||||
describe "Homebrew.pr_automerge_args" do
 | 
			
		||||
  it_behaves_like "parseable arguments"
 | 
			
		||||
end
 | 
			
		||||
@ -884,6 +884,21 @@ Generate Homebrew's manpages.
 | 
			
		||||
* `--link`:
 | 
			
		||||
  This is now done automatically by `brew update`.
 | 
			
		||||
 | 
			
		||||
### `pr-automerge` [*`options`*]
 | 
			
		||||
 | 
			
		||||
Finds pull requests that can be automatically merged using `brew pr-publish`.
 | 
			
		||||
 | 
			
		||||
* `--tap`:
 | 
			
		||||
  Target repository tap (default: `homebrew/core`)
 | 
			
		||||
* `--with-label`:
 | 
			
		||||
  Pull requests must have this label (default: `ready to merge`)
 | 
			
		||||
* `--without-label`:
 | 
			
		||||
  Pull requests must not have this label (default: `do not merge`)
 | 
			
		||||
* `--publish`:
 | 
			
		||||
  Run `brew pr-publish` on matching pull requests.
 | 
			
		||||
* `--ignore-failures`:
 | 
			
		||||
  Include pull requests that have failing status checks.
 | 
			
		||||
 | 
			
		||||
### `pr-publish` [*`options`*] *`pull_request`* [*`pull_request`* ...]
 | 
			
		||||
 | 
			
		||||
Publishes bottles for a pull request with GitHub Actions. Requires write access
 | 
			
		||||
 | 
			
		||||
@ -1128,6 +1128,29 @@ 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\-automerge\fR [\fIoptions\fR]"
 | 
			
		||||
Finds pull requests that can be automatically merged using \fBbrew pr\-publish\fR\.
 | 
			
		||||
.
 | 
			
		||||
.TP
 | 
			
		||||
\fB\-\-tap\fR
 | 
			
		||||
Target repository tap (default: \fBhomebrew/core\fR)
 | 
			
		||||
.
 | 
			
		||||
.TP
 | 
			
		||||
\fB\-\-with\-label\fR
 | 
			
		||||
Pull requests must have this label (default: \fBready to merge\fR)
 | 
			
		||||
.
 | 
			
		||||
.TP
 | 
			
		||||
\fB\-\-without\-label\fR
 | 
			
		||||
Pull requests must not have this label (default: \fBdo not merge\fR)
 | 
			
		||||
.
 | 
			
		||||
.TP
 | 
			
		||||
\fB\-\-publish\fR
 | 
			
		||||
Run \fBbrew pr\-publish\fR on matching pull requests\.
 | 
			
		||||
.
 | 
			
		||||
.TP
 | 
			
		||||
\fB\-\-ignore\-failures\fR
 | 
			
		||||
Include pull requests that have failing status checks\.
 | 
			
		||||
.
 | 
			
		||||
.SS "\fBpr\-publish\fR [\fIoptions\fR] \fIpull_request\fR [\fIpull_request\fR \.\.\.]"
 | 
			
		||||
Publishes bottles for a pull request with GitHub Actions\. Requires write access to the repository\.
 | 
			
		||||
.
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user