Class: Aidp::Watch::GanttSynchronizer

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/watch/gantt_synchronizer.rb

Overview

Synchronizes parsed Gantt task data with GitHub Projects and Mermaid docs.

Constant Summary collapse

CRITICAL_PATH_VALUES =
%w[Yes No].freeze

Instance Method Summary collapse

Constructor Details

#initialize(repository_client:, state_store:, project_id:, field_mappings:, auto_create_fields: true, parser_class: PrdParser) ⇒ GanttSynchronizer

Returns a new instance of GanttSynchronizer.



11
12
13
14
15
16
17
18
19
# File 'lib/aidp/watch/gantt_synchronizer.rb', line 11

def initialize(repository_client:, state_store:, project_id:, field_mappings:, auto_create_fields: true, parser_class: PrdParser)
  @repository_client = repository_client
  @state_store = state_store
  @project_id = project_id
  @field_mappings = field_mappings
  @auto_create_fields = auto_create_fields
  @parser_class = parser_class
  @project_fields_cache = nil
end

Instance Method Details

#sync_from_prd(prd_path:, format: nil, issue_numbers_by_title: {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/aidp/watch/gantt_synchronizer.rb', line 21

def sync_from_prd(prd_path:, format: nil, issue_numbers_by_title: {})
  parsed = @parser_class.new(file_path: prd_path, format: format).parse
  tasks = resolve_issue_numbers(parsed[:tasks], issue_numbers_by_title)
  critical_path = calculate_critical_path(tasks)
  tasks_by_id = tasks.each_with_object({}) { |task, memo| memo[task[:id]] = task }

  synced = 0
  skipped = 0

  tasks.each do |task|
    if task[:issue_number].nil?
      skipped += 1
      next
    end

    item_id = ensure_project_item(task[:issue_number])
    update_date_fields(item_id, task)
    update_dependencies_field(item_id, task, tasks_by_id)
    update_critical_path_field(item_id, critical_path.include?(task[:id]))

    @state_store.record_project_sync(task[:issue_number], {
      gantt_task_id: task[:id],
      gantt_path: prd_path,
      gantt_format: parsed[:format].to_s,
      critical_path: critical_path.include?(task[:id])
    })
    synced += 1
  end

  {synced: synced, skipped: skipped, critical_path: critical_path}
end

#sync_issue_status_to_gantt(prd_path:, issue_number:, status:, format: nil) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/aidp/watch/gantt_synchronizer.rb', line 53

def sync_issue_status_to_gantt(prd_path:, issue_number:, status:, format: nil)
  parser = @parser_class.new(file_path: prd_path, format: format)
  parsed = parser.parse
  return false unless parsed[:format] == :mermaid

  content = File.read(prd_path)
  lines = content.lines
  line_index = mermaid_task_line_index(content, parsed[:tasks], issue_number)
  return false unless line_index

  lines[line_index] = rewrite_mermaid_status(lines[line_index], status)
  File.write(prd_path, lines.join)
  true
end