class LockDiff::Github::UrlDetector
Constants
- REGEXP
xxx.github.aaa/yyyy
Public Class Methods
new(urls)
click to toggle source
# File lib/lock_diff/github/url_detector.rb, line 9 def initialize(urls) @urls = Array(urls).compact end
Public Instance Methods
call()
click to toggle source
# File lib/lock_diff/github/url_detector.rb, line 13 def call url = @urls.find { |_url| _url.include?("github") } return unless url begin response = HTTPClient.get(url, follow_redirect: true) url = response.header.request_uri.to_s rescue repository = RepositoryNameDetector.new(url).call url = "https://github.com/#{repository}" end if url.match(REGEXP) _, owner, repo = url.match(REGEXP).to_a url = "https://github.com/#{owner}/#{repo}" HTTPClient.get(url).ok? ? url : nil else repository = RepositoryNameDetector.new(url).call "https://github.com/#{repository}" end rescue => e LockDiff.logger.warn("Could not detect github url by #{url} because of #{e.inspect}") nil end