class GemHadar

def github_remote_url

Returns:
  • (URI, nil) - The parsed GitHub remote URI or nil if not found.
def github_remote_url
  if remotes = `git remote -v`
    remotes_urls = remotes.scan(/^(\S+)\s+(\S+)\s+\(push\)/)
    remotes_uris = remotes_urls.map do |name, url|
      if %r(\A(?<scheme>[^@]+)@(?<hostname>[A-Za-z0-9.]+):(?:\d*)(?<path>.*)) =~ url
        path = ?/ + path unless path.start_with? ?/
        url = 'ssh://%s@%s%s' % [ scheme, hostname, path ] # approximate correct URIs
      end
      URI.parse(url)
    end
    remotes_uris.find { |uri| uri.hostname == 'github.com' }
  end
end