Class: CleoQualityReview::IncrementalBaseResolver

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

Overview

Resolves the git base for an incremental review.

On a pull request that cleo-quality-review has already reviewed, this returns the most recent previously-reviewed commit that is still an ancestor of the current head, so only changes made since that review are analysed. It falls back to nil (meaning "review the full diff") outside a pull request context, when no prior review survives in history, or on any lookup error.

Constant Summary collapse

REVIEW_MARKER_PREFIX =
"<!-- cleo-quality-review:"
DISABLED_VALUES =
%w[0 false no off].freeze
ENABLED_ENV_KEY =
"CLEO_QUALITY_REVIEW_INCREMENTAL"
REVIEWS_PER_PAGE =
100
MAX_REVIEW_PAGES =
20

Instance Method Summary collapse

Constructor Details

#initialize(command_runner:, env: ENV, client: nil) ⇒ IncrementalBaseResolver

Returns a new instance of IncrementalBaseResolver.

Parameters:

  • command_runner (CommandRunner)

    for executing git commands

  • env (Hash{String => String}) (defaults to: ENV)

    process environment

  • client (GitHubClient, nil) (defaults to: nil)

    GitHub API client (built from env when omitted)



29
30
31
32
33
# File 'lib/cleo_quality_review/incremental_base_resolver.rb', line 29

def initialize(command_runner:, env: ENV, client: nil)
  @command_runner = command_runner
  @env = env
  @client = client
end

Instance Method Details

#resolve(head: "HEAD") ⇒ String?

Resolve the incremental base commit.

Parameters:

  • head (String) (defaults to: "HEAD")

    git ref for the current head

Returns:

  • (String, nil)

    commit SHA to diff against, or nil to review the full diff



39
40
41
42
43
44
45
46
# File 'lib/cleo_quality_review/incremental_base_resolver.rb', line 39

def resolve(head: "HEAD")
  return nil unless incremental_lookup_available?

  newest_reviewed_ancestor(head)
rescue StandardError => error
  warn("cleo-quality-review: incremental base lookup failed (#{error.message}); reviewing the full diff")
  nil
end