-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcd-bot.rb
More file actions
54 lines (44 loc) · 1.44 KB
/
cd-bot.rb
File metadata and controls
54 lines (44 loc) · 1.44 KB
1
2
3
4
5
6
7
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
46
47
48
49
50
51
52
53
require 'json'
require 'net/http'
require 'uri'
require 'time'
def lambda_handler(event:, context:)
detail = event['detail']
pipeline = detail['pipeline']
stage = detail['stage']
state = detail['state']
region = event['region']
kst_time = Time.now.getlocal('+09:00').strftime("%Y-%m-%d %H:%M:%S KST")
color = case state
when 'Succeeded' then 0x2ECC71 # 초록
when 'Failed' then 0xE74C3C # 빨강
when 'InProgress'then 0x3498DB # 파랑
else 0x95A5A6 # 회색
end
embed = {
title: "CodePipeline Stage 업데이트",
description: "**Pipeline:** `#{pipeline}`\n" \
"**Stage:** `#{stage}`\n" \
"**State:** `#{state}`",
color: color,
footer: {
text: "AWS Region: #{region} | #{kst_time}"
}
}
webhook_url = ENV['DISCORD_WEBHOOK_URL']
uri = URI.parse(webhook_url)
header = { 'Content-Type': 'application/json' }
payload = {
content:"<@&1315864971426529281>,
username: "AWS CodePipeline Notifier",
avatar_url: "https://a0.awsstatic.com/libra-css/images/logos/aws_logo_smile_1200x630.png",
embeds: [embed]
}
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri, header)
request.body = payload.to_json
response = http.request(request)
puts "Discord 응답 코드: #{response.code}"
{ statusCode: 200, body: 'Success' }
end