Class: Soba::Services::IssueProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/soba/services/issue_processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(github_client: nil, workflow_executor: nil, phase_strategy: nil, config: nil) ⇒ IssueProcessor



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/soba/services/issue_processor.rb', line 19

def initialize(github_client: nil, workflow_executor: nil, phase_strategy: nil, config: nil)
  @github_client = github_client || Infrastructure::GitHubClient.new
  @config = config || Configuration
  @workflow_executor = workflow_executor || WorkflowExecutor.new(
    tmux_session_manager: TmuxSessionManager.new(
      tmux_client: Infrastructure::TmuxClient.new
    ),
    git_workspace_manager: GitWorkspaceManager.new(configuration: @config)
  )
  @phase_strategy = phase_strategy || Domain::PhaseStrategy.new
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



17
18
19
# File 'lib/soba/services/issue_processor.rb', line 17

def config
  @config
end

#github_clientObject (readonly)

Returns the value of attribute github_client.



17
18
19
# File 'lib/soba/services/issue_processor.rb', line 17

def github_client
  @github_client
end

#phase_strategyObject (readonly)

Returns the value of attribute phase_strategy.



17
18
19
# File 'lib/soba/services/issue_processor.rb', line 17

def phase_strategy
  @phase_strategy
end

#workflow_executorObject (readonly)

Returns the value of attribute workflow_executor.



17
18
19
# File 'lib/soba/services/issue_processor.rb', line 17

def workflow_executor
  @workflow_executor
end

Instance Method Details

#process(issue) ⇒ Object



55
56
57
58
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/soba/services/issue_processor.rb', line 55

def process(issue)
  phase = phase_strategy.determine_phase(issue[:labels])

  return skipped_result('No phase determined for issue') unless phase

  current_label = current_label_for_phase(phase)
  next_label = phase_strategy.next_label(phase)

  begin
    repository = get_repository_from_config
    github_client.update_issue_labels(
      repository,
      issue[:number],
      from: current_label,
      to: next_label
    )
  rescue StandardError => e
    raise IssueProcessingError, "Failed to update labels: #{e.message}"
  end

  phase_config = get_phase_config(phase)

  if phase_config&.command
    puts "Processing phase: #{phase} with command: #{phase_config.command}"
    puts "  Phase name: #{phase_config.name || 'not set'}"

    actual_config = config.respond_to?(:config) ? config.config : config
    use_tmux = actual_config.workflow.use_tmux
    setup_workspace = actual_config.git.setup_workspace

    execution_result = workflow_executor.execute(
      phase: phase_config,
      issue_number: issue[:number],
      use_tmux: use_tmux,
      setup_workspace: setup_workspace,
      issue_title: issue[:title],
      phase_name: phase.to_s
    )

    result = {
      success: execution_result[:success],
      phase: phase,
      issue_number: issue[:number],
      label_updated: true,
      output: execution_result[:output],
      error: execution_result[:error],
    }

    # Add tmux-specific fields if present
    result[:mode] = execution_result[:mode] if execution_result[:mode]
    result[:session_name] = execution_result[:session_name] if execution_result[:session_name]
    result[:window_name] = execution_result[:window_name] if execution_result[:window_name]
    result[:pane_id] = execution_result[:pane_id] if execution_result[:pane_id]
    result[:tmux_info] = execution_result[:tmux_info] if execution_result[:tmux_info]

    result
  else
    {
      success: true,
      phase: phase,
      issue_number: issue[:number],
      label_updated: true,
      workflow_skipped: true,
      reason: 'Phase configuration not defined',
    }
  end
end

#run(issue_number, use_tmux: true) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/soba/services/issue_processor.rb', line 31

def run(issue_number, use_tmux: true)
  # Fetch issue details from GitHub
  repository = get_repository_from_config
  issue = @github_client.issue(repository, issue_number)

  # Convert issue to expected format
  issue_hash = {
    number: issue.number,
    title: issue.title,
    labels: issue.labels.map { |l| l.name || l[:name] },
  }

  # Process with the specified tmux mode
  original_use_tmux = @config.config.workflow.use_tmux
  begin
    # Temporarily override the config value
    @config.config.workflow.use_tmux = use_tmux
    process(issue_hash)
  ensure
    # Restore original config value
    @config.config.workflow.use_tmux = original_use_tmux
  end
end