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

Sparkle: Surface more Item values #16158

Merged
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
32 changes: 23 additions & 9 deletions Library/Homebrew/livecheck/strategy/sparkle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,21 @@ def self.match?(url)
# @api public
:title,
# @api public
:link,
# @api public
:channel,
# @api private
# @api public
:release_notes_link,
# @api public
:pub_date,
# @api public
:os,
# @api public
:url,
# @api private
:bundle_version,
# @api public
:minimum_system_version,
keyword_init: true,
) do
extend Forwardable
Expand Down Expand Up @@ -84,12 +92,14 @@ def self.items_from_content(content)
os = enclosure["os"]
end

channel = item.elements["channel"]&.text
url ||= item.elements["link"]&.text
title = item.elements["title"]&.text&.strip
link = item.elements["link"]&.text&.strip
url ||= link
channel = item.elements["channel"]&.text&.strip
release_notes_link = item.elements["releaseNotesLink"]&.text&.strip
short_version ||= item.elements["shortVersionString"]&.text&.strip
version ||= item.elements["version"]&.text&.strip

title = item.elements["title"]&.text&.strip
pub_date = item.elements["pubDate"]&.text&.strip&.presence&.then do |date_string|
Time.parse(date_string)
rescue ArgumentError
Expand Down Expand Up @@ -117,11 +127,15 @@ def self.items_from_content(content)
end

data = {
title: title,
channel: channel,
pub_date: pub_date,
url: url,
bundle_version: bundle_version,
title: title,
link: link,
channel: channel,
release_notes_link: release_notes_link,
pub_date: pub_date,
os: os,
url: url,
bundle_version: bundle_version,
minimum_system_version: minimum_system_version,
}.compact
next if data.empty?

Expand Down
135 changes: 82 additions & 53 deletions Library/Homebrew/test/livecheck/strategy/sparkle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,42 @@ def create_appcast_xml(items_str = "")
let(:item_hashes) do
{
v123: {
title: "Version 1.2.3",
pub_date: "Fri, 01 Jan 2021 01:23:45 +0000",
url: "https://www.example.com/example/example-1.2.3.tar.gz",
short_version: "1.2.3",
version: "123",
title: "Version 1.2.3",
release_notes_link: "https://www.example.com/example/1.2.3.html",
pub_date: "Fri, 01 Jan 2021 01:23:45 +0000",
url: "https://www.example.com/example/example-1.2.3.tar.gz",
short_version: "1.2.3",
version: "123",
minimum_system_version: "10.10",
},
v122: {
title: "Version 1.2.2",
pub_date: "Not a parseable date string",
url: "https://www.example.com/example/example-1.2.2.tar.gz",
short_version: "1.2.2",
version: "122",
title: "Version 1.2.2",
release_notes_link: "https://www.example.com/example/1.2.2.html",
pub_date: "Not a parseable date string",
link: "https://www.example.com/example/example-1.2.2.tar.gz",
short_version: "1.2.2",
version: "122",
minimum_system_version: "10.10",
},
v121: {
title: "Version 1.2.1",
pub_date: "Thu, 31 Dec 2020 01:23:45 +0000",
url: "https://www.example.com/example/example-1.2.1.tar.gz",
short_version: "1.2.1",
version: "121",
title: "Version 1.2.1",
release_notes_link: "https://www.example.com/example/1.2.1.html",
pub_date: "Thu, 31 Dec 2020 01:23:45 +0000",
os: "osx",
url: "https://www.example.com/example/example-1.2.1.tar.gz",
short_version: "1.2.1",
version: "121",
minimum_system_version: "10.10",
},
v120: {
title: "Version 1.2.0",
pub_date: "Wed, 30 Dec 2020 01:23:45 +0000",
url: "https://www.example.com/example/example-1.2.0.tar.gz",
short_version: "1.2.0",
version: "120",
title: "Version 1.2.0",
release_notes_link: "https://www.example.com/example/1.2.0.html",
pub_date: "Wed, 30 Dec 2020 01:23:45 +0000",
os: "macos",
url: "https://www.example.com/example/example-1.2.0.tar.gz",
short_version: "1.2.0",
version: "120",
minimum_system_version: "10.10",
},
}
end
Expand All @@ -63,8 +73,8 @@ def create_appcast_xml(items_str = "")
v123_item = <<~EOS
<item>
<title>#{item_hashes[:v123][:title]}</title>
<sparkle:minimumSystemVersion>10.10</sparkle:minimumSystemVersion>
<sparkle:releaseNotesLink>https://www.example.com/example/#{item_hashes[:v123][:short_version]}.html</sparkle:releaseNotesLink>
<sparkle:minimumSystemVersion>#{item_hashes[:v123][:minimum_system_version]}</sparkle:minimumSystemVersion>
<sparkle:releaseNotesLink>#{item_hashes[:v123][:release_notes_link]}</sparkle:releaseNotesLink>
<pubDate>#{item_hashes[:v123][:pub_date]}</pubDate>
<enclosure url="#{item_hashes[:v123][:url]}" sparkle:shortVersionString="#{item_hashes[:v123][:short_version]}" sparkle:version="#{item_hashes[:v123][:version]}" length="12345678" type="application/octet-stream" sparkle:dsaSignature="ABCDEF+GHIJKLMNOPQRSTUVWXYZab/cdefghijklmnopqrst/uvwxyz1234567==" />
</item>
Expand All @@ -73,32 +83,32 @@ def create_appcast_xml(items_str = "")
v122_item = <<~EOS
<item>
<title>#{item_hashes[:v122][:title]}</title>
<sparkle:minimumSystemVersion>10.10</sparkle:minimumSystemVersion>
<sparkle:releaseNotesLink>https://www.example.com/example/#{item_hashes[:v122][:short_version]}.html</sparkle:releaseNotesLink>
<link>#{item_hashes[:v122][:link]}</link>
<sparkle:minimumSystemVersion>#{item_hashes[:v122][:minimum_system_version]}</sparkle:minimumSystemVersion>
<sparkle:releaseNotesLink>#{item_hashes[:v122][:release_notes_link]}</sparkle:releaseNotesLink>
<pubDate>#{item_hashes[:v122][:pub_date]}</pubDate>
<sparkle:version>#{item_hashes[:v122][:version]}</sparkle:version>
<sparkle:shortVersionString>#{item_hashes[:v122][:short_version]}</sparkle:shortVersionString>
<link>#{item_hashes[:v122][:url]}</link>
</item>
EOS

v121_item_with_osx_os = <<~EOS
<item>
<title>#{item_hashes[:v121][:title]}</title>
<sparkle:minimumSystemVersion>10.10</sparkle:minimumSystemVersion>
<sparkle:releaseNotesLink>https://www.example.com/example/#{item_hashes[:v121][:short_version]}.html</sparkle:releaseNotesLink>
<sparkle:minimumSystemVersion>#{item_hashes[:v121][:minimum_system_version]}</sparkle:minimumSystemVersion>
<sparkle:releaseNotesLink>#{item_hashes[:v121][:release_notes_link]}</sparkle:releaseNotesLink>
<pubDate>#{item_hashes[:v121][:pub_date]}</pubDate>
<enclosure os="osx" url="#{item_hashes[:v121][:url]}" sparkle:shortVersionString="#{item_hashes[:v121][:short_version]}" sparkle:version="#{item_hashes[:v121][:version]}" length="12345678" type="application/octet-stream" sparkle:dsaSignature="ABCDEF+GHIJKLMNOPQRSTUVWXYZab/cdefghijklmnopqrst/uvwxyz1234567==" />
<enclosure os="#{item_hashes[:v121][:os]}" url="#{item_hashes[:v121][:url]}" sparkle:shortVersionString="#{item_hashes[:v121][:short_version]}" sparkle:version="#{item_hashes[:v121][:version]}" length="12345678" type="application/octet-stream" sparkle:dsaSignature="ABCDEF+GHIJKLMNOPQRSTUVWXYZab/cdefghijklmnopqrst/uvwxyz1234567==" />
</item>
EOS

v120_item_with_macos_os = <<~EOS
<item>
<title>#{item_hashes[:v120][:title]}</title>
<sparkle:minimumSystemVersion>10.10</sparkle:minimumSystemVersion>
<sparkle:releaseNotesLink>https://www.example.com/example/#{item_hashes[:v120][:short_version]}.html</sparkle:releaseNotesLink>
<sparkle:minimumSystemVersion>#{item_hashes[:v120][:minimum_system_version]}</sparkle:minimumSystemVersion>
<sparkle:releaseNotesLink>#{item_hashes[:v120][:release_notes_link]}</sparkle:releaseNotesLink>
<pubDate>#{item_hashes[:v120][:pub_date]}</pubDate>
<enclosure os="macos" url="#{item_hashes[:v120][:url]}" sparkle:shortVersionString="#{item_hashes[:v120][:short_version]}" sparkle:version="#{item_hashes[:v120][:version]}" length="12345678" type="application/octet-stream" sparkle:dsaSignature="ABCDEF+GHIJKLMNOPQRSTUVWXYZab/cdefghijklmnopqrst/uvwxyz1234567==" />
<enclosure os="#{item_hashes[:v120][:os]}" url="#{item_hashes[:v120][:url]}" sparkle:shortVersionString="#{item_hashes[:v120][:short_version]}" sparkle:version="#{item_hashes[:v120][:version]}" length="12345678" type="application/octet-stream" sparkle:dsaSignature="ABCDEF+GHIJKLMNOPQRSTUVWXYZab/cdefghijklmnopqrst/uvwxyz1234567==" />
</item>
EOS

Expand Down Expand Up @@ -131,8 +141,8 @@ def create_appcast_xml(items_str = "")
no_versions_item = create_appcast_xml <<~EOS
<item>
<title>Version</title>
<sparkle:minimumSystemVersion>10.10</sparkle:minimumSystemVersion>
<sparkle:releaseNotesLink>https://www.example.com/example/#{item_hashes[:v123][:short_version]}.html</sparkle:releaseNotesLink>
<sparkle:minimumSystemVersion>#{item_hashes[:v123][:minimum_system_version]}</sparkle:minimumSystemVersion>
<sparkle:releaseNotesLink>#{item_hashes[:v123][:release_notes_link]}</sparkle:releaseNotesLink>
<pubDate>#{item_hashes[:v123][:pub_date]}</pubDate>
<enclosure url="#{item_hashes[:v123][:url]}" length="12345678" type="application/octet-stream" sparkle:dsaSignature="ABCDEF+GHIJKLMNOPQRSTUVWXYZab/cdefghijklmnopqrst/uvwxyz1234567==" />
</item>
Expand All @@ -157,34 +167,53 @@ def create_appcast_xml(items_str = "")
let(:items) do
{
v123: Homebrew::Livecheck::Strategy::Sparkle::Item.new(
title: item_hashes[:v123][:title],
pub_date: Time.parse(item_hashes[:v123][:pub_date]),
url: item_hashes[:v123][:url],
bundle_version: Homebrew::BundleVersion.new(item_hashes[:v123][:short_version],
item_hashes[:v123][:version]),
title: item_hashes[:v123][:title],
release_notes_link: item_hashes[:v123][:release_notes_link],
pub_date: Time.parse(item_hashes[:v123][:pub_date]),
url: item_hashes[:v123][:url],
bundle_version: Homebrew::BundleVersion.new(
item_hashes[:v123][:short_version],
item_hashes[:v123][:version],
),
minimum_system_version: item_hashes[:v123][:minimum_system_version],
),
v122: Homebrew::Livecheck::Strategy::Sparkle::Item.new(
title: item_hashes[:v122][:title],
title: item_hashes[:v122][:title],
link: item_hashes[:v122][:link],
release_notes_link: item_hashes[:v122][:release_notes_link],
# `#items_from_content` falls back to a default `pub_date` when
# one isn't provided or can't be successfully parsed.
pub_date: Time.new(0),
url: item_hashes[:v122][:url],
bundle_version: Homebrew::BundleVersion.new(item_hashes[:v122][:short_version],
item_hashes[:v122][:version]),
pub_date: Time.new(0),
url: item_hashes[:v122][:link],
bundle_version: Homebrew::BundleVersion.new(
item_hashes[:v122][:short_version],
item_hashes[:v122][:version],
),
minimum_system_version: item_hashes[:v122][:minimum_system_version],
),
v121: Homebrew::Livecheck::Strategy::Sparkle::Item.new(
title: item_hashes[:v121][:title],
pub_date: Time.parse(item_hashes[:v121][:pub_date]),
url: item_hashes[:v121][:url],
bundle_version: Homebrew::BundleVersion.new(item_hashes[:v121][:short_version],
item_hashes[:v121][:version]),
title: item_hashes[:v121][:title],
release_notes_link: item_hashes[:v121][:release_notes_link],
pub_date: Time.parse(item_hashes[:v121][:pub_date]),
os: item_hashes[:v121][:os],
url: item_hashes[:v121][:url],
bundle_version: Homebrew::BundleVersion.new(
item_hashes[:v121][:short_version],
item_hashes[:v121][:version],
),
minimum_system_version: item_hashes[:v121][:minimum_system_version],
),
v120: Homebrew::Livecheck::Strategy::Sparkle::Item.new(
title: item_hashes[:v120][:title],
pub_date: Time.parse(item_hashes[:v120][:pub_date]),
url: item_hashes[:v120][:url],
bundle_version: Homebrew::BundleVersion.new(item_hashes[:v120][:short_version],
item_hashes[:v120][:version]),
title: item_hashes[:v120][:title],
release_notes_link: item_hashes[:v120][:release_notes_link],
pub_date: Time.parse(item_hashes[:v120][:pub_date]),
os: item_hashes[:v120][:os],
url: item_hashes[:v120][:url],
bundle_version: Homebrew::BundleVersion.new(
item_hashes[:v120][:short_version],
item_hashes[:v120][:version],
),
minimum_system_version: item_hashes[:v120][:minimum_system_version],
),
}
end
Expand Down