Skip to content

Commit

Permalink
developer/bin/cask-pr-local-check: fix RuboCop style.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMcQuaid committed Jul 27, 2020
1 parent 1c81105 commit 154f406
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions developer/bin/cask-pr-local-check
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env ruby

require 'json'
require 'open-uri'
require 'optparse'
require 'tmpdir'
require "json"
require "open-uri"
require "optparse"
require "tmpdir"

# Options
ARGV.push('--help') if ARGV.empty?
ARGV.push("--help") if ARGV.empty?

OptionParser.new do |opt|
opt.banner = <<~BANNER
Expand All @@ -19,25 +19,28 @@ OptionParser.new do |opt|
Options:
BANNER

opt.on('-h', '--help', 'Show this help.') do
opt.on("-h", "--help", "Show this help.") do
puts opt
exit 0
end
end.parse!

pr_url = ARGV[0]

abort 'URL is not from an official Homebrew Cask tap' if pr_url !~ %r{^https://github.com/Homebrew/homebrew-cask.*}
unless %r{^https://github.com/Homebrew/homebrew-cask.*}.match?(pr_url)
abort "URL is not from an official Homebrew Cask tap"
end

pr_api = pr_url.sub(%r{^https://github.com/([^/]+)/([^/]+)/pull/([^/]+).*}, 'https://api.github.com/repos/\1/\2/pulls/\3/files')
pr_api = pr_url.sub(%r{^https://github.com/([^/]+)/([^/]+)/pull/([^/]+).*},
'https://api.github.com/repos/\1/\2/pulls/\3/files')
pr_json = JSON.parse(URI(pr_api).read)

abort 'PR needs to have a single file' if pr_json.count != 1
abort "PR needs to have a single file" if pr_json.count != 1

file_raw_url = pr_json[0]['raw_url']
file_raw_url = pr_json[0]["raw_url"]
file_name = File.basename(file_raw_url)
local_file = File.join(Dir.mktmpdir, file_name)

File.write(local_file, URI(file_raw_url).read)
system('brew', 'cask', 'audit', '--download', local_file)
system('brew', 'cask', 'style', local_file)
system("brew", "cask", "audit", "--download", local_file)
system("brew", "cask", "style", local_file)

0 comments on commit 154f406

Please sign in to comment.