2018-02-03 11:09:32 +00:00
|
|
|
#!/usr/bin/env ruby
|
2020-09-25 01:18:32 +02:00
|
|
|
# frozen_string_literal: true
|
2018-02-03 11:09:32 +00:00
|
|
|
|
2020-07-27 10:39:13 +01:00
|
|
|
require "json"
|
|
|
|
|
require "open-uri"
|
|
|
|
|
require "optparse"
|
|
|
|
|
require "tmpdir"
|
2018-02-03 11:09:32 +00:00
|
|
|
|
2020-05-06 22:14:06 +01:00
|
|
|
# Options
|
2020-07-27 10:39:13 +01:00
|
|
|
ARGV.push("--help") if ARGV.empty?
|
2020-05-06 22:14:06 +01:00
|
|
|
|
|
|
|
|
OptionParser.new do |opt|
|
|
|
|
|
opt.banner = <<~BANNER
|
2020-12-03 12:28:16 +08:00
|
|
|
Run `brew` `audit` and `style` checks locally, from a pull request URL.
|
2020-05-06 22:14:06 +01:00
|
|
|
Useful when online CI is broken.
|
|
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
|
#{File.basename($PROGRAM_NAME)} <pr url>
|
|
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
BANNER
|
|
|
|
|
|
2020-07-27 10:39:13 +01:00
|
|
|
opt.on("-h", "--help", "Show this help.") do
|
2020-05-06 22:14:06 +01:00
|
|
|
puts opt
|
|
|
|
|
exit 0
|
|
|
|
|
end
|
|
|
|
|
end.parse!
|
|
|
|
|
|
2018-02-03 11:09:32 +00:00
|
|
|
pr_url = ARGV[0]
|
|
|
|
|
|
2020-07-27 10:39:13 +01:00
|
|
|
unless %r{^https://github.com/Homebrew/homebrew-cask.*}.match?(pr_url)
|
|
|
|
|
abort "URL is not from an official Homebrew Cask tap"
|
|
|
|
|
end
|
2018-02-03 11:09:32 +00:00
|
|
|
|
2020-07-27 10:39:13 +01:00
|
|
|
pr_api = pr_url.sub(%r{^https://github.com/([^/]+)/([^/]+)/pull/([^/]+).*},
|
|
|
|
|
'https://api.github.com/repos/\1/\2/pulls/\3/files')
|
2020-02-22 13:44:37 +00:00
|
|
|
pr_json = JSON.parse(URI(pr_api).read)
|
2018-02-03 11:09:32 +00:00
|
|
|
|
2020-07-27 10:39:13 +01:00
|
|
|
abort "PR needs to have a single file" if pr_json.count != 1
|
2018-02-03 11:09:32 +00:00
|
|
|
|
2022-05-27 13:16:25 +10:00
|
|
|
file_raw_url = pr_json[0]["raw_url"].gsub("%2F", "/")
|
2018-02-03 11:09:32 +00:00
|
|
|
file_name = File.basename(file_raw_url)
|
2019-12-07 19:21:41 +00:00
|
|
|
local_file = File.join(Dir.mktmpdir, file_name)
|
2018-02-03 11:09:32 +00:00
|
|
|
|
2019-12-07 19:21:41 +00:00
|
|
|
File.write(local_file, URI(file_raw_url).read)
|
2023-12-05 20:27:54 +01:00
|
|
|
abort "Audit failed" unless system("brew", "audit", "--new", local_file)
|
2020-12-03 12:28:16 +08:00
|
|
|
abort "Style check failed" unless system("brew", "style", local_file)
|