module Gemdiff::RepoFinder

Constants

GITHUB_REPO_REGEX
REPO_EXCEPTIONS

rails builds several gems that are not individual projects some repos move and the old repo page still exists some repos are not mostly ruby so the github search doesn't find them

Public Class Methods

github_url(gem_name) click to toggle source

Try to get the homepage from the gemspec If not found, search github

# File lib/gemdiff/repo_finder.rb, line 95
def github_url(gem_name)
  gemspec_homepage(gem_name) || search(gem_name)
end

Private Class Methods

access_token() click to toggle source
# File lib/gemdiff/repo_finder.rb, line 129
def access_token
  ENV["GEMDIFF_GITHUB_TOKEN"] || ENV["GITHUB_TOKEN"]
end
clean_url(url) click to toggle source

return https URL with anchors stripped

# File lib/gemdiff/repo_finder.rb, line 114
def clean_url(url)
  url.sub(/\Ahttp:/, "https:").partition("#").first
end
find_local_gemspec(name) click to toggle source
# File lib/gemdiff/repo_finder.rb, line 143
def find_local_gemspec(name)
  `gem spec #{name}`
end
find_remote_gemspec(name) click to toggle source
# File lib/gemdiff/repo_finder.rb, line 147
def find_remote_gemspec(name)
  `gem spec -r #{name}`
end
gemspec(name) click to toggle source
# File lib/gemdiff/repo_finder.rb, line 137
def gemspec(name)
  yaml = find_local_gemspec(name)
  return yaml unless yaml.to_s.empty?
  find_remote_gemspec(name)
end
gemspec_homepage(gem_name) click to toggle source
# File lib/gemdiff/repo_finder.rb, line 101
def gemspec_homepage(gem_name)
  if (full_name = REPO_EXCEPTIONS[gem_name.to_sym])
    return github_repo(full_name)
  end
  yaml = gemspec(gem_name)
  return if yaml.to_s.empty?
  spec = YAML.load(yaml)
  return clean_url(spec.homepage) if spec.homepage =~ GITHUB_REPO_REGEX
  match = spec.description.to_s.match(GITHUB_REPO_REGEX)
  match && clean_url(match[0])
end
github_repo(full_name) click to toggle source
# File lib/gemdiff/repo_finder.rb, line 125
def github_repo(full_name)
  "https://github.com/#{full_name}"
end
octokit_client() click to toggle source
# File lib/gemdiff/repo_finder.rb, line 133
def octokit_client
  Octokit::Client.new(access_token: access_token)
end