Class: Aidp::Watch::AutoPrProcessor

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

Overview

Handles the aidp-auto label on PRs by chaining review and CI-fix flows until the PR is ready for human review.

Completion criteria:

  • Automated review completed (or already processed)

  • CI passing (success or skipped states accepted)

  • Iteration cap not exceeded (default: 20)

When complete:

  • Converts draft PR to ready for review

  • Requests the label-adder as reviewer

  • Posts completion comment

  • Removes aidp-auto label

Constant Summary collapse

DEFAULT_AUTO_LABEL =
"aidp-auto"
DEFAULT_ITERATION_CAP =
20
PASSING_CI_STATES =
%w[success skipped].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:, review_processor:, ci_fix_processor:, label_config: {}, iteration_cap: nil, verbose: false, prompt: nil) ⇒ AutoPrProcessor

Returns a new instance of AutoPrProcessor.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/aidp/watch/auto_pr_processor.rb', line 28

def initialize(repository_client:, state_store:, review_processor:, ci_fix_processor:,
  label_config: {}, iteration_cap: nil, verbose: false, prompt: nil)
  @repository_client = repository_client
  @state_store = state_store
  @review_processor = review_processor
  @ci_fix_processor = ci_fix_processor
  @state_extractor = GitHubStateExtractor.new(repository_client: repository_client)
  @verbose = verbose
  @prompt = prompt
  @auto_label = label_config[:auto_trigger] || label_config["auto_trigger"] || DEFAULT_AUTO_LABEL
  @iteration_cap = iteration_cap || DEFAULT_ITERATION_CAP
end

Instance Attribute Details

#auto_labelObject (readonly)

Returns the value of attribute auto_label.



69
70
71
# File 'lib/aidp/watch/auto_pr_processor.rb', line 69

def auto_label
  @auto_label
end

#iteration_capObject (readonly)

Returns the value of attribute iteration_cap.



69
70
71
# File 'lib/aidp/watch/auto_pr_processor.rb', line 69

def iteration_cap
  @iteration_cap
end

Instance Method Details

#process(pr) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/aidp/watch/auto_pr_processor.rb', line 41

def process(pr)
  number = pr[:number]
  Aidp.log_debug("auto_pr_processor", "process_started", pr: number, title: pr[:title])
  display_message("🤖 Running autonomous review/CI loop for PR ##{number}", type: :info)

  # Record this iteration
  iteration = @state_store.record_auto_pr_iteration(number)
  Aidp.log_debug("auto_pr_processor", "iteration_recorded", pr: number, iteration: iteration, cap: @iteration_cap)

  # Check iteration cap
  if iteration > @iteration_cap
    Aidp.log_warn("auto_pr_processor", "iteration_cap_reached",
      pr: number, iteration: iteration, cap: @iteration_cap)
    display_message("⚠️  PR ##{number} reached iteration cap (#{@iteration_cap}), marking ready", type: :warn)
    finalize_pr(pr_number: number, reason: :iteration_cap_reached)
    return
  end

  # Run review and CI fix flows. Each processor is responsible for its own guards.
  @review_processor.process(pr)
  @ci_fix_processor.process(pr)

  finalize_if_ready(pr_number: number)
rescue => e
  Aidp.log_error("auto_pr_processor", "process_failed", pr: pr[:number], error: e.message, error_class: e.class.name)
  display_message("❌ aidp-auto failed on PR ##{pr[:number]}: #{e.message}", type: :error)
end