Module: Commands::Base

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
# 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

Instance Method Details

#current_userObject



62
63
64
65
# 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) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# 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) ⇒ Object



45
46
47
# File 'lib/lita/commands/base.rb', line 45

def format_incidents(incidents)
  incidents.map { |incident| format_incident(incident) }
end

#format_note(note, incident_id) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# 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) ⇒ Object



30
31
32
# File 'lib/lita/commands/base.rb', line 30

def format_notes(notes, incident_id)
  notes.map { |note| format_note(note, incident_id) }
end

#initialize(message, pagerduty, store) ⇒ Object



19
20
21
22
23
24
# File 'lib/lita/commands/base.rb', line 19

def initialize(message, pagerduty, store)
  @message = message
  @pagerduty = pagerduty
  @store = store
  @data = nil
end

#pagerdutyObject



67
68
69
70
71
72
73
74
# File 'lib/lita/commands/base.rb', line 67

def pagerduty
  @pagerduty ||= ::Pagerduty.new(
    http,
    config.api_key,
    config.email,
    config.teams
  )
end

#response(obj) ⇒ Object



26
27
28
# File 'lib/lita/commands/base.rb', line 26

def response(obj)
  @data = obj
end

#storeObject



76
77
78
# File 'lib/lita/commands/base.rb', line 76

def store
  @store ||= Store.new(redis)
end