Class: Xcov::SlackPoster

Inherits:
Object
  • Object
show all
Defined in:
lib/xcov/slack_poster.rb

Instance Method Summary collapse

Instance Method Details

#run(report) ⇒ Object



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
# File 'lib/xcov/slack_poster.rb', line 5

def run(report)
  return if Xcov.config[:skip_slack]
  return if Xcov.config[:slack_url].nil?

  require 'slack-notifier'
  notifier = Slack::Notifier.new(Xcov.config[:slack_url])
  notifier.username = 'xcov'

  if Xcov.config[:slack_channel].to_s.length > 0
    notifier.channel = Xcov.config[:slack_channel]
    notifier.channel = ('#' + notifier.channel) unless ['#', '@'].include?(notifier.channel[0])
  end

  attachments = []

  report.targets.each do |target|
    attachments << {
      text: "#{target.name}: #{target.displayable_coverage}",
      color: target.coverage_color,
      short: true
    }
  end

  result = notifier.ping "Your *xcov* coverage report",
                         icon_url: 'https://s3-eu-west-1.amazonaws.com/fastlane.tools/fastlane.png',
                         attachments: attachments

  if result.code.to_i == 200
    UI.message 'Successfully sent Slack notification'.green
  else
    UI.message result.to_s.red
  end
end