50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/highway/steps/library/slack.rb', line 50
def self.run(parameters:, context:, report:)
username = parameters["username"]
webhook = parameters["webhook"].to_s
avatar_emoji = parameters["avatar"][:value] if parameters["avatar"]&[:tag] == :emoji
avatar_url = parameters["avatar"][:value].to_s if parameters["avatar"]&[:tag] == :url
attachments = [
generate_build_attachments(context),
generate_tests_attachments(context),
generate_deployment_attachments(context),
]
attachments = attachments.flatten.compact
attachments.each { |attachment|
attachment[:mrkdwn_in] = [:text, :fields]
attachment[:fallback] ||= attachment.fetch(:fields, []).reduce([]) { |memo, field| memo + ["#{field[:title]}: #{field[:value]}."] }.join(" ")
}
attachments.each { |attachment|
attachment[:fields].each { |field| field[:value] = Slack::Notifier::Util::LinkFormatter.format(field[:value]) }
attachment[:fallback] = Slack::Notifier::Util::LinkFormatter.format(attachment[:fallback])
}
notifier = Slack::Notifier.new(webhook)
notifier.post({
username: username,
icon_emoji: avatar_emoji,
icon_url: avatar_url,
attachments: attachments,
})
context.interface.success("Successfully posted a report message on Slack.")
end
|