Class: Lita::Handlers::ServerStatus

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/server_status.rb

Constant Summary collapse

MESSAGE_REGEX =
%r/(?::eyes:\s)*(.+) is deploying (.+)\/(.+) to (.+)/i

Instance Method Summary collapse

Instance Method Details

#formatted_timeObject



30
31
32
# File 'lib/lita/handlers/server_status.rb', line 30

def formatted_time
  Time.now.strftime('%Y-%m-%d %H:%M')
end

#list_statuses(response) ⇒ Object



20
21
22
# File 'lib/lita/handlers/server_status.rb', line 20

def list_statuses(response)
  response.reply status_message
end

#save_status(response) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/lita/handlers/server_status.rb', line 11

def save_status(response)
  message = response.message.body
  user, application, branch, environment = message.match(MESSAGE_REGEX).captures
  apply_status = { id: "#{application}:#{environment}",
                   message: "#{application} #{environment}: #{branch} (#{user} @ #{formatted_time})" }

  redis.set("server_status:#{apply_status[:id]}", apply_status[:message])
end

#status_messageObject



24
25
26
27
28
# File 'lib/lita/handlers/server_status.rb', line 24

def status_message
  messages = redis.keys('server_status*').sort.map { |key| redis.get(key) }
  messages << 'I don\'t know what state the servers are in.' if messages.empty?
  messages.join("\n")
end