class Unwrappr::Researchers::GithubComparison

Compares the old version to the new via the Github API: developer.github.com/v3/repos/commits/#compare-two-commits

Implements the `gem_researcher` interface required by the LockFileAnnotator.

Public Class Methods

new(client) click to toggle source
# File lib/unwrappr/researchers/github_comparison.rb, line 11
def initialize(client)
  @client = client
end

Public Instance Methods

research(gem_change, change_info) click to toggle source
# File lib/unwrappr/researchers/github_comparison.rb, line 15
def research(gem_change, change_info)
  return change_info if github_repo_not_identified?(change_info) ||
                        gem_added_or_removed?(gem_change)

  change_info.merge(
    github_comparison: try_comparing(
      repo: github_repo(change_info),
      base: gem_change.base_version,
      head: gem_change.head_version
    )
  )
end

Private Instance Methods

compare(repo, base, head) click to toggle source
# File lib/unwrappr/researchers/github_comparison.rb, line 36
def compare(repo, base, head)
  @client.compare(repo, base, head)
rescue Octokit::NotFound
  nil
end
gem_added_or_removed?(gem_change) click to toggle source
# File lib/unwrappr/researchers/github_comparison.rb, line 50
def gem_added_or_removed?(gem_change)
  gem_change.base_version.nil? || gem_change.head_version.nil?
end
github_repo(gem_change_info) click to toggle source
# File lib/unwrappr/researchers/github_comparison.rb, line 46
def github_repo(gem_change_info)
  gem_change_info[:github_repo]
end
github_repo_not_identified?(gem_change_info) click to toggle source
# File lib/unwrappr/researchers/github_comparison.rb, line 42
def github_repo_not_identified?(gem_change_info)
  github_repo(gem_change_info).nil?
end
try_comparing(repo:, base:, head:) click to toggle source
# File lib/unwrappr/researchers/github_comparison.rb, line 30
def try_comparing(repo:, base:, head:)
  comparison = compare(repo, "v#{base}", "v#{head}")
  comparison ||= compare(repo, base.to_s, head.to_s)
  comparison
end