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 previously-reviewed commit recorded on the sticky pull request comment, provided it 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 sticky comment survives in history, or on any lookup error.

Constant Summary collapse

MARKER_PREFIX =
StickyCommentBuilder::MARKER_PREFIX
COMMIT_PATTERN =
/#{Regexp.escape(MARKER_PREFIX)}\s*commit=(\S+)\s*-->/
DISABLED_VALUES =
%w[0 false no off].freeze
ENABLED_ENV_KEY =
"CLEO_QUALITY_REVIEW_INCREMENTAL"
COMMENTS_PER_PAGE =
100
MAX_COMMENT_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)



31
32
33
34
35
# File 'lib/cleo_quality_review/incremental_base_resolver.rb', line 31

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



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

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

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