8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/lita/handlers/docker_hub.rb', line 8
def receive(request, response)
response.["Content-Type"] = "application/json"
body = parse(request.body.read)
repo_name = body.fetch("repository", {}).fetch("repo_name", nil)
repo_url = body.fetch("repository", {}).fetch("repo_url", nil)
tag = body.fetch("push_data", {}).fetch("tag", nil)
if repo_name.present? && repo_url.present? && tag.present?
target = find_room_by_name(config.room)
message = render_template("build", repo_name: repo_name,
tag: tag)
case robot.config.robot.adapter
when :slack
attachment = ::Lita::Adapters::Slack::Attachment.new(message,
title: "Docker Hub",
title_link: repo_url,
color: "#36a64f")
robot.chat_service.send_attachment(target, [attachment])
else
robot.send_message(target, message)
end
response.write("ok")
else
response.write("error")
end
rescue => error
Lita.logger.error error.message
Lita.logger.debug error.backtrace.join("\n")
response.write("error")
end
|