class Unwrappr::Github::PrSource

Obtains Gemfile.lock changes from a Github Pull Request

Implements the `lock_file_diff_source` interface as defined by the LockFileAnnotator.

Public Class Methods

new(repo, pr_number, lock_files, client) click to toggle source
# File lib/unwrappr/github/pr_source.rb, line 12
def initialize(repo, pr_number, lock_files, client)
  @repo = repo
  @pr_number = pr_number
  @lock_files = lock_files
  @client = client
end

Public Instance Methods

each_file() { |lock_file_diff( filename: filename, base_file: file_contents(filename, base_sha), head_file: file_contents(filename, head_sha), patch: patch, sha: head_sha| ... } click to toggle source
# File lib/unwrappr/github/pr_source.rb, line 19
def each_file
  lock_file_diffs.each do |lock_file_diff|
    yield LockFileDiff.new(
      filename: lock_file_diff.filename,
      base_file: file_contents(lock_file_diff.filename, base_sha),
      head_file: file_contents(lock_file_diff.filename, head_sha),
      patch: lock_file_diff.patch,
      sha: head_sha
    )
  end
end

Private Instance Methods

base_sha() click to toggle source
# File lib/unwrappr/github/pr_source.rb, line 51
def base_sha
  @base_sha ||= pull_request.base.sha
end
file_contents(filename, ref) click to toggle source
# File lib/unwrappr/github/pr_source.rb, line 41
def file_contents(filename, ref)
  Base64.decode64(
    @client.contents(@repo, path: filename, ref: ref).content
  )
end
head_sha() click to toggle source
# File lib/unwrappr/github/pr_source.rb, line 47
def head_sha
  @head_sha ||= pull_request.head.sha
end
lock_file_diffs() click to toggle source
# File lib/unwrappr/github/pr_source.rb, line 33
def lock_file_diffs
  @lock_file_diffs ||= @client
                       .pull_request_files(@repo, @pr_number)
                       .select do |file|
                         @lock_files.include?(File.basename(file.filename))
                       end
end
pull_request() click to toggle source
# File lib/unwrappr/github/pr_source.rb, line 55
def pull_request
  @pull_request ||= @client.pull_request(@repo, @pr_number)
end