Class: CleoQualityReview::ChangesDiff

Inherits:
Object
  • Object
show all
Defined in:
lib/cleo_quality_review/changes_diff.rb

Overview

Captures the git diff used for a quality review run

Instance Method Summary collapse

Constructor Details

#initialize(target_files:, command_runner:, base_ref: GitDiffBase::DEFAULT_BASE_REF, strict_base: false) ⇒ ChangesDiff

Returns a new instance of ChangesDiff.

Parameters:

  • target_files (Array<String>)

    files included in the review

  • command_runner (CommandRunner)

    for executing git commands

  • base_ref (String) (defaults to: GitDiffBase::DEFAULT_BASE_REF)

    git ref to compare against

  • strict_base (Boolean) (defaults to: false)

    whether unresolved refs should raise



16
17
18
19
20
21
# File 'lib/cleo_quality_review/changes_diff.rb', line 16

def initialize(target_files:, command_runner:, base_ref: GitDiffBase::DEFAULT_BASE_REF, strict_base: false)
  @target_files = target_files
  @command_runner = command_runner
  @base_ref = base_ref || GitDiffBase::DEFAULT_BASE_REF
  @strict_base = strict_base
end

Instance Method Details

#review_idString

Returns deterministic review identifier for this diff.

Returns:

  • (String)

    deterministic review identifier for this diff



31
32
33
# File 'lib/cleo_quality_review/changes_diff.rb', line 31

def review_id
  Digest::SHA256.hexdigest(to_s)
end

#to_sString

Returns combined tracked and untracked diff content.

Returns:

  • (String)

    combined tracked and untracked diff content



25
26
27
# File 'lib/cleo_quality_review/changes_diff.rb', line 25

def to_s
  @to_s ||= [tracked_changes_diff, untracked_changes_diff].reject(&:empty?).join("\n")
end