Merge pull request #7668 from nandahkrishna/livecheck-url-feature

livecheck: reference Formula URLs
This commit is contained in:
Mike McQuaid 2020-05-31 13:02:06 +01:00 committed by GitHub
commit a829fef52e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 4 deletions

View File

@ -2670,7 +2670,7 @@ class Formula
# regex /foo-(\d+(?:\.\d+)+)\.tar/
# end</pre>
def livecheck(&block)
@livecheck ||= Livecheck.new
@livecheck ||= Livecheck.new(self)
return @livecheck unless block_given?
@livecheckable = true

View File

@ -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
@ -44,7 +45,14 @@ class Livecheck
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.

View File

@ -697,6 +697,20 @@ describe Formula do
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

View File

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