| 
									
										
										
										
											2020-03-22 13:12:48 +11:00
										 |  |  | # 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 | 
					
						
							| 
									
										
										
										
											2020-04-12 12:05:50 +02:00
										 |  |  |         `pr-publish` [<options>] <pull_request> [<pull_request> ...] | 
					
						
							| 
									
										
										
										
											2020-03-22 13:12:48 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-18 12:13:43 -04:00
										 |  |  |         Publish bottles for a pull request with GitHub Actions. | 
					
						
							| 
									
										
										
										
											2020-07-02 22:47:45 +02:00
										 |  |  |         Requires write access to the repository. | 
					
						
							| 
									
										
										
										
											2020-03-22 13:12:48 +11:00
										 |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2020-07-02 22:47:45 +02:00
										 |  |  |       flag   "--tap=", | 
					
						
							|  |  |  |              description: "Target tap repository (default: `homebrew/core`)." | 
					
						
							| 
									
										
										
										
											2020-07-28 11:29:09 +02:00
										 |  |  |       flag   "--workflow=", | 
					
						
							|  |  |  |              description: "Target workflow filename (default: `publish-commit-bottles.yml`)." | 
					
						
							| 
									
										
										
										
											2020-03-22 13:12:48 +11:00
										 |  |  |       switch :verbose | 
					
						
							| 
									
										
										
										
											2020-04-18 12:13:43 -04:00
										 |  |  |       min_named 1
 | 
					
						
							| 
									
										
										
										
											2020-03-22 13:12:48 +11:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def pr_publish | 
					
						
							|  |  |  |     pr_publish_args.parse | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-02 22:47:45 +02:00
										 |  |  |     tap = Tap.fetch(Homebrew.args.tap || CoreTap.instance.name) | 
					
						
							| 
									
										
										
										
											2020-07-28 11:29:09 +02:00
										 |  |  |     workflow = Homebrew.args.workflow || "publish-commit-bottles.yml" | 
					
						
							|  |  |  |     ref = "master" | 
					
						
							| 
									
										
										
										
											2020-03-31 10:02:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-12 12:05:50 +02:00
										 |  |  |     args.named.uniq.each do |arg| | 
					
						
							| 
									
										
										
										
											2020-07-02 22:47:45 +02:00
										 |  |  |       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 | 
					
						
							| 
									
										
										
										
											2020-07-27 12:29:08 +02:00
										 |  |  |       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}" | 
					
						
							| 
									
										
										
										
											2020-07-28 11:29:09 +02:00
										 |  |  |       GitHub.workflow_dispatch_event(user, repo, workflow, ref, pull_request: issue) | 
					
						
							| 
									
										
										
										
											2020-03-22 13:12:48 +11:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |