Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate-cask-ci-matrix: fix incorrect error being raised #18783

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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)

Check warning on line 59 in Library/Homebrew/dev-cmd/generate-cask-ci-matrix.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/generate-cask-ci-matrix.rb#L59

Added line #L59 was not covered by tests
raise UsageError, "The GITHUB_REPOSITORY environment variable must be set." if repository.blank?

tap = T.let(Tap.fetch(repository), Tap)

Check warning on line 62 in Library/Homebrew/dev-cmd/generate-cask-ci-matrix.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/generate-cask-ci-matrix.rb#L62

Added line #L62 was not covered by tests

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 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)

Check warning on line 222 in Library/Homebrew/dev-cmd/generate-cask-ci-matrix.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/generate-cask-ci-matrix.rb#L222

Added line #L222 was not covered by tests

ruby_files_in_wrong_directory =
T.must(changed_files[:modified_ruby_files]) - (
Expand Down Expand Up @@ -310,10 +304,8 @@
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
Loading