Sha256: 6dd27420fa2971b90f9a979b6bd9d5df44866b63dc28908007d73466899125df

Contents?: true

Size: 1.62 KB

Versions: 6

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

require_relative '../command'
require_relative '../utils/table'

module Dri
  module Commands
    class Incidents < Dri::Command
      include Dri::Utils::Table
      using Refinements

      def initialize(options)
        @options = options
      end

      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
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dri-0.7.0 lib/dri/commands/incidents.rb
dri-0.6.1 lib/dri/commands/incidents.rb
dri-0.6.0 lib/dri/commands/incidents.rb
dri-0.5.1 lib/dri/commands/incidents.rb
dri-0.5.0 lib/dri/commands/incidents.rb
dri-0.4.0 lib/dri/commands/incidents.rb