Sha256: 330ec1aec77b18dc8143d68a498e56b1135c03b57f407cf25e85349e79d4679c

Contents?: true

Size: 1.34 KB

Versions: 18

Compression:

Stored size: 1.34 KB

Contents

module Xcov
  class SlackPoster

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

      require 'slack-notifier'

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

      notifier = Slack::Notifier.new(url, channel: channel, username: username)

      attachments = []

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

      begin
        message = Slack::Notifier::Util::LinkFormatter.format(Xcov.config[:slack_message])
        results = notifier.ping(
          message,
          icon_url: 'https://s3-eu-west-1.amazonaws.com/fastlane.tools/fastlane.png',
          attachments: attachments
        )

        if !results.first.nil? && results.first.code.to_i == 200
          UI.message 'Successfully sent Slack notification'.green
        else
          UI.error "xcov failed to upload results to slack"
        end

      rescue Exception => e
        UI.error "xcov failed to upload results to slack. error: #{e.to_s}"
      end
    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
xcov-1.8.1 lib/xcov/slack_poster.rb
xcov-1.8.0 lib/xcov/slack_poster.rb
xcov-1.7.5 lib/xcov/slack_poster.rb
xcov-1.7.4 lib/xcov/slack_poster.rb
xcov-1.7.3 lib/xcov/slack_poster.rb
xcov-1.7.2 lib/xcov/slack_poster.rb
xcov-1.7.1 lib/xcov/slack_poster.rb
xcov-1.7.0 lib/xcov/slack_poster.rb
xcov-1.6.0 lib/xcov/slack_poster.rb
xcov-1.5.1 lib/xcov/slack_poster.rb
xcov-1.5.0 lib/xcov/slack_poster.rb
xcov-1.4.3 lib/xcov/slack_poster.rb
xcov-1.4.2 lib/xcov/slack_poster.rb
xcov-1.4.1 lib/xcov/slack_poster.rb
xcov-1.4.0 lib/xcov/slack_poster.rb
xcov-1.3.5 lib/xcov/slack_poster.rb
xcov-1.3.4 lib/xcov/slack_poster.rb
xcov-1.3.3 lib/xcov/slack_poster.rb