Class: Ace::Review::Molecules::PrTaskSpecResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/review/molecules/pr_task_spec_resolver.rb

Overview

Resolves a single task spec path from PR metadata when possible.

Class Method Summary collapse

Class Method Details

.extract_from_branch(branch_name) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/ace/review/molecules/pr_task_spec_resolver.rb', line 35

def self.extract_from_branch(branch_name)
  return nil unless branch_name && !branch_name.strip.empty?

  # Extract prefix before first hyphen as potential task reference
  prefix = branch_name.split("-", 2).first
  return nil if prefix.nil? || prefix.empty?
  return nil if prefix.include?("/")

  prefix
end

.extract_from_text(text) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/ace/review/molecules/pr_task_spec_resolver.rb', line 46

def self.extract_from_text(text)
  return nil unless text && !text.strip.empty?

  full_ref = text.match(/\b(v\.\d+\.\d+\.\d+\+task\.\d+(?:\.\d+)?)\b/i)
  return full_ref[1] if full_ref

  task_ref = text.match(/\btask[.\s:#-]+(\d+(?:\.\d+)?)\b/i)
  task_ref&.[](1)
end

.extract_task_reference(pr_metadata) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/ace/review/molecules/pr_task_spec_resolver.rb', line 26

def self.extract_task_reference()
  return nil unless .is_a?(Hash)

  from_branch = extract_from_branch(["headRefName"])
  return from_branch if from_branch

  extract_from_text(["body"]) || extract_from_text(["title"])
end

.resolve_spec_path(pr_metadata) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ace/review/molecules/pr_task_spec_resolver.rb', line 8

def self.resolve_spec_path()
  task_reference = extract_task_reference()
  return nil unless task_reference

  require_relative "task_resolver"
  task_info = TaskResolver.resolve(task_reference)
  return nil unless task_info

  spec_path = task_info[:spec_path]
  return nil unless spec_path && File.exist?(spec_path)
  return nil unless spec_path.end_with?(".s.md")

  spec_path
rescue => e
  warn "Warning: Failed to resolve PR task spec: #{e.message}" if Ace::Review.debug?
  nil
end