module Commands::Base

Public Class Methods

included(base) click to toggle source
# File lib/lita/commands/base.rb, line 3
def self.included(base)
  base.class_eval do
    extend ClassMethods
    attr_reader :message
    attr_reader :data
    attr_reader :pagerduty
    attr_reader :store
  end
end
new(message, pagerduty, store) click to toggle source
# File lib/lita/commands/base.rb, line 19
def initialize(message, pagerduty, store)
  @message = message
  @pagerduty = pagerduty
  @store = store
  @data = nil
end

Public Instance Methods

current_user() click to toggle source
# File lib/lita/commands/base.rb, line 62
def current_user
  @current_user ||= pagerduty.get_users(query: store.get_user(message))
                             .first
end
format_incident(incident) click to toggle source
# File lib/lita/commands/base.rb, line 49
def format_incident(incident)
  assignee = (incident.fetch(:assignments, []).first || {})
             .fetch(:assignee, {})
             .fetch(:summary, 'none')
  {
    message: 'incident.info',
    params: {
      id: incident[:id], subject: incident[:title],
      assigned: assignee.inspect, url: incident[:html_url]
    }
  }
end
format_incidents(incidents) click to toggle source
# File lib/lita/commands/base.rb, line 45
def format_incidents(incidents)
  incidents.map { |incident| format_incident(incident) }
end
format_note(note, incident_id) click to toggle source
# File lib/lita/commands/base.rb, line 34
def format_note(note, incident_id)
  {
    message: 'note.show',
    params: {
      id: incident_id,
      content: note[:content],
      user: note[:user][:summary]
    }
  }
end
format_notes(notes, incident_id) click to toggle source
# File lib/lita/commands/base.rb, line 30
def format_notes(notes, incident_id)
  notes.map { |note| format_note(note, incident_id) }
end
pagerduty() click to toggle source
# File lib/lita/commands/base.rb, line 67
def pagerduty
  @pagerduty ||= ::Pagerduty.new(
    http,
    config.api_key,
    config.email,
    config.teams
  )
end
response(obj) click to toggle source
# File lib/lita/commands/base.rb, line 26
def response(obj)
  @data = obj
end
store() click to toggle source
# File lib/lita/commands/base.rb, line 76
def store
  @store ||= Store.new(redis)
end