Class: Fastlane::Actions::SlackUploadAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::SlackUploadAction
- Defined in:
- lib/fastlane/plugin/slack_upload/actions/slack_upload_action.rb
Class Method Summary collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .example_code ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .run(params) ⇒ Object
Class Method Details
.authors ⇒ Object
87 88 89 |
# File 'lib/fastlane/plugin/slack_upload/actions/slack_upload_action.rb', line 87 def self. ['Dawid Cieslak'] end |
.available_options ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/fastlane/plugin/slack_upload/actions/slack_upload_action.rb', line 46 def self. [ FastlaneCore::ConfigItem.new(key: :slack_api_token, env_name: "SLACK_API_TOKEN", sensitive: true, description: "Slack API token"), FastlaneCore::ConfigItem.new(key: :title, env_name: "SLACK_UPLOAD_TITLE", description: "Title of the file", optional: false), FastlaneCore::ConfigItem.new(key: :channel, env_name: "SLACK_UPLOAD_CHANNEL", description: "#channel or @username", optional: false), FastlaneCore::ConfigItem.new(key: :file_path, env_name: "SLACK_UPLOAD_FILE_PATH", description: "Path to the file", optional: false), FastlaneCore::ConfigItem.new(key: :file_type, env_name: "SLACK_UPLOAD_FILE_TYPE", description: "A file type identifier", optional: true), FastlaneCore::ConfigItem.new(key: :file_name, env_name: "SLACK_UPLOAD_FILE_NAME", description: "Filename of file", optional: true), FastlaneCore::ConfigItem.new(key: :initial_comment, env_name: "SLACK_UPLOAD_INITIAL_COMMENT", description: "Initial comment to add to file", optional: true) ] end |
.description ⇒ Object
83 84 85 |
# File 'lib/fastlane/plugin/slack_upload/actions/slack_upload_action.rb', line 83 def self.description 'Uploads given file to Slack' end |
.example_code ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/fastlane/plugin/slack_upload/actions/slack_upload_action.rb', line 91 def self.example_code [ 'slack_upload( title: "New version #{version} is available ", channel: "#general", file_path: "./screenshots.zip" )', 'slack_upload( slack_api_token: "xyz", title: "New version #{version} is available ", channel: "#general", file_path: "./screenshots.zip", file_type: "zip", # Optional, type can be recognized from file path, file_name: "screen_shots.zip", # Optional, name can be recognized from file path, initial_comment: "Enjoy!" # Optional )' ] end |
.is_supported?(platform) ⇒ Boolean
79 80 81 |
# File 'lib/fastlane/plugin/slack_upload/actions/slack_upload_action.rb', line 79 def self.is_supported?(platform) true end |
.run(params) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 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 |
# File 'lib/fastlane/plugin/slack_upload/actions/slack_upload_action.rb', line 5 def self.run(params) require 'slack-ruby-client' title = params[:title] filepath = params[:file_path] filename = params[:file_name] initialComment = params[:initial_comment] if params[:channel].to_s.length > 0 # From `slack` plugin implementation: https://github.com/fastlane/fastlane/blob/master/fastlane/lib/fastlane/actions/slack.rb channel = params[:channel] channel = ('#' + params[:channel]) unless ['#', '@'].include?(channel[0]) # send message to channel by default end if params[:file_type].to_s.empty? filetype = File.extname(filepath)[1..-1] # Remove '.' from the file extension else filetype = params[:file_type] end Slack.configure do |config| config.token = params[:slack_api_token] end client = Slack::Web::Client.new begin results = client.files_upload( channels: channel, as_user: true, file: Faraday::UploadIO.new(filepath, filetype), title: title, filename: filename, initial_comment: initialComment ) rescue => exception UI.error("Exception: #{exception}") ensure UI.success('Successfully sent file to Slack') end end |