Sha256: 857819568334ab6a764fdb4270a7c47ea2d72df5330a8028c26112f8b635785e

Contents?: true

Size: 1.92 KB

Versions: 378

Compression:

Stored size: 1.92 KB

Contents

module Scan
  class SlackPoster
    def run(results)
      return if Scan.config[:skip_slack]
      return if Scan.config[:slack_only_on_failure] && results[:failures] == 0
      return if Scan.config[:slack_url].to_s.empty?

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

      if Scan.config[:slack_channel].to_s.length > 0
        notifier.channel = Scan.config[:slack_channel]
        notifier.channel = ('#' + notifier.channel) unless ['#', '@'].include?(notifier.channel[0]) # send message to channel by default
      end

      attachments = []

      if Scan.config[:slack_message]
        attachments << {
          text: Scan.config[:slack_message].to_s,
          color: "good"
        }
      end

      attachments << {
        text: "Build Errors: #{results[:build_errors] || 0}",
        color: results[:build_errors].to_i > 0 ? "danger" : "good",
        short: true
      }

      if results[:failures]
        attachments << {
          text: "Test Failures: #{results[:failures]}",
          color: results[:failures].to_i > 0 ? "danger" : "good",
          short: true
        }
      end

      if results[:tests] and results[:failures]
        attachments << {
          text: "Successful Tests: #{results[:tests] - results[:failures]}",
          color: "good",
          short: true
        }
      end

      result = notifier.ping "#{Scan.project.app_name} Tests:",
                             icon_url: 'https://s3-eu-west-1.amazonaws.com/fastlane.tools/fastlane.png',
                             attachments: attachments

      if result.code.to_i == 200
        UI.success('Successfully sent Slack notification')
      elsif result.code.to_i == 404
        UI.error("The Slack URL you provided could not be reached (404)")
      else
        UI.error("The Slack notification could not be sent:")
        UI.error(result.to_s)
      end
    end
  end
end

Version data entries

378 entries across 378 versions & 1 rubygems

Version Path
fastlane-2.65.0.beta.20171107010003 scan/lib/scan/slack_poster.rb
fastlane-2.64.0 scan/lib/scan/slack_poster.rb
fastlane-2.64.0.beta.20171106010003 scan/lib/scan/slack_poster.rb
fastlane-2.64.0.beta.20171105010003 scan/lib/scan/slack_poster.rb
fastlane-2.64.0.beta.20171104010004 scan/lib/scan/slack_poster.rb
fastlane-2.64.0.beta.20171103010004 scan/lib/scan/slack_poster.rb
fastlane-2.64.0.beta.20171102010003 scan/lib/scan/slack_poster.rb
fastlane-2.64.0.beta.20171101010004 scan/lib/scan/slack_poster.rb
fastlane-2.63.0 scan/lib/scan/slack_poster.rb
fastlane-2.63.0.beta.20171031010003 scan/lib/scan/slack_poster.rb
fastlane-2.63.0.beta.20171030010003 scan/lib/scan/slack_poster.rb
fastlane-2.63.0.beta.20171029010003 scan/lib/scan/slack_poster.rb
fastlane-2.63.0.beta.20171028010003 scan/lib/scan/slack_poster.rb
fastlane-2.63.0.beta.20171027010003 scan/lib/scan/slack_poster.rb
fastlane-2.63.0.beta.20171026010003 scan/lib/scan/slack_poster.rb
fastlane-2.63.0.beta.20171025010003 scan/lib/scan/slack_poster.rb
fastlane-2.63.0.beta.20171024010003 scan/lib/scan/slack_poster.rb
fastlane-2.62.1 scan/lib/scan/slack_poster.rb
fastlane-2.63.0.beta.20171023010003 scan/lib/scan/slack_poster.rb
fastlane-2.63.0.beta.20171022010003 scan/lib/scan/slack_poster.rb