Merge pull request #8662 from SeekingMeaning/audit/cask-prerelease
cask/audit: detect tag from URL
This commit is contained in:
		
						commit
						27dcba9f66
					
				@ -468,8 +468,9 @@ module Cask
 | 
			
		||||
      user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*}) if @online
 | 
			
		||||
      return if user.nil?
 | 
			
		||||
 | 
			
		||||
      # TODO: Detect tag from URL instead of using `cask.version`.
 | 
			
		||||
      error = SharedAudits.github_release(user, repo, cask.version, cask: cask)
 | 
			
		||||
      tag = SharedAudits.github_tag_from_url(cask.url)
 | 
			
		||||
      tag ||= cask.version
 | 
			
		||||
      error = SharedAudits.github_release(user, repo, tag, cask: cask)
 | 
			
		||||
      add_error error if error
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
@ -481,7 +482,9 @@ module Cask
 | 
			
		||||
 | 
			
		||||
      odebug "Auditing GitLab prerelease"
 | 
			
		||||
 | 
			
		||||
      error = SharedAudits.gitlab_release(user, repo, cask.version)
 | 
			
		||||
      tag = SharedAudits.gitlab_tag_from_url(cask.url)
 | 
			
		||||
      tag ||= cask.version
 | 
			
		||||
      error = SharedAudits.gitlab_release(user, repo, tag)
 | 
			
		||||
      add_error error if error
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -784,9 +784,7 @@ module Homebrew
 | 
			
		||||
        owner = Regexp.last_match(1)
 | 
			
		||||
        repo = Regexp.last_match(2)
 | 
			
		||||
 | 
			
		||||
        tag = url.match(%r{^https://gitlab\.com/[\w-]+/[\w-]+/-/archive/([^/]+)/})
 | 
			
		||||
                 .to_a
 | 
			
		||||
                 .second
 | 
			
		||||
        tag = SharedAudits.gitlab_tag_from_url(url)
 | 
			
		||||
        tag ||= stable.specs[:tag]
 | 
			
		||||
        tag ||= stable.version
 | 
			
		||||
 | 
			
		||||
@ -797,12 +795,7 @@ module Homebrew
 | 
			
		||||
      when %r{^https://github.com/([\w-]+)/([\w-]+)}
 | 
			
		||||
        owner = Regexp.last_match(1)
 | 
			
		||||
        repo = Regexp.last_match(2)
 | 
			
		||||
        tag = url.match(%r{^https://github\.com/[\w-]+/[\w-]+/archive/([^/]+)\.(tar\.gz|zip)$})
 | 
			
		||||
                 .to_a
 | 
			
		||||
                 .second
 | 
			
		||||
        tag ||= url.match(%r{^https://github\.com/[\w-]+/[\w-]+/releases/download/([^/]+)/})
 | 
			
		||||
                   .to_a
 | 
			
		||||
                   .second
 | 
			
		||||
        tag = SharedAudits.github_tag_from_url(url)
 | 
			
		||||
        tag ||= formula.stable.specs[:tag]
 | 
			
		||||
 | 
			
		||||
        if @online
 | 
			
		||||
 | 
			
		||||
@ -164,4 +164,22 @@ module SharedAudits
 | 
			
		||||
 | 
			
		||||
    "Bitbucket repository not notable enough (<30 forks and <75 watchers)"
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def github_tag_from_url(url)
 | 
			
		||||
    url = url.to_s
 | 
			
		||||
    tag = url.match(%r{^https://github\.com/[\w-]+/[\w-]+/archive/([^/]+)\.(tar\.gz|zip)$})
 | 
			
		||||
             .to_a
 | 
			
		||||
             .second
 | 
			
		||||
    tag ||= url.match(%r{^https://github\.com/[\w-]+/[\w-]+/releases/download/([^/]+)/})
 | 
			
		||||
               .to_a
 | 
			
		||||
               .second
 | 
			
		||||
    tag
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def gitlab_tag_from_url(url)
 | 
			
		||||
    url = url.to_s
 | 
			
		||||
    url.match(%r{^https://gitlab\.com/[\w-]+/[\w-]+/-/archive/([^/]+)/})
 | 
			
		||||
       .to_a
 | 
			
		||||
       .second
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user