Class: Fastlane::Actions::SlackAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/slack.rb

Defined Under Namespace

Classes: Runner

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Helper collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, deprecated_notes, lane_context, method_missing, other_action, output, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorObject



260
261
262
# File 'fastlane/lib/fastlane/actions/slack.rb', line 260

def self.author
  "KrauseFx"
end

.available_optionsObject



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'fastlane/lib/fastlane/actions/slack.rb', line 183

def self.available_options
  [
    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: :pretext,
                                 env_name: "FL_SLACK_PRETEXT",
                                 description: "This is optional text that appears above the message attachment block. 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: :use_webhook_configured_username_and_icon,
                                 env_name: "FL_SLACK_USE_WEBHOOK_CONFIGURED_USERNAME_AND_ICON",
                                 description: "Use webhook's default username and icon settings? (true/false)",
                                 default_value: false,
                                 type: Boolean,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :slack_url,
                                 env_name: "SLACK_URL",
                                 sensitive: true,
                                 description: "Create an Incoming WebHook for your Slack group",
                                 verify_block: proc do |value|
                                   UI.user_error!("Invalid URL, must start with https://") unless value.start_with?("https://")
                                 end),
    FastlaneCore::ConfigItem.new(key: :username,
                                 env_name: "FL_SLACK_USERNAME",
                                 description: "Overrides the webhook's username property if use_webhook_configured_username_and_icon is false",
                                 default_value: "fastlane",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :icon_url,
                                 env_name: "FL_SLACK_ICON_URL",
                                 description: "Specifies a URL of an image to use as the photo of the message. Overrides the webhook's image property if use_webhook_configured_username_and_icon is false",
                                 default_value: "https://fastlane.tools/assets/img/fastlane_icon.png",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :icon_emoji,
                                 env_name: "FL_SLACK_ICON_EMOJI",
                                 description: "Specifies an emoji (using colon shortcodes, eg. :white_check_mark:) to use as the photo of the message. Overrides the webhook's image property if use_webhook_configured_username_and_icon is false. This parameter takes precedence over icon_url",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :payload,
                                 env_name: "FL_SLACK_PAYLOAD",
                                 description: "Add additional information to this post. payload must be a hash containing any key with any value",
                                 default_value: {},
                                 type: Hash),
    FastlaneCore::ConfigItem.new(key: :default_payloads,
                                 env_name: "FL_SLACK_DEFAULT_PAYLOADS",
                                 description: "Specifies default payloads to include. Pass an empty array to suppress all the default payloads",
                                 default_value: ['lane', 'test_result', 'git_branch', 'git_author', 'last_git_commit', 'last_git_commit_hash'],
                                 type: Array),
    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: {},
                                 type: Hash),
    FastlaneCore::ConfigItem.new(key: :success,
                                 env_name: "FL_SLACK_SUCCESS",
                                 description: "Was this build successful? (true/false)",
                                 optional: true,
                                 default_value: true,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :fail_on_error,
                                 env_name: "FL_SLACK_FAIL_ON_ERROR",
                                 description: "Should an error sending the slack notification cause a failure? (true/false)",
                                 optional: true,
                                 default_value: true,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :link_names,
                                 env_name: "FL_SLACK_LINK_NAMES",
                                 description: "Find and link channel names and usernames (true/false)",
                                 optional: true,
                                 default_value: false,
                                 type: Boolean)
  ]
end

.categoryObject



289
290
291
# File 'fastlane/lib/fastlane/actions/slack.rb', line 289

def self.category
  :notifications
end

.descriptionObject



179
180
181
# File 'fastlane/lib/fastlane/actions/slack.rb', line 179

def self.description
  "Send a success/error message to your [Slack](https://slack.com) group"
end

.detailsObject



293
294
295
# File 'fastlane/lib/fastlane/actions/slack.rb', line 293

def self.details
  "Create an Incoming WebHook and export this as `SLACK_URL`. Can send a message to **#channel** (by default), a direct message to **@username** or a message to a private group **group** with success (green) or failure (red) status."
end

.example_codeObject



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'fastlane/lib/fastlane/actions/slack.rb', line 264

def self.example_code
  [
    'slack(message: "App successfully released!")',
    'slack(
      message: "App successfully released!",
      channel: "#channel",  # Optional, by default will post to the default channel configured for the POST URL.
      success: true,        # Optional, defaults to true.
      payload: {            # Optional, lets you specify any number of your own Slack attachments.
        "Build Date" => Time.new.to_s,
        "Built by" => "Jenkins",
      },
      default_payloads: [:git_branch, :git_author], # Optional, lets you specify default payloads to include. Pass an empty array to suppress all the default payloads.
      attachment_properties: { # Optional, lets you specify any other properties available for attachments in the slack API (see https://api.slack.com/docs/attachments).
                               # This hash is deep merged with the existing properties set using the other properties above. This allows your own fields properties to be appended to the existing fields that were created using the `payload` property for instance.
        thumb_url: "http://example.com/path/to/thumb.png",
        fields: [{
          title: "My Field",
          value: "My Value",
          short: true
        }]
      }
    )'
  ]
end

.generate_slack_attachments(options) ⇒ Object



305
306
307
308
# File 'fastlane/lib/fastlane/actions/slack.rb', line 305

def self.generate_slack_attachments(options)
  UI.deprecated('`Fastlane::Actions::Slack.generate_slack_attachments` is subject to be removed as Slack recommends migrating `attachments` to Block Kit. fastlane will also follow the same direction.')
  Runner.generate_slack_attachments(options)
end

.is_supported?(platform) ⇒ Boolean

Returns:



171
172
173
# File 'fastlane/lib/fastlane/actions/slack.rb', line 171

def self.is_supported?(platform)
  true
end

.run(options) ⇒ Object



175
176
177
# File 'fastlane/lib/fastlane/actions/slack.rb', line 175

def self.run(options)
  Runner.new(options[:slack_url]).run(options)
end

.trim_message(message) ⇒ Object



301
302
303
# File 'fastlane/lib/fastlane/actions/slack.rb', line 301

def self.trim_message(message)
  Runner.trim_message(message)
end