Sha256: 313a9bcfb02723a3aae3ba9ccb67f9e597cdcb7c6994223e8e78c6d7da15d4ec

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Unwrappr
  module Researchers
    # Compares the old version to the new via the Github API:
    # https://developer.github.com/v3/repos/commits/#compare-two-commits
    #
    # Implements the `gem_researcher` interface required by the
    # LockFileAnnotator.
    class GithubComparison
      def initialize(client)
        @client = client
      end

      def research(gem_change, gem_change_info)
        repo = gem_change_info[:github_repo]
        return gem_change_info if repo.nil?

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

      private

      def try_comparing(repo:, base:, head:)
        comparison = compare(repo, "v#{base}", "v#{head}")
        comparison ||= compare(repo, base.to_s, head.to_s)
        comparison
      end

      def compare(repo, base, head)
        @client.compare(repo, base, head)
      rescue Octokit::NotFound
        nil
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
unwrappr-0.3.2 lib/unwrappr/researchers/github_comparison.rb
unwrappr-0.3.1 lib/unwrappr/researchers/github_comparison.rb
unwrappr-0.3.0 lib/unwrappr/researchers/github_comparison.rb