Sha256: 89f78d2a48f6afb3775f0fe8eb035c9400bef005cf8a7cb9232d387cd51c0ae6

Contents?: true

Size: 1.78 KB

Versions: 80

Compression:

Stored size: 1.78 KB

Contents

require 'digest'
require 'forwardable'
require 'honeybadger/cli/main'
require 'honeybadger/cli/helpers'
require 'honeybadger/util/http'
require 'honeybadger/util/stats'

module Honeybadger
  module CLI
    class Notify
      extend Forwardable
      include Helpers::BackendCmd

      def initialize(options, args, config)
        @options = options
        @args = args
        @config = config
        @shell = ::Thor::Base.shell.new
      end

      def run
        payload = {
          api_key: config.get(:api_key),
          notifier: NOTIFIER,
          error: {
            class: options['class'],
            message: options['message']
          },
          request: {},
          server: {
            project_root: Dir.pwd,
            environment_name: config.get(:env),
            time: Time.now,
            stats: Util::Stats.all
          }
        }

        payload[:error][:fingerprint] = Digest::SHA1.hexdigest(options['fingerprint']) if option?('fingerprint')
        payload[:error][:tags] = options['tags'].to_s.strip.split(',').map(&:strip) if option?('tags')

        payload[:request][:component] = options['component'] if option?('component')
        payload[:request][:action] = options['action'] if option?('action')
        payload[:request][:url] = options['url'] if option?('url')

        payload.delete(:request) if payload[:request].empty?

        response = config.backend.notify(:notices, payload)
        if response.success?
          say("Error notification complete.", :green)
        else
          say(error_message(response), :red)
          exit(1)
        end
      end

      private

      attr_reader :options, :args, :config

      def_delegator :@shell, :say

      def option?(key)
        options.has_key?(key) && options[key] != key
      end
    end
  end
end

Version data entries

80 entries across 80 versions & 1 rubygems

Version Path
honeybadger-5.24.0 lib/honeybadger/cli/notify.rb
honeybadger-5.23.0 lib/honeybadger/cli/notify.rb
honeybadger-5.22.0 lib/honeybadger/cli/notify.rb
honeybadger-5.21.0 lib/honeybadger/cli/notify.rb
honeybadger-5.20.1 lib/honeybadger/cli/notify.rb
honeybadger-5.20.0 lib/honeybadger/cli/notify.rb
honeybadger-5.19.2 lib/honeybadger/cli/notify.rb
honeybadger-5.19.1 lib/honeybadger/cli/notify.rb
honeybadger-5.19.0 lib/honeybadger/cli/notify.rb
honeybadger-5.18.0 lib/honeybadger/cli/notify.rb
honeybadger-5.17.0 lib/honeybadger/cli/notify.rb
honeybadger-5.16.0 lib/honeybadger/cli/notify.rb
honeybadger-5.15.6 lib/honeybadger/cli/notify.rb
honeybadger-5.15.5 lib/honeybadger/cli/notify.rb
honeybadger-5.15.4 lib/honeybadger/cli/notify.rb
honeybadger-5.15.3 lib/honeybadger/cli/notify.rb
honeybadger-5.15.2 lib/honeybadger/cli/notify.rb
honeybadger-5.15.1 lib/honeybadger/cli/notify.rb
honeybadger-5.15.0 lib/honeybadger/cli/notify.rb
honeybadger-5.14.2 lib/honeybadger/cli/notify.rb