generate-cask-ci-matrix: fix incorrect error raised

This commit is contained in:
Bevan Kay 2024-11-18 00:38:02 +11:00
parent cc0b5d6d05
commit 597f5fa018
No known key found for this signature in database
GPG Key ID: C55CB024B5314B57
2 changed files with 9 additions and 27 deletions

View File

@ -48,15 +48,6 @@ module Homebrew
hide_from_man_page!
end
sig { params(args: T::Array[String]).void }
def initialize(*args)
super
repository = ENV.fetch("GITHUB_REPOSITORY", "homebrew/homebrew-cask")
raise UsageError, "The GITHUB_REPOSITORY environment variable must be set." if repository.blank?
@tap = T.let(Tap.fetch(repository), Tap)
end
sig { override.void }
def run
skip_install = args.skip_install?
@ -64,14 +55,17 @@ module Homebrew
casks = args.named if args.casks?
pr_url = args.named if args.url?
syntax_only = args.syntax_only?
tap = @tap
repository = ENV.fetch("GITHUB_REPOSITORY", nil)
raise UsageError, "The GITHUB_REPOSITORY environment variable must be set." if repository.blank?
tap = T.let(Tap.fetch(repository), Tap)
raise UsageError, "Either `--cask` or `--url` must be specified." if casks.blank? && pr_url.blank?
raise UsageError, "Only one url can be specified" if pr_url&.count&.> 1
raise UsageError, "This command must be run from inside a tap directory." if Dir.pwd.to_s != tap.path.to_s
labels = if pr_url
pr = GitHub::API.open_rest(pr_url)
pr = GitHub::API.open_rest(pr_url.first)
pr.fetch("labels").map { |l| l.fetch("name") }
else
[]
@ -225,7 +219,7 @@ module Homebrew
def generate_matrix(tap, labels: [], cask_names: [], skip_install: false, new_cask: false)
odie "This command must be run from inside a tap directory." unless tap
changed_files = find_changed_files
changed_files = find_changed_files(tap)
ruby_files_in_wrong_directory =
T.must(changed_files[:modified_ruby_files]) - (
@ -310,10 +304,8 @@ module Homebrew
end
end
sig { returns(T::Hash[Symbol, T::Array[String]]) }
def find_changed_files
tap = @tap
sig { params(tap: Tap).returns(T::Hash[Symbol, T::Array[String]]) }
def find_changed_files(tap)
commit_range_start = Utils.safe_popen_read("git", "rev-parse", "origin").chomp
commit_range_end = Utils.safe_popen_read("git", "rev-parse", "HEAD").chomp
commit_range = "#{commit_range_start}...#{commit_range_end}"

View File

@ -4,15 +4,5 @@ require "cmd/shared_examples/args_parse"
require "dev-cmd/generate-cask-ci-matrix"
RSpec.describe Homebrew::DevCmd::GenerateCaskCiMatrix do
ENV["GITHUB_REPOSITORY"] = "homebrew/homebrew-cask"
it_behaves_like "parseable arguments"
it "fails when not from inside a tap directory", :integration_test do
expect do
brew "generate-cask-ci-matrix", "--cask", "google-chrome",
"GITHUB_REPOSITORY" => ENV.fetch("GITHUB_REPOSITORY")
end
.to output(/Error: Invalid usage: This command must be run from inside a tap directory./).to_stderr
end
end