cask-pr-local-check: improve with optparse (#82084)

This commit is contained in:
Vítor Galvão
2020-05-06 22:14:06 +01:00
committed by GitHub
parent 412aebf23e
commit 90f8246040
+22 -2
View File
@@ -1,12 +1,32 @@
#!/usr/bin/env ruby
require 'open-uri'
require 'json'
require 'open-uri'
require 'optparse'
require 'tmpdir'
# Options
ARGV.push('--help') if ARGV.empty?
OptionParser.new do |opt|
opt.banner = <<~BANNER
Run `brew cask` `audi` and `style` checks locally, from a pull request URL.
Useful when online CI is broken.
Usage:
#{File.basename($PROGRAM_NAME)} <pr url>
Options:
BANNER
opt.on('-h', '--help', 'Show this help.') do
puts opt
exit 0
end
end.parse!
pr_url = ARGV[0]
abort 'You need to give the script exactly one argument, the URL to a pull request from an official Homebrew Cask tap' if pr_url.nil?
abort 'URL is not from an official Homebrew Cask tap' if pr_url !~ %r{^https://github.com/Homebrew/homebrew-cask.*}
pr_api = pr_url.sub(%r{^https://github.com/([^/]+)/([^/]+)/pull/([^/]+).*}, 'https://api.github.com/repos/\1/\2/pulls/\3/files')