Class: Fastlane::Actions::SlackAction
- Inherits:
-
Fastlane::Action
- Object
- Fastlane::Action
- Fastlane::Actions::SlackAction
- Defined in:
- lib/fastlane/actions/slack.rb
Class Method Summary collapse
- .author ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .run(options) ⇒ Object
-
.trim_message(message) ⇒ Object
As there is a text limit in the notifications, we are usually interested in the last part of the message e.g.
Methods inherited from Fastlane::Action
action_name, authors, details, output, sh, step_text
Class Method Details
.author ⇒ Object
99 100 101 |
# File 'lib/fastlane/actions/slack.rb', line 99 def self. "KrauseFx" end |
.available_options ⇒ Object
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 |
# File 'lib/fastlane/actions/slack.rb', line 59 def self. [ FastlaneCore::ConfigItem.new(key: :message, env_name: "FL_SLACK_MESSAGE", description: "The message that should be displayed on Slack. This supports the standard Slack markup language", optional: true), FastlaneCore::ConfigItem.new(key: :channel, env_name: "FL_SLACK_CHANNEL", description: "#channel or @username", optional: true), FastlaneCore::ConfigItem.new(key: :slack_url, env_name: "SLACK_URL", description: "Create an Incoming WebHook for your Slack group", verify_block: Proc.new do |value| raise "Invalid URL, must start with https://" unless value.start_with?"https://" end), FastlaneCore::ConfigItem.new(key: :payload, env_name: "FL_SLACK_PAYLOAD", description: "Add additional information to this post. payload must be a hash containg any key with any value", default_value: {}, is_string: false), FastlaneCore::ConfigItem.new(key: :default_payloads, env_name: "FL_SLACK_DEFAULT_PAYLOADS", description: "Remove some of the default payloads. More information about the available payloads on GitHub", optional: true, is_string: false), FastlaneCore::ConfigItem.new(key: :attachment_properties, env_name: "FL_SLACK_ATTACHMENT_PROPERTIES", description: "Merge additional properties in the slack attachment, see https://api.slack.com/docs/attachments", default_value: {}, is_string: false), FastlaneCore::ConfigItem.new(key: :success, env_name: "FL_SLACK_SUCCESS", description: "Was this build successful? (true/false)", optional: true, default_value: true, is_string: false), ] end |
.description ⇒ Object
55 56 57 |
# File 'lib/fastlane/actions/slack.rb', line 55 def self.description "Send a success/error message to your Slack group" end |
.is_supported?(platform) ⇒ Boolean
5 6 7 |
# File 'lib/fastlane/actions/slack.rb', line 5 def self.is_supported?(platform) true end |
.run(options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 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 |
# File 'lib/fastlane/actions/slack.rb', line 19 def self.run() require 'slack-notifier' [:message] = self.([:message].to_s || '') [:message] = Slack::Notifier::LinkFormatter.format([: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 [:channel].to_s.length > 0 notifier.channel = [:channel] notifier.channel = ('#' + notifier.channel) unless ['#', '@'].include?(notifier.channel[0]) # send message to channel by default end = () return [notifier, ] if Helper.is_test? # tests will verify the slack attachments and other properties result = notifier.ping '', icon_url: 'https://s3-eu-west-1.amazonaws.com/fastlane.tools/fastlane.png', attachments: [] 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 |
.trim_message(message) ⇒ Object
As there is a text limit in the notifications, we are usually interested in the last part of the message e.g. for tests
12 13 14 15 16 17 |
# File 'lib/fastlane/actions/slack.rb', line 12 def self.() # We want the last 7000 characters, instead of the first 7000, as the error is at the bottom start_index = [.length - 7000, 0].max = [start_index..-1] end |