class Unwrappr::LockFileAnnotator

The main entry object for annotating Gemfile.lock files.

This class has four main collaborators:

Public Class Methods

annotate_github_pull_request( repo:, pr_number:, lock_files:, client: Octokit.client ) click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/unwrappr/lock_file_annotator.rb, line 20
def self.annotate_github_pull_request(
  repo:, pr_number:, lock_files:, client: Octokit.client
)
  new(
    lock_file_diff_source: Github::PrSource.new(repo, pr_number, lock_files, client),
    annotation_sink: Github::PrSink.new(repo, pr_number, client),
    annotation_writer: Writers::Composite.new(
      Writers::Title,
      Writers::VersionChange,
      Writers::ProjectLinks,
      Writers::SecurityVulnerabilities,
      Writers::GithubCommitLog
    ),
    gem_researcher: Researchers::Composite.new(
      Researchers::RubyGemsInfo.new,
      Researchers::GithubRepo.new,
      Researchers::GithubComparison.new(client),
      Researchers::SecurityVulnerabilities.new
    )
  ).annotate
end
new( lock_file_diff_source:, annotation_sink:, annotation_writer:, gem_researcher: ) click to toggle source

rubocop:enable Metrics/MethodLength

# File lib/unwrappr/lock_file_annotator.rb, line 43
def initialize(
  lock_file_diff_source:,
  annotation_sink:,
  annotation_writer:,
  gem_researcher:
)
  @lock_file_diff_source = lock_file_diff_source
  @annotation_sink = annotation_sink
  @annotation_writer = annotation_writer
  @gem_researcher = gem_researcher
end

Public Instance Methods

annotate() click to toggle source
# File lib/unwrappr/lock_file_annotator.rb, line 55
def annotate
  @lock_file_diff_source.each_file do |lock_file_diff|
    puts "Annotating #{lock_file_diff.filename}"

    lock_file_diff.each_gem_change do |gem_change|
      gem_change_info = @gem_researcher.research(gem_change, {})
      message = @annotation_writer.write(gem_change, gem_change_info)
      @annotation_sink.annotate_change(gem_change, message)
    end
  end
end