Class: Fastlane::Actions::RocketChatAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::RocketChatAction
- Defined in:
- lib/fastlane/plugin/rocket_chat/actions/rocket_chat.rb
Helper collapse
-
.deep_merge(a, b) ⇒ Object
Adapted from stackoverflow.com/a/30225093/158525.
- .generate_attachments(options) ⇒ Object
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.
Class Method Details
.author ⇒ Object
111 112 113 |
# File 'lib/fastlane/plugin/rocket_chat/actions/rocket_chat.rb', line 111 def self. "thiagofelix" end |
.available_options ⇒ Object
56 57 58 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 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/fastlane/plugin/rocket_chat/actions/rocket_chat.rb', line 56 def self. [ FastlaneCore::ConfigItem.new(key: :message, env_name: "FL_ROCKET_CHAT_MESSAGE", description: "The message that should be displayed on Rocket.Chat. This supports the standard Rocket.Chat markup language", optional: true), FastlaneCore::ConfigItem.new(key: :channel, env_name: "FL_ROCKET_CHAT_CHANNEL", description: "#channel or @username", optional: true), FastlaneCore::ConfigItem.new(key: :use_webhook_configured_username_and_icon, env_name: "FL_ROCKET_CHAT_USE_WEBHOOK_CONFIGURED_USERNAME_AND_ICON", description: "Use webook's default username and icon settings? (true/false)", default_value: false, is_string: false, optional: true), FastlaneCore::ConfigItem.new(key: :rocket_chat_url, env_name: "ROCKET_CHAT_URL", description: "Create an Incoming WebHook for your Rocket.Chat group"), FastlaneCore::ConfigItem.new(key: :username, env_name: "FL_ROCKET_CHAT_USERNAME", description: "Overrides the webook's username property if use_webhook_configured_username_and_icon is false", default_value: "fastlane", is_string: true, optional: true), FastlaneCore::ConfigItem.new(key: :icon_url, env_name: "FL_ROCKET_CHAT_ICON_URL", description: "Overrides the webook's image property if use_webhook_configured_username_and_icon is false", default_value: "https://s3-eu-west-1.amazonaws.com/fastlane.tools/fastlane.png", is_string: true, optional: true), FastlaneCore::ConfigItem.new(key: :payload, env_name: "FL_ROCKET_CHAT_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_ROCKET_CHAT_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_ROCKET_CHAT_ATTACHMENT_PROPERTIES", description: "Merge additional properties in the Rocket.Chat attachment", default_value: {}, is_string: false), FastlaneCore::ConfigItem.new(key: :success, env_name: "FL_ROCKET_CHAT_SUCCESS", description: "Was this build successful? (true/false)", optional: true, default_value: true, is_string: false) ] end |
.deep_merge(a, b) ⇒ Object
Adapted from stackoverflow.com/a/30225093/158525
187 188 189 190 191 192 193 194 |
# File 'lib/fastlane/plugin/rocket_chat/actions/rocket_chat.rb', line 187 def self.deep_merge(a, b) merger = proc do |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : Array === v1 && Array === v2 ? v1 | v2 : [:undefined, nil, :nil].include?(v2) ? v1 : v2 end a.merge(b, &merger) end |
.description ⇒ Object
52 53 54 |
# File 'lib/fastlane/plugin/rocket_chat/actions/rocket_chat.rb', line 52 def self.description "Send a success/error message to your RocketChat group" end |
.generate_attachments(options) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/fastlane/plugin/rocket_chat/actions/rocket_chat.rb', line 119 def self.() color = ([:success] ? 'good' : 'danger') should_add_payload = ->(payload_name) { [:default_payloads].nil? || [:default_payloads].include?(payload_name) } = { fallback: [:message], text: [:message], color: color, mrkdwn_in: ["pretext", "text", "fields", "message"], fields: [] } # custom user payloads [:fields] += [:payload].map do |k, v| { title: k.to_s, value: v.to_s } end # Add the lane to the Rocket.Chat message # This might be nil, if Rocket.Chat is called as "one-off" action if should_add_payload[:lane] && Actions.lane_context[Actions::SharedValues::LANE_NAME] [:fields] << { title: 'Lane', value: Actions.lane_context[Actions::SharedValues::LANE_NAME] } end # test_result if should_add_payload[:test_result] [:fields] << { title: 'Result', value: ([:success] ? 'Success' : 'Error') } end # git branch if Actions.git_branch && should_add_payload[:git_branch] [:fields] << { title: 'Git Branch', value: Actions.git_branch } end # git_author if Actions. && should_add_payload[:git_author] unless ENV['FASTLANE_ROCKET_CHAT_HIDE_AUTHOR_ON_SUCCESS'] && [:success] [:fields] << { title: 'Git Author', value: Actions. } end end # last_git_commit if Actions. && should_add_payload[:last_git_commit] [:fields] << { title: 'Git Commit', value: Actions. } end # merge additional properties deep_merge(, [:attachment_properties]) end |
.is_supported?(platform) ⇒ Boolean
7 8 9 |
# File 'lib/fastlane/plugin/rocket_chat/actions/rocket_chat.rb', line 7 def self.is_supported?(platform) true end |
.run(options) ⇒ Object
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 |
# File 'lib/fastlane/plugin/rocket_chat/actions/rocket_chat.rb', line 21 def self.run() require 'rocket-chat-notifier' [:message] = self.([:message].to_s || '') notifier = ::RocketChat::Notifier.new([:rocket_chat_url]) notifier.username = [:use_webhook_configured_username_and_icon] ? nil : [:username] icon_url = [:use_webhook_configured_username_and_icon] ? nil : [:icon_url] 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 rocket chat attachments and other properties result = notifier.ping '', icon_url: icon_url, attachments: [] if result.code.to_i == 200 UI.success('Successfully sent RocketChat notification') else UI.verbose(result) UI.user_error!("Error pushing RocketChat message, maybe the integration has no permission to post on this channel? Try removing the channel parameter in your Fastfile.") 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
14 15 16 17 18 19 |
# File 'lib/fastlane/plugin/rocket_chat/actions/rocket_chat.rb', line 14 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 |