Class: Ace::Git::Atoms::TaskPatternExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/git/atoms/task_pattern_extractor.rb

Overview

Extracts task ID from branch name using configurable patterns Pure function - no I/O operations

Consolidated from ace-review TaskAutoDetector

Class Method Summary collapse

Class Method Details

.extract(branch_name) ⇒ String|nil

Extract task ID using default patterns

Parameters:

  • branch_name (String)

    Branch name to extract from

Returns:

  • (String|nil)

    Task ID or nil



44
45
46
# File 'lib/ace/git/atoms/task_pattern_extractor.rb', line 44

def self.extract(branch_name)
  extract_from_branch(branch_name)
end

.extract_from_branch(branch_name, patterns: nil) ⇒ String|nil

Extract task ID from branch name using configurable patterns Default pattern matches:

117-feature -> "117"
121.01-archive -> "121.01"

Does not match:

main -> nil
feature-123 -> nil (number not at start)

Parameters:

  • branch_name (String)

    e.g., “117-feature-name”, “121.01-archive”

  • patterns (Array<String>|nil) (defaults to: nil)

    Optional regex patterns (uses default if nil)

Returns:

  • (String|nil)

    task ID or nil if not found



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ace/git/atoms/task_pattern_extractor.rb', line 22

def self.extract_from_branch(branch_name, patterns: nil)
  return nil if branch_name.nil? || branch_name.empty?
  return nil if branch_name == "HEAD" # Detached HEAD state

  # Use provided patterns or default pattern
  patterns ||= ['^(\d+(?:\.\d+)?)-']

  patterns.each do |pattern|
    regex = Regexp.new(pattern)
    match = branch_name.match(regex)
    return match[1] if match && match[1]
  rescue RegexpError => e
    warn "Warning: Invalid task pattern '#{pattern}': #{e.message}"
    next
  end

  nil
end

.has_task_pattern?(branch_name) ⇒ Boolean

Check if branch name contains a task pattern

Parameters:

  • branch_name (String)

    Branch name to check

Returns:

  • (Boolean)

    True if branch contains task pattern



51
52
53
# File 'lib/ace/git/atoms/task_pattern_extractor.rb', line 51

def self.has_task_pattern?(branch_name)
  !extract(branch_name).nil?
end