Class: Dri::Commands::Incidents

Inherits:
Dri::Command show all
Includes:
Utils::Constants::Triage::Labels, Utils::Table
Defined in:
lib/dri/commands/incidents.rb

Constant Summary

Constants included from Utils::Constants::Triage::Labels

Utils::Constants::Triage::Labels::FAILURE, Utils::Constants::Triage::Labels::FAILURE_NEW, Utils::Constants::Triage::Labels::FOUND, Utils::Constants::Triage::Labels::INCIDENT, Utils::Constants::Triage::Labels::QA, Utils::Constants::Triage::Labels::QUALITY, Utils::Constants::Triage::Labels::QUARANTINE, Utils::Constants::Triage::Labels::SERVICE

Instance Method Summary collapse

Methods included from Utils::Table

#print_table

Methods inherited from Dri::Command

#add_color, #api_client, #bold, #command, #config, #cursor, #editor, #emoji, #handover_report_path, #logger, #ops_token, #pastel, #profile, #prompt, #spinner, #timezone, #token, #username, #verify_config_exists

Constructor Details

#initialize(options) ⇒ Incidents

Returns a new instance of Incidents.



14
15
16
# File 'lib/dri/commands/incidents.rb', line 14

def initialize(options)
  @options = options
end

Instance Method Details

#execute(_input: $stdin, output: $stdout) ⇒ Object

rubocop:disable Metrics/AbcSize



18
19
20
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
52
53
54
55
56
57
58
# File 'lib/dri/commands/incidents.rb', line 18

def execute(_input: $stdin, output: $stdout) # rubocop:disable Metrics/AbcSize
  verify_config_exists

  incident = add_color('Incident', :bright_yellow)
  service = add_color('Service', :bright_yellow)
  status = add_color('Status', :bright_yellow)
  url = add_color('URL', :bright_yellow)

  header = [incident, service, status, url]

  logger.info "Looking for open incidents..."
  incidents = []

  spinner.run do
    response = api_client.incidents

    if response.nil?
      logger.info 'Hooray, no active incidents 🎉.'
      break
    end

    response.each do |incident|
      title = incident.title.truncate(70)
      url = incident.web_url
      labels = incident.labels
      status = "N/A"
      service = "N/A"

      labels.each do |label|
        status = label.gsub!(INCIDENT, ' ').to_s if label.include? INCIDENT
        service = label.gsub!(SERVICE, ' ').to_s if label.include? SERVICE
      end

      incidents << [title, service, status, url]
    end
  end
  print_table(header, incidents, alignments: [:left, :center, :center, :center])
  output.puts(<<~MSG)
    Found: #{incidents.size} incident(s).
  MSG
end