Class: Aidp::Watch::ProjectsProcessor

Inherits:
Object
  • Object
show all
Includes:
MessageDisplay
Defined in:
lib/aidp/watch/projects_processor.rb

Overview

Synchronizes GitHub issues with GitHub Projects V2. Updates project fields based on issue state and handles blocking relationships.

Constant Summary collapse

DEFAULT_FIELD_MAPPINGS =

Default field mapping configuration

{
  status: "Status",
  priority: "Priority",
  skills: "Skills",
  personas: "Personas",
  blocking: "Blocking",
  start_date: "Start Date",
  target_date: "Target Date",
  dependencies: "Dependencies",
  critical_path: "Critical Path"
}.freeze
STATUS_VALUES =

Status values for different issue states

{
  backlog: "Backlog",
  todo: "Todo",
  in_progress: "In Progress",
  in_review: "In Review",
  done: "Done",
  blocked: "Blocked"
}.freeze
CRITICAL_PATH_VALUES =
%w[Yes No].freeze

Constants included from MessageDisplay

MessageDisplay::COLOR_MAP, MessageDisplay::CRITICAL_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MessageDisplay

#display_message, included, #message_display_prompt, #quiet_mode?

Constructor Details

#initialize(repository_client:, state_store:, project_id:, config: {}, gantt_synchronizer: nil) ⇒ ProjectsProcessor

Returns a new instance of ProjectsProcessor.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/aidp/watch/projects_processor.rb', line 38

def initialize(repository_client:, state_store:, project_id:, config: {}, gantt_synchronizer: nil)
  @repository_client = repository_client
  @state_store = state_store
  @project_id = project_id
  @config = normalize_config(config)
  @field_mappings = DEFAULT_FIELD_MAPPINGS.merge(@config[:field_mappings] || {})
  @auto_create_fields = @config[:auto_create_fields] != false
  @project_fields_cache = nil
  @gantt_synchronizer = gantt_synchronizer || GanttSynchronizer.new(
    repository_client: repository_client,
    state_store: state_store,
    project_id: project_id,
    field_mappings: @field_mappings,
    auto_create_fields: @auto_create_fields
  )
end

Instance Attribute Details

#project_idObject (readonly)

Returns the value of attribute project_id.



36
37
38
# File 'lib/aidp/watch/projects_processor.rb', line 36

def project_id
  @project_id
end

#repository_clientObject (readonly)

Returns the value of attribute repository_client.



36
37
38
# File 'lib/aidp/watch/projects_processor.rb', line 36

def repository_client
  @repository_client
end

#state_storeObject (readonly)

Returns the value of attribute state_store.



36
37
38
# File 'lib/aidp/watch/projects_processor.rb', line 36

def state_store
  @state_store
end

Instance Method Details

#check_blocking_dependencies(issue_number) ⇒ Hash

Check if an issue is blocked by any of its sub-issues

Parameters:

  • issue_number (Integer)

    The parent issue number

Returns:

  • (Hash)

    Blocking status with :blocked flag and :blockers list



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/aidp/watch/projects_processor.rb', line 136

def check_blocking_dependencies(issue_number)
  Aidp.log_debug("projects_processor", "check_blocking_dependencies", issue_number: issue_number)

  status = @state_store.blocking_status(issue_number)

  if status[:blocked]
    # Fetch current status of sub-issues
    open_blockers = []
    status[:blockers].each do |sub_number|
      issue = @repository_client.fetch_issue(sub_number)
      open_blockers << sub_number if issue[:state] == "open"
    rescue => e
      Aidp.log_warn("projects_processor", "Failed to fetch sub-issue",
        sub_issue: sub_number, error: e.message)
      # Assume still blocking if we can't check
      open_blockers << sub_number
    end

    if open_blockers.any?
      update_blocking_field(issue_number, open_blockers)
      display_message("⚠️  Issue ##{issue_number} is blocked by #{open_blockers.size} open sub-issues",
        type: :warn)
      {blocked: true, blockers: open_blockers}
    else
      # All sub-issues are closed - unblock parent
      clear_blocking_field(issue_number)
      update_issue_status(issue_number, STATUS_VALUES[:todo])
      display_message("✓ Issue ##{issue_number} is no longer blocked", type: :success)
      {blocked: false, blockers: []}
    end
  else
    {blocked: false, blockers: []}
  end
end

#ensure_project_fieldsBoolean

Initialize required project fields if they don't exist

Returns:

  • (Boolean)

    True if all fields are ready



206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/aidp/watch/projects_processor.rb', line 206

def ensure_project_fields
  return true unless @auto_create_fields

  Aidp.log_debug("projects_processor", "ensure_project_fields", project_id: @project_id)

  all_ready = true
  required_fields.each do |field_spec|
    field = find_or_create_field(field_spec[:name], field_spec[:type], field_spec[:options])
    all_ready = false unless field
  end

  all_ready
end

#sync_all_issues(issues) ⇒ Object

Sync all active issues in a project

Parameters:

  • issues (Array<Hash>)

    Array of issue data with :number keys



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/aidp/watch/projects_processor.rb', line 173

def sync_all_issues(issues)
  Aidp.log_debug("projects_processor", "sync_all_issues", count: issues.size)

  display_message("📊 Syncing #{issues.size} issues to project...", type: :info)

  synced = 0
  failed = 0

  issues.each do |issue|
    success = sync_issue_to_project(issue[:number])
    if success
      synced += 1
    else
      failed += 1
    end
  end

  display_message("📊 Sync complete: #{synced} synced, #{failed} failed", type: :info)
  {synced: synced, failed: failed}
end

#sync_from_gantt(prd_path = configured_prd_path, issue_numbers_by_title: {}) ⇒ Object



194
195
196
197
198
199
200
201
202
# File 'lib/aidp/watch/projects_processor.rb', line 194

def sync_from_gantt(prd_path = configured_prd_path, issue_numbers_by_title: {})
  return {synced: 0, skipped: 0, critical_path: []} unless prd_path

  @gantt_synchronizer.sync_from_prd(
    prd_path: prd_path,
    format: configured_gantt_format,
    issue_numbers_by_title: issue_numbers_by_title
  )
end

#sync_issue_to_project(issue_number, status: nil) ⇒ Boolean

Sync a single issue to the project

Parameters:

  • issue_number (Integer)

    The issue number

  • status (String, nil) (defaults to: nil)

    Optional status to set

Returns:

  • (Boolean)

    True if sync was successful



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/aidp/watch/projects_processor.rb', line 59

def sync_issue_to_project(issue_number, status: nil)
  Aidp.log_debug("projects_processor", "sync_issue_to_project", issue_number: issue_number, status: status)

  # Check if issue is already linked to project
  item_id = @state_store.project_item_id(issue_number)

  unless item_id
    # Link issue to project
    begin
      item_id = @repository_client.link_issue_to_project(@project_id, issue_number)
      @state_store.record_project_item_id(issue_number, item_id)
      display_message("📊 Linked issue ##{issue_number} to project", type: :success)
    rescue => e
      Aidp.log_error("projects_processor", "Failed to link issue to project",
        issue_number: issue_number, error: e.message)
      display_message("⚠️  Failed to link issue ##{issue_number} to project: #{e.message}", type: :warn)
      return false
    end
  end

  # Update status if provided
  if status
    return false unless update_issue_status(issue_number, status)
  end

  # Check and update blocking status
  check_blocking_dependencies(issue_number)

  @state_store.record_project_sync(issue_number, {
    last_sync: Time.now.utc.iso8601,
    status: status
  })
  sync_issue_status_to_gantt(issue_number, status) if status && gantt_sync_enabled?

  true
rescue => e
  Aidp.log_error("projects_processor", "Failed to sync issue to project",
    issue_number: issue_number, error: e.message)
  false
end

#update_issue_status(issue_number, status) ⇒ Boolean

Update the status field for an issue in the project

Parameters:

  • issue_number (Integer)

    The issue number

  • status (String)

    The status value (e.g., "In Progress", "Done")

Returns:

  • (Boolean)

    True if update was successful



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/aidp/watch/projects_processor.rb', line 104

def update_issue_status(issue_number, status)
  Aidp.log_debug("projects_processor", "update_issue_status",
    issue_number: issue_number, status: status)

  item_id = @state_store.project_item_id(issue_number)
  return false unless item_id

  status_field = find_or_create_field(@field_mappings[:status], "SINGLE_SELECT", STATUS_VALUES.values)
  return false unless status_field

  option_id = find_option_id(status_field, status)
  return false unless option_id

  begin
    @repository_client.update_project_item_field(
      item_id,
      status_field[:id],
      {project_id: @project_id, option_id: option_id}
    )
    display_message("✓ Updated status for ##{issue_number} to '#{status}'", type: :success)
    true
  rescue => e
    Aidp.log_error("projects_processor", "Failed to update status",
      issue_number: issue_number, status: status, error: e.message)
    display_message("⚠️  Failed to update status: #{e.message}", type: :warn)
    false
  end
end