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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/fastlane/actions/slack.rb', line 29
def self.run(params)
options = { message: '',
success: true,
channel: nil
}.merge(params.first || {})
require 'slack-notifier'
color = (options[:success] ? 'good' : 'danger')
options[:message] = options[:message].to_s
options[:message] = Slack::Notifier::LinkFormatter.format(options[:message])
url = ENV['SLACK_URL']
unless url
Helper.log.fatal "Please add 'ENV[\"SLACK_URL\"] = \"https://hooks.slack.com/services/...\"' to your Fastfile's `before_all` section.".red
raise 'No SLACK_URL given.'.red
end
notifier = Slack::Notifier.new url
notifier.username = 'fastlane'
if options[:channel].to_s.length > 0
notifier.channel = options[:channel]
notifier.channel = ('#' + notifier.channel) unless ['#', '@'].include?(notifier.channel[0]) end
test_result = {
fallback: options[:message],
text: options[:message],
color: color,
fields: [
{
title: 'Lane',
value: Actions.lane_context[Actions::SharedValues::LANE_NAME],
short: true
},
{
title: 'Test Result',
value: (options[:success] ? 'Success' : 'Error'),
short: true
}
]
}
if git_branch
test_result[:fields] << {
title: 'Git Branch',
value: git_branch,
short: true
}
end
if git_author
if ENV['FASTLANE_SLACK_HIDE_AUTHOR_ON_SUCCESS'] and options[:success]
else
test_result[:fields] << {
title: 'Git Author',
value: git_author,
short: true
}
end
end
if last_git_commit
test_result[:fields] << {
title: 'Git Commit',
value: last_git_commit,
short: false
}
end
result = notifier.ping '',
icon_url: 'https://s3-eu-west-1.amazonaws.com/fastlane.tools/fastlane.png',
attachments: [test_result]
unless result.code.to_i == 200
Helper.log.debug result
raise 'Error pushing Slack message, maybe the integration has no permission to post on this channel? Try removing the channel parameter in your Fastfile.'.red
else
Helper.log.info 'Successfully sent Slack notification'.green
end
end
|