Merge pull request #18178 from cho-m/github-tag
utils/shared_audits: GitHub urls can have '.' in repo and '/' in tag
This commit is contained in:
		
						commit
						06fc2247c7
					
				@ -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://github.com/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://github.com/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://github.com/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://github.com/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"
 | 
			
		||||
 | 
			
		||||
@ -185,14 +185,8 @@ module SharedAudits
 | 
			
		||||
 | 
			
		||||
  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)) }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user