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

livecheck: reference Formula URLs #7668

Merged
merged 1 commit into from May 31, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/formula.rb
Expand Up @@ -2670,7 +2670,7 @@ def test(&block)
# regex /foo-(\d+(?:\.\d+)+)\.tar/
# end</pre>
def livecheck(&block)
@livecheck ||= Livecheck.new
@livecheck ||= Livecheck.new(self)
return @livecheck unless block_given?

@livecheckable = true
Expand Down
12 changes: 10 additions & 2 deletions Library/Homebrew/livecheck.rb
Expand Up @@ -10,7 +10,8 @@ class Livecheck
# e.g. `Not maintained`
attr_reader :skip_msg

def initialize
def initialize(formula)
@formula = formula
@regex = nil
@skip = false
@skip_msg = nil
Expand Down Expand Up @@ -44,7 +45,14 @@ def skip?
def url(val = nil)
return @url if val.nil?

@url = val
@url = case val
when :head, :stable, :devel
@formula.send(val).url
when :homepage
@formula.homepage
else
val
end
end

# Returns a Hash of all instance variable values.
Expand Down
14 changes: 14 additions & 0 deletions Library/Homebrew/test/formula_spec.rb
Expand Up @@ -697,6 +697,20 @@

expect(f.livecheckable?).to be true
end

specify "livecheck references Formula URL" do
f = formula do
homepage "https://brew.sh/test"

url "https://brew.sh/test-1.0.tbz"
livecheck do
url :homepage
regex(/test-(\d+(?:.\d+)+).tbz/)
end
end

expect(f.livecheck.url).to eq("https://brew.sh/test")
end
end

specify "dependencies" do
Expand Down
8 changes: 7 additions & 1 deletion Library/Homebrew/test/livecheck_spec.rb
@@ -1,9 +1,15 @@
# frozen_string_literal: true

require "formula"
require "livecheck"

describe Livecheck do
subject(:livecheckable) { described_class.new }
let(:f) do
formula do
url "https://brew.sh/test-0.1.tbz"
end
end
let(:livecheckable) { described_class.new(f) }

describe "#regex" do
it "returns nil if unset" do
Expand Down