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
- .git_author ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .last_git_commit ⇒ Object
- .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, details, output, sh
Class Method Details
.author ⇒ Object
108 109 110 |
# File 'lib/fastlane/actions/slack.rb', line 108 def self. "KrauseFx" end |
.available_options ⇒ Object
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 98 99 100 101 102 103 104 105 106 |
# File 'lib/fastlane/actions/slack.rb', line 73 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: :success, env_name: "FL_SLACK_SUCCESS", description: "Was this build successful? (true/false)", optional: true, default_value: true, is_string: false), ] end |
.description ⇒ Object
69 70 71 |
# File 'lib/fastlane/actions/slack.rb', line 69 def self.description "Send a success/error message to your Slack group" end |
.git_author ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/fastlane/actions/slack.rb', line 4 def self. s = `git log --name-status HEAD^..HEAD` s = s.match(/Author:.*<(.*)>/)[1] return s if s.to_s.length > 0 return nil rescue return nil end |
.is_supported?(platform) ⇒ Boolean
19 20 21 |
# File 'lib/fastlane/actions/slack.rb', line 19 def self.is_supported?(platform) true end |
.last_git_commit ⇒ Object
13 14 15 16 17 |
# File 'lib/fastlane/actions/slack.rb', line 13 def self.last_git_commit s = `git log -1 --pretty=%B`.strip return s if s.to_s.length > 0 nil end |
.run(options) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/fastlane/actions/slack.rb', line 33 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
26 27 28 29 30 31 |
# File 'lib/fastlane/actions/slack.rb', line 26 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 |