Sha256: efe2863841595a3a07a04296ea69fcc3ddd0247efd6a4b0bdc51dfd74c4ebf33

Contents?: true

Size: 1.99 KB

Versions: 67

Compression:

Stored size: 1.99 KB

Contents

require_relative 'module'

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?

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

      require 'slack-notifier'
      notifier = Slack::Notifier.new(Scan.config[:slack_url]) do
        defaults(channel: channel,
                username: 'fastlane')
      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)
      result = result.first

      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

67 entries across 67 versions & 1 rubygems

Version Path
fastlane-2.86.0.beta.20180316050051 scan/lib/scan/slack_poster.rb
fastlane-2.86.0.beta.20180315050105 scan/lib/scan/slack_poster.rb
fastlane-2.86.0.beta.20180314050053 scan/lib/scan/slack_poster.rb
fastlane-2.86.0.beta.20180313050023 scan/lib/scan/slack_poster.rb
fastlane-2.86.0.beta.20180312050111 scan/lib/scan/slack_poster.rb
fastlane-2.86.0.beta.20180311050103 scan/lib/scan/slack_poster.rb
fastlane-2.86.0.beta.20180310050010 scan/lib/scan/slack_poster.rb
fastlane-2.86.0.beta.20180309050025 scan/lib/scan/slack_poster.rb
fastlane-2.85.0 scan/lib/scan/slack_poster.rb
fastlane-2.85.0.beta.20180308050114 scan/lib/scan/slack_poster.rb
fastlane-2.85.0.beta.20180307050101 scan/lib/scan/slack_poster.rb
fastlane-2.85.0.beta.20180306050019 scan/lib/scan/slack_poster.rb
fastlane-2.85.0.beta.20180305050037 scan/lib/scan/slack_poster.rb
fastlane-2.85.0.beta.20180304050031 scan/lib/scan/slack_poster.rb
fastlane-2.85.0.beta.20180303050048 scan/lib/scan/slack_poster.rb
fastlane-2.85.0.beta.20180302050035 scan/lib/scan/slack_poster.rb
fastlane-2.84.0 scan/lib/scan/slack_poster.rb
fastlane-2.84.0.beta.20180301050048 scan/lib/scan/slack_poster.rb
fastlane-2.84.0.beta.20180228050122 scan/lib/scan/slack_poster.rb
fastlane-2.84.0.beta.20180227050054 scan/lib/scan/slack_poster.rb