flowdock_service.rb
1.47 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
54
55
56
57
if defined? Flowdock
class NotificationServices::FlowdockService < NotificationService
LABEL = 'flowdock'
FIELDS += [
[
:api_token, {
label: 'Flow API Token',
placeholder: '123456789abcdef123456789abcdefgh'
}
]
]
def check_params
if FIELDS.any? { |f, _| self[f].blank? }
errors.add :base, 'You must specify your Flowdock(Flow) API token'
end
end
def url
'https://www.flowdock.com/session'
end
def create_notification(problem)
flow = Flowdock::Flow.new(
api_token: api_token,
source: "Errbit",
from: {
name: "Errbit",
address: ENV['ERRBIT_EMAIL_FROM'] || 'support@flowdock.com'
}
)
subject = "[#{problem.environment}] #{problem.message.to_s.truncate(100)}"
url = app_problem_url problem.app, problem
flow.push_to_team_inbox(
subject: subject,
content: content(problem, url),
project: project_name(problem),
link: url
)
end
private
# can only contain alphanumeric characters and underscores
def project_name(problem)
problem.app.name.gsub(/[^0-9a-z_]/i, '')
end
def content(problem, url)
full_description = "[#{problem.environment}][#{problem.where}] #{problem.message}"
<<-MSG.strip_heredoc
#{ERB::Util.html_escape full_description}<br>
<a href="#{url}">#{url}</a>
MSG
end
end
end