fastlane-plugin-rocket_chat 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7ef717c02e6634f56cf7d28609e9157b9000e79f
4
+ data.tar.gz: e1a935a869bd90115da2cc5d0d431b7241791d18
5
+ SHA512:
6
+ metadata.gz: 4c5a1305f71883b5cb25d2230358510287833096c483219c2a7eccea04bcab7666d1761e6bd4601e674b1402efb4cbd7cd44cb6a33601c762c8665da2e251833
7
+ data.tar.gz: d314f3500cda97c38846edc60e27071e30c1ab5d1a68dca7ebeb5fbc4ac693b7bc9b51b789e28a478ad265a0844a8be4bd6d8895ed0a6d1ef8e045bf3ece43a3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Pavel Procházka <pprochazka72@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,72 @@
1
+ # rocket_chat plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-rocket_chat)
4
+ [![Build Status](https://travis-ci.org/thiagofelix/fastlane-plugin-rocket_chat.svg?branch=master)](https://travis-ci.org/thiagofelix/fastlane-plugin-rocket_chat)
5
+ [![Code Climate](https://codeclimate.com/github/thiagofelix/fastlane-plugin-rocket_chat/badges/gpa.svg)](https://codeclimate.com/github/thiagofelix/fastlane-plugin-rocket_chat)
6
+
7
+ ## Getting Started
8
+
9
+ This project is a [fastlane](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-rocket_chat`, add it to your project by running:
10
+
11
+ ```bash
12
+ fastlane add_plugin rocket_chat
13
+ ```
14
+
15
+ ### About [RocketChat](http://rocket.chat)
16
+ Create an Incoming WebHook and export this as `ROCKET_CHAT_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.
17
+
18
+ ## Example
19
+ ```ruby
20
+ rocket_chat(
21
+ message: "App successfully released!"
22
+ )
23
+
24
+ rocket_chat(
25
+ message: "App successfully released!",
26
+ channel: "#channel", # Optional, by default will post to the default channel configured for the POST URL.
27
+ success: true, # Optional, defaults to true.
28
+ payload: { # Optional, lets you specify any number of your own Rocket.Chat attachments.
29
+ 'Build Date' => Time.new.to_s,
30
+ 'Built by' => 'Jenkins',
31
+ },
32
+ default_payloads: [:git_branch, :git_author], # Optional, lets you specify a whitelist of default payloads to include. Pass an empty array to suppress all the default payloads. Don't add this key, or pass nil, if you want all the default payloads. The available default payloads are: `lane`, `test_result`, `git_branch`, `git_author`, `last_git_commit_message`.
33
+ attachment_properties: { # Optional, lets you specify any other properties available for 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.
34
+ thumb_url: 'http://example.com/path/to/thumb.png',
35
+ fields: [{
36
+ title: 'My Field',
37
+ value: 'My Value'
38
+ }]
39
+ }
40
+ )
41
+ ```
42
+
43
+ ## Issues and Feedback
44
+
45
+ For any other issues and feedback about this plugin, please submit it to this repository.
46
+
47
+ ## Troubleshooting
48
+
49
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://github.com/fastlane/fastlane/blob/master/fastlane/docs/PluginsTroubleshooting.md) doc in the main `fastlane` repo.
50
+
51
+ ## Using `fastlane` Plugins
52
+
53
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Plugins.md).
54
+
55
+ ## About `fastlane`
56
+
57
+ `fastlane` is the easiest way to automate building and releasing your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
58
+
59
+ Contributing
60
+ ------------
61
+
62
+ If there is any thing you'd like to contribute or fix, please:
63
+
64
+ - Fork the repo
65
+ - Add tests for any new functionality
66
+ - Make your changes
67
+ - Verify all new & existing tests pass
68
+ - Make a pull request
69
+
70
+ License
71
+ -------
72
+ The rocket-chat-notifier gem is distributed under the MIT License.
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/rocket_chat/version'
2
+
3
+ module Fastlane
4
+ module RocketChat
5
+ # Return all .rb files inside the "actions" and "helper" directory
6
+ def self.all_classes
7
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
+ end
9
+ end
10
+ end
11
+
12
+ # By default we want to import all available actions and helpers
13
+ # A plugin can contain any number of actions and plugins
14
+ Fastlane::RocketChat.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,200 @@
1
+ # rubocop:disable Style/CaseEquality
2
+ # rubocop:disable Style/MultilineTernaryOperator
3
+ # rubocop:disable Style/NestedTernaryOperator
4
+ module Fastlane
5
+ module Actions
6
+ class RocketChatAction < Action
7
+ def self.is_supported?(platform)
8
+ true
9
+ end
10
+
11
+ # As there is a text limit in the notifications, we are
12
+ # usually interested in the last part of the message
13
+ # e.g. for tests
14
+ def self.trim_message(message)
15
+ # We want the last 7000 characters, instead of the first 7000, as the error is at the bottom
16
+ start_index = [message.length - 7000, 0].max
17
+ message = message[start_index..-1]
18
+ message
19
+ end
20
+
21
+ def self.run(options)
22
+ require 'rocket-chat-notifier'
23
+
24
+ options[:message] = self.trim_message(options[:message].to_s || '')
25
+
26
+ notifier = ::RocketChat::Notifier.new(options[:rocket_chat_url])
27
+
28
+ notifier.username = options[:use_webhook_configured_username_and_icon] ? nil : options[:username]
29
+ icon_url = options[:use_webhook_configured_username_and_icon] ? nil : options[:icon_url]
30
+
31
+ if options[:channel].to_s.length > 0
32
+ notifier.channel = options[:channel]
33
+ notifier.channel = ('#' + notifier.channel) unless ['#', '@'].include?(notifier.channel[0]) # send message to channel by default
34
+ end
35
+
36
+ attachment = generate_attachments(options)
37
+
38
+ return [notifier, attachment] if Helper.is_test? # tests will verify the rocket chat attachments and other properties
39
+
40
+ result = notifier.ping '',
41
+ icon_url: icon_url,
42
+ attachments: [attachment]
43
+
44
+ if result.code.to_i == 200
45
+ UI.success('Successfully sent RocketChat notification')
46
+ else
47
+ UI.verbose(result)
48
+ 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.")
49
+ end
50
+ end
51
+
52
+ def self.description
53
+ "Send a success/error message to your RocketChat group"
54
+ end
55
+
56
+ def self.available_options
57
+ [
58
+ FastlaneCore::ConfigItem.new(key: :message,
59
+ env_name: "FL_ROCKET_CHAT_MESSAGE",
60
+ description: "The message that should be displayed on Rocket.Chat. This supports the standard Rocket.Chat markup language",
61
+ optional: true),
62
+ FastlaneCore::ConfigItem.new(key: :channel,
63
+ env_name: "FL_ROCKET_CHAT_CHANNEL",
64
+ description: "#channel or @username",
65
+ optional: true),
66
+ FastlaneCore::ConfigItem.new(key: :use_webhook_configured_username_and_icon,
67
+ env_name: "FL_ROCKET_CHAT_USE_WEBHOOK_CONFIGURED_USERNAME_AND_ICON",
68
+ description: "Use webook's default username and icon settings? (true/false)",
69
+ default_value: false,
70
+ is_string: false,
71
+ optional: true),
72
+ FastlaneCore::ConfigItem.new(key: :rocket_chat_url,
73
+ env_name: "ROCKET_CHAT_URL",
74
+ description: "Create an Incoming WebHook for your Rocket.Chat group"),
75
+ FastlaneCore::ConfigItem.new(key: :username,
76
+ env_name: "FL_ROCKET_CHAT_USERNAME",
77
+ description: "Overrides the webook's username property if use_webhook_configured_username_and_icon is false",
78
+ default_value: "fastlane",
79
+ is_string: true,
80
+ optional: true),
81
+ FastlaneCore::ConfigItem.new(key: :icon_url,
82
+ env_name: "FL_ROCKET_CHAT_ICON_URL",
83
+ description: "Overrides the webook's image property if use_webhook_configured_username_and_icon is false",
84
+ default_value: "https://s3-eu-west-1.amazonaws.com/fastlane.tools/fastlane.png",
85
+ is_string: true,
86
+ optional: true),
87
+ FastlaneCore::ConfigItem.new(key: :payload,
88
+ env_name: "FL_ROCKET_CHAT_PAYLOAD",
89
+ description: "Add additional information to this post. payload must be a hash containg any key with any value",
90
+ default_value: {},
91
+ is_string: false),
92
+ FastlaneCore::ConfigItem.new(key: :default_payloads,
93
+ env_name: "FL_ROCKET_CHAT_DEFAULT_PAYLOADS",
94
+ description: "Remove some of the default payloads. More information about the available payloads on GitHub",
95
+ optional: true,
96
+ is_string: false),
97
+ FastlaneCore::ConfigItem.new(key: :attachment_properties,
98
+ env_name: "FL_ROCKET_CHAT_ATTACHMENT_PROPERTIES",
99
+ description: "Merge additional properties in the Rocket.Chat attachment",
100
+ default_value: {},
101
+ is_string: false),
102
+ FastlaneCore::ConfigItem.new(key: :success,
103
+ env_name: "FL_ROCKET_CHAT_SUCCESS",
104
+ description: "Was this build successful? (true/false)",
105
+ optional: true,
106
+ default_value: true,
107
+ is_string: false)
108
+ ]
109
+ end
110
+
111
+ def self.author
112
+ "thiagofelix"
113
+ end
114
+
115
+ #####################################################
116
+ # @!group Helper
117
+ #####################################################
118
+
119
+ def self.generate_attachments(options)
120
+ color = (options[:success] ? 'good' : 'danger')
121
+ should_add_payload = ->(payload_name) { options[:default_payloads].nil? || options[:default_payloads].include?(payload_name) }
122
+
123
+ attachment = {
124
+ fallback: options[:message],
125
+ text: options[:message],
126
+ color: color,
127
+ mrkdwn_in: ["pretext", "text", "fields", "message"],
128
+ fields: []
129
+ }
130
+
131
+ # custom user payloads
132
+ attachment[:fields] += options[:payload].map do |k, v|
133
+ {
134
+ title: k.to_s,
135
+ value: v.to_s
136
+ }
137
+ end
138
+
139
+ # Add the lane to the Rocket.Chat message
140
+ # This might be nil, if Rocket.Chat is called as "one-off" action
141
+ if should_add_payload[:lane] && Actions.lane_context[Actions::SharedValues::LANE_NAME]
142
+ attachment[:fields] << {
143
+ title: 'Lane',
144
+ value: Actions.lane_context[Actions::SharedValues::LANE_NAME]
145
+ }
146
+ end
147
+
148
+ # test_result
149
+ if should_add_payload[:test_result]
150
+ attachment[:fields] << {
151
+ title: 'Result',
152
+ value: (options[:success] ? 'Success' : 'Error')
153
+ }
154
+ end
155
+
156
+ # git branch
157
+ if Actions.git_branch && should_add_payload[:git_branch]
158
+ attachment[:fields] << {
159
+ title: 'Git Branch',
160
+ value: Actions.git_branch
161
+ }
162
+ end
163
+
164
+ # git_author
165
+ if Actions.git_author_email && should_add_payload[:git_author]
166
+ unless ENV['FASTLANE_ROCKET_CHAT_HIDE_AUTHOR_ON_SUCCESS'] && options[:success]
167
+ attachment[:fields] << {
168
+ title: 'Git Author',
169
+ value: Actions.git_author_email
170
+ }
171
+ end
172
+ end
173
+
174
+ # last_git_commit
175
+ if Actions.last_git_commit_message && should_add_payload[:last_git_commit]
176
+ attachment[:fields] << {
177
+ title: 'Git Commit',
178
+ value: Actions.last_git_commit_message
179
+ }
180
+ end
181
+
182
+ # merge additional properties
183
+ deep_merge(attachment, options[:attachment_properties])
184
+ end
185
+
186
+ # Adapted from http://stackoverflow.com/a/30225093/158525
187
+ def self.deep_merge(a, b)
188
+ merger = proc do |key, v1, v2|
189
+ Hash === v1 && Hash === v2 ?
190
+ v1.merge(v2, &merger) : Array === v1 && Array === v2 ?
191
+ v1 | v2 : [:undefined, nil, :nil].include?(v2) ? v1 : v2
192
+ end
193
+ a.merge(b, &merger)
194
+ end
195
+ end
196
+ end
197
+ end
198
+ # rubocop:enable Style/CaseEquality
199
+ # rubocop:enable Style/MultilineTernaryOperator
200
+ # rubocop:enable Style/NestedTernaryOperator
@@ -0,0 +1,12 @@
1
+ module Fastlane
2
+ module Helper
3
+ class ChangelogHelper
4
+ # class methods that you define here become available in your action
5
+ # as `Helper::ChangelogHelper.your_method`
6
+ #
7
+ def self.show_message
8
+ UI.message("Hello from the rocket_chat plugin helper!")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module RocketChat
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-rocket_chat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Thiago Felix
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rocket-chat-notifier
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: fastlane
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 1.96.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 1.96.0
111
+ description:
112
+ email: thiago@thiagofelix.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - LICENSE
118
+ - README.md
119
+ - lib/fastlane/plugin/rocket_chat.rb
120
+ - lib/fastlane/plugin/rocket_chat/actions/rocket_chat.rb
121
+ - lib/fastlane/plugin/rocket_chat/helper/rocket_chat_helper.rb
122
+ - lib/fastlane/plugin/rocket_chat/version.rb
123
+ homepage: https://github.com/thiagofelix/fastlane-plugin-rocket_chat
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.4.5.1
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Send message to Rocket.Chat right from fastlane
147
+ test_files: []
148
+ has_rdoc: