Class: Lita::Handlers::GitlabCi

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_config(config) ⇒ Object



5
6
7
# File 'lib/lita/handlers/gitlab_ci.rb', line 5

def self.default_config(config)
  config.rooms = %w(#general)
end

Instance Method Details

#webhook(request, response) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lita/handlers/gitlab_ci.rb', line 11

def webhook(request, response)
  data = parse_json(request.body)

  # Build Information
  project_name = data["project_name"]
  build_status = data["build_status"]
  build_date = Time.parse(data["build_started_at"]) # UTC Time
  branch = data["ref"]

  message_body = "#{project_name} (#{branch}) build on #{build_date} and #{build_status}."

  rooms = Lita.config.handlers.gitlab_ci.rooms
  rooms.each do |room|
    target = Source.new(room: room)
    robot.send_message(target, message_body)
  end

  response.body << message_body
end