Module: Ocak::TargetResolver

Defined in:
lib/ocak/target_resolver.rb

Defined Under Namespace

Classes: TargetResolutionError

Class Method Summary collapse

Class Method Details

.extract_target_name(body, field:) ⇒ Object

Extract target name from YAML front-matter. Returns the target name string, or nil if not found.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ocak/target_resolver.rb', line 27

def self.extract_target_name(body, field:)
  match = body.match(/\A---\s*\n(.*?)\n---/m)
  return nil unless match

  frontmatter = YAML.safe_load(match[1])
  return nil unless frontmatter.is_a?(Hash)

  frontmatter[field]&.to_s&.strip
rescue Psych::SyntaxError
  nil
end

.resolve(issue, config:) ⇒ Object

Resolves the target repo for an issue. Returns { name:, path: } hash or nil (single-repo mode). Raises TargetResolutionError on missing/invalid target in multi-repo mode.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ocak/target_resolver.rb', line 10

def self.resolve(issue, config:)
  return nil unless config.multi_repo?

  body = issue['body'].to_s
  repo_name = extract_target_name(body, field: config.target_field)

  unless repo_name
    raise TargetResolutionError,
          "Issue ##{issue['number']} is missing required '#{config.target_field}' field in body. " \
          "Known repos: #{config.repos.keys.join(', ')}"
  end

  config.resolve_repo(repo_name)
end