Skip to content

Commit

Permalink
Merge pull request #18783 from bevanjkay/generate-cask-ci-matrix-fix
Browse files Browse the repository at this point in the history
generate-cask-ci-matrix: fix incorrect error being raised
  • Loading branch information
MikeMcQuaid authored Nov 18, 2024
2 parents cc0b5d6 + 597f5fa commit 7de8d2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
26 changes: 9 additions & 17 deletions Library/Homebrew/dev-cmd/generate-cask-ci-matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,24 @@ class GenerateCaskCiMatrix < AbstractCommand
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?
new_cask = args.new?
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
[]
Expand Down Expand Up @@ -225,7 +219,7 @@ def runners(cask_content:)
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]) - (
Expand Down Expand Up @@ -310,10 +304,8 @@ def generate_matrix(tap, labels: [], cask_names: [], skip_install: false, new_ca
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}"
Expand Down
10 changes: 0 additions & 10 deletions Library/Homebrew/test/dev-cmd/generate-cask-ci-matrix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,5 @@
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

0 comments on commit 7de8d2d

Please sign in to comment.