Skip to content

Commit

Permalink
Merge pull request #18178 from cho-m/github-tag
Browse files Browse the repository at this point in the history
utils/shared_audits: GitHub urls can have '.' in repo and '/' in tag
  • Loading branch information
cho-m authored Aug 29, 2024
2 parents 81c4351 + d1dc3b2 commit 06fc224
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
22 changes: 22 additions & 0 deletions Library/Homebrew/test/utils/shared_audits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@
require "utils/shared_audits"

RSpec.describe SharedAudits do
describe "::github_tag_from_url" do
it "finds tags in archive urls" do
url = "https:/a/b/archive/refs/tags/v1.2.3.tar.gz"
expect(described_class.github_tag_from_url(url)).to eq("v1.2.3")
end

it "finds tags in release urls" do
url = "https:/a/b/releases/download/1.2.3/b-1.2.3.tar.bz2"
expect(described_class.github_tag_from_url(url)).to eq("1.2.3")
end

it "finds tags with slashes" do
url = "https:/a/b/archive/refs/tags/c/d/e/f/g-v1.2.3.tar.gz"
expect(described_class.github_tag_from_url(url)).to eq("c/d/e/f/g-v1.2.3")
end

it "finds tags in orgs/repos with special characters" do
url = "https:/a-b/c-d_e.f/archive/refs/tags/2.5.tar.gz"
expect(described_class.github_tag_from_url(url)).to eq("2.5")
end
end

describe "::gitlab_tag_from_url" do
it "doesn't find tags in invalid urls" do
url = "https://gitlab.com/a/-/archive/v1.2.3/a-v1.2.3.tar.gz"
Expand Down
10 changes: 2 additions & 8 deletions Library/Homebrew/utils/shared_audits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,8 @@ def self.bitbucket(user, repo)

sig { params(url: String).returns(T.nilable(String)) }
def self.github_tag_from_url(url)
url = url.to_s
tag = url.match(%r{^https://github\.com/[\w-]+/[\w-]+/archive/refs/tags/([^/]+)\.(tar\.gz|zip)$})
.to_a
.second
tag ||= url.match(%r{^https://github\.com/[\w-]+/[\w-]+/releases/download/([^/]+)/})
.to_a
.second
tag
tag = url[%r{^https://github\.com/[\w-]+/[\w.-]+/archive/refs/tags/(.+)\.(tar\.gz|zip)$}, 1]
tag || url[%r{^https://github\.com/[\w-]+/[\w.-]+/releases/download/([^/]+)/}, 1]
end

sig { params(url: String).returns(T.nilable(String)) }
Expand Down

0 comments on commit 06fc224

Please sign in to comment.