Sha256: 224c64f72af252ea301676fb7473d77f4eaffaab3b048389461293a3a87073f5

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

module Lita
  module Handlers
    class ServerStatus < Handler
      MESSAGE_REGEX = /(.+) is starting deploy of '(.+)' from branch '(.+)' to (.+)/i

      route(MESSAGE_REGEX, :save_status)
      route(/server status/i, :list_statuses, command: true,
            help: { "server status" => "List out the current server statuses." }
      )

      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} @ #{Time.now.to_s})" }

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

      def list_statuses(response)
        message = []
        redis.keys("server_status*").each do |key|
          message << redis.get(key)
        end

        response.reply message.join("\n")
      end
    end

    Lita.register_handler(ServerStatus)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lita-server_status-0.0.1 lib/lita/handlers/server_status.rb