-
Notifications
You must be signed in to change notification settings - Fork 0
/
slack_client.rb
54 lines (41 loc) · 989 Bytes
/
slack_client.rb
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
54
require_relative 'api_client.rb'
class SlackClient
include ApiClient
ENDPOINT = "#{ENV.fetch('SLACK_ENDPOINT')}".freeze
def initialize(gmud_hash)
@gmud_hash = gmud_hash
end
def call
return unless gmud_hash
post_notification(
'https://hooks.slack.com/services/',
ENDPOINT,
{ 'text': slack_message }.to_json
)
end
private
attr_reader :gmud_hash
def slack_message
if gmud_hash[:changes].empty? || gmud_hash[:riskiness].empty?
raw_template
else
full_template
end
end
def raw_template
<<-SLACK_MESSAGE
<#{gmud_hash[:link]}|*#{gmud_hash[:repository]} - GMUD #{gmud_hash[:number]}*>
*O que mudou* :repeat:
#{gmud_hash[:raw_description]}
SLACK_MESSAGE
end
def full_template
<<-SLACK_MESSAGE
<#{gmud_hash[:link]}|*#{gmud_hash[:repository]} - GMUD #{gmud_hash[:number]}*>
*O que mudou* :repeat:
#{gmud_hash[:changes]}
*Riscos* :warning:
#{gmud_hash[:riskiness]}
SLACK_MESSAGE
end
end