aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorBaptiste Fontaine2016-03-13 01:40:00 +0100
committerXu Cheng2016-03-14 19:39:15 +0800
commit236a18debe51e815f2d81a43d2151c500555abf9 (patch)
treeec6b164bfba5ea718d818f8bf1ed8848bc6258d2 /Library
parent1e1184fc2d7bae278b2806ddda296e26dcc9fe97 (diff)
downloadbrew-236a18debe51e815f2d81a43d2151c500555abf9.tar.bz2
audit: fix crash when HOMEBREW_NO_GITHUB_API is set
Running brew audit --strict --online on a formula with a GitHub homepage/url would crash if HOMEBREW_NO_GITHUB_API is set because GitHub.repository returns `nil` and the audit code assumes it always returns a hash. Closes Homebrew/homebrew#50054. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/audit.rb2
-rw-r--r--Library/Homebrew/test/test_cmd_audit.rb17
2 files changed, 19 insertions, 0 deletions
diff --git a/Library/Homebrew/cmd/audit.rb b/Library/Homebrew/cmd/audit.rb
index 9eec5590f..76702a967 100644
--- a/Library/Homebrew/cmd/audit.rb
+++ b/Library/Homebrew/cmd/audit.rb
@@ -509,6 +509,8 @@ class FormulaAuditor
return
end
+ return if metadata.nil?
+
problem "GitHub fork (not canonical repository)" if metadata["fork"]
if (metadata["forks_count"] < 20) && (metadata["subscribers_count"] < 20) &&
(metadata["stargazers_count"] < 50)
diff --git a/Library/Homebrew/test/test_cmd_audit.rb b/Library/Homebrew/test/test_cmd_audit.rb
index d030624ed..1f35e33b5 100644
--- a/Library/Homebrew/test/test_cmd_audit.rb
+++ b/Library/Homebrew/test/test_cmd_audit.rb
@@ -340,4 +340,21 @@ class FormulaAuditorTests < Homebrew::TestCase
assert_equal "Please remove default template comments",
fa.problems.shift
end
+
+ def test_audit_github_repository_no_api
+ fa = formula_auditor "foo", <<-EOS.undent, :strict => true, :online => true
+ class Foo < Formula
+ homepage "https://github.com/example/example"
+ url "http://example.com/foo-1.0.tgz"
+ end
+ EOS
+
+ original_value = ENV["HOMEBREW_NO_GITHUB_API"]
+ ENV["HOMEBREW_NO_GITHUB_API"] = "1"
+
+ fa.audit_github_repository
+ assert_equal [], fa.problems
+ ensure
+ ENV["HOMEBREW_NO_GITHUB_API"] = original_value
+ end
end