Class: McpServer::CompletedWorkTool

Inherits:
MCP::Tool
  • Object
show all
Defined in:
lib/jirametrics/mcp_server.rb

Class Method Summary collapse

Class Method Details

.build_row(issue, project_name, started, stopped, cutoff, completed_status, completed_resolution, end_time, history_field, history_value, ever_blocked, ever_stalled, currently_blocked, currently_stalled) ⇒ Object



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/jirametrics/mcp_server.rb', line 301

def self.build_row issue, project_name, started, stopped, cutoff, completed_status, completed_resolution,
                   end_time, history_field, history_value, ever_blocked, ever_stalled,
                   currently_blocked, currently_stalled
  completed_date = stopped.to_date
  return nil if cutoff && completed_date < cutoff

  status_at_done, resolution_at_done = issue.status_resolution_at_done
  return nil if completed_status && status_at_done&.name != completed_status
  return nil if completed_resolution && completed_resolution != resolution_at_done
  return nil unless McpServer.matches_history?(issue, end_time,
                                               history_field, history_value, ever_blocked, ever_stalled,
                                               currently_blocked, currently_stalled)

  cycle_time = started ? (completed_date - started.to_date).to_i + 1 : nil
  {
    key: issue.key,
    summary: issue.summary,
    type: issue.type,
    completed_date: completed_date,
    cycle_time_days: cycle_time,
    flow_efficiency: McpServer.flow_efficiency_percent(issue, stopped),
    status_at_done: status_at_done&.name,
    resolution_at_done: resolution_at_done,
    project: project_name
  }
end

.call(server_context:, days_back: nil, project: nil, project_name: nil, completed_status: nil, completed_resolution: nil, history_field: nil, history_value: nil, ever_blocked: nil, ever_stalled: nil, currently_blocked: nil, currently_stalled: nil) ⇒ Object



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/jirametrics/mcp_server.rb', line 328

def self.call(server_context:, days_back: nil, project: nil, project_name: nil,
              completed_status: nil, completed_resolution: nil,
              history_field: nil, history_value: nil, ever_blocked: nil, ever_stalled: nil,
              currently_blocked: nil, currently_stalled: nil, **)
  project ||= project_name
  rows = []
  allowed_projects = McpServer.resolve_projects(server_context, project)

  server_context[:projects].each do |project_name, project_data|
    next if allowed_projects && !allowed_projects.include?(project_name)

    today = project_data[:today]
    cutoff = today - days_back if days_back

    project_data[:issues].each do |issue|
      started, stopped = issue.started_stopped_times
      next unless stopped

      row = build_row(issue, project_name, started, stopped, cutoff, completed_status, completed_resolution,
                      project_data[:end_time], history_field, history_value, ever_blocked, ever_stalled,
                      currently_blocked, currently_stalled)
      rows << row if row
    end
  end

  rows.sort_by! { |r| -r[:completed_date].to_time.to_i }

  if rows.empty?
    text = 'No completed work found.'
  else
    lines = rows.map do |r|
      ct = r[:cycle_time_days] ? "#{r[:cycle_time_days]}d" : 'unknown'
      fe = r[:flow_efficiency] ? " | FE: #{r[:flow_efficiency]}%" : ''
      completion = [r[:status_at_done], r[:resolution_at_done]].compact.join(' / ')
      "#{r[:key]} | #{r[:project]} | #{r[:type]} | #{r[:completed_date]} | " \
        "Cycle time: #{ct}#{fe} | #{completion} | #{r[:summary]}"
    end
    text = lines.join("\n")
  end

  MCP::Tool::Response.new([{ type: 'text', text: text }])
end