Module: Aireview::ReviewMarker

Defined in:
lib/aireview/review_marker.rb

Overview

A hidden marker in the note body: it lets the review find its own comment and tell whether anything that affects the result changed.

Constant Summary collapse

PATTERN =
/<!--\s*aireview:key=([0-9a-f]+)\s*-->/

Class Method Summary collapse

Class Method Details

.build(key) ⇒ Object



13
14
15
# File 'lib/aireview/review_marker.rb', line 13

def build(key)
  "<!-- aireview:key=#{key} -->"
end

.extract(body) ⇒ Object



17
18
19
20
# File 'lib/aireview/review_marker.rb', line 17

def extract(body)
  match = PATTERN.match(body.to_s)
  match && match[1]
end

.key(prompts:, config:) ⇒ Object

The key is computed from the assembled prompts, not from a single SHA: that way the diff, the MR description, the Jira context, the review instructions and ignore_paths enter it by themselves. What else affects the result — provider, model and temperature of the stages, the shared pool with its critique policy, Jev as the critique engine — is known by Config#result_signature. Without a pool the key is the same as before. The LLM Critique counts only when it can run (its prompt is there), Jev only when it decides (its question templates are there): with the default engine the key is what it was before Jev.



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/aireview/review_marker.rb', line 31

def key(prompts:, config:)
  signature = config.result_signature
  source = {
    'generate' => [*signature['generate'], prompts[:generate_prompt]],
    'critique' => prompts[:critique_prompt] ? [*signature['critique'], prompts[:critique_prompt]] : nil
  }
  jev = prompts[:jev_questions]
  source['critique_engine'] = [*signature['critique_engine'], jev] if jev
  source['pool'] = signature['pool'] if signature['pool']

  Digest::SHA256.hexdigest(JSON.generate(source))[0, 16]
end

.state(merge_request) ⇒ Object

What makes a review result stale: a new commit, a target branch change, a rebase that moves the comparison base, and an edit of the title or the description — the requirements the review checks the code against come from those.



48
49
50
51
52
53
54
55
56
# File 'lib/aireview/review_marker.rb', line 48

def state(merge_request)
  {
    'sha' => merge_request['sha'],
    'target_branch' => merge_request['target_branch'],
    'diff_refs' => merge_request['diff_refs'],
    'title' => merge_request['title'],
    'description' => merge_request['description']
  }
end