fastlane-plugin-slack_bot 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +155 -27
- data/lib/fastlane/plugin/slack_bot/actions/file_upload_to_slack.rb +176 -0
- data/lib/fastlane/plugin/slack_bot/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f2aabbc8c122fde9ab66c2f19a43ee068eeb1905fe71676b58f3f97615df758
|
4
|
+
data.tar.gz: 2f14989f7e4afcf43fd873748b385bb9fb30c5e8b419d4c4ad35b5f910dedd8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4aa6547bd6c2d4b3f4275be0296027171e1e4f47e90540bd676e1adedc92840bc5945972e1462ada73f1a30eabf8ba7eeebaf9d46e76205d81053bc2595ceb3b
|
7
|
+
data.tar.gz: 15a515660c49d9ca4b7d9de700c4212692402c05d53feba5b039fadc82c00f7bf03fcd6255b8467c659ef8545028f823723ef3e30cde8efbd7144fc1b1e8ebfc
|
data/README.md
CHANGED
@@ -1,11 +1,30 @@
|
|
1
1
|
## Fastlane `slack_bot` plugin
|
2
2
|
|
3
|
-
[![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-slack_bot)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
[![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-slack_bot)
|
4
|
+
![![License]](https://img.shields.io/badge/license-MIT-green.svg?style=flat)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/fastlane-plugin-slack_bot.svg)](https://badge.fury.io/rb/fastlane-plugin-slack_bot)
|
6
|
+
![![RubyGem Download Badge]](https://ruby-gem-downloads-badge.herokuapp.com/fastlane-plugin-slack_bot?type=total)
|
7
|
+
[![Twitter: @manish](https://img.shields.io/badge/contact-@manish-blue.svg?style=flat)](https://twitter.com/manish_rathi_)
|
8
|
+
|
9
|
+
A fastlane plugin to customize your automation workflow(s) with a **Slack Bot** 🤖 using the [Slack APIs](https://api.slack.com/)
|
10
|
+
|
11
|
+
- [About](#about)
|
12
|
+
- [Getting Started](#getting-started)
|
13
|
+
- [Features](#features)
|
14
|
+
- [Post a message](#examples-post-a-message) examples
|
15
|
+
- [Upload a file](#examples-upload-a-message) examples
|
16
|
+
- [About Fastlane](#about-fastlane)
|
17
|
+
|
18
|
+
## About
|
19
|
+
|
20
|
+
A fastlane plugin to post slack message and much more using Slack bot api token. 🚀\
|
21
|
+
**Note:** `Fastlane` comes with built-in `slack` action by default, which uses slack webhook url and have webhook limitations.
|
22
|
+
i.e Listing couple of slack **webhook url** limitations:
|
23
|
+
- can't post a direct message to a slack user.
|
24
|
+
- can’t post a message inside a slack thread.
|
25
|
+
- can’t update a posted slack message.
|
26
|
+
- can’t list and upload a file inside a slack channel.
|
27
|
+
- much more, compare to a **Slack Bot** 🤖 using the [Slack APIs](https://api.slack.com/)
|
9
28
|
|
10
29
|
## Getting Started
|
11
30
|
|
@@ -23,41 +42,64 @@ fastlane add_plugin slack_bot
|
|
23
42
|
```
|
24
43
|
If you are using fastlane using Gemfile in your project, add it to your project by running:
|
25
44
|
```bash
|
26
|
-
bundle exec fastlane add_plugin slack_bot
|
45
|
+
bundle exec fastlane add_plugin slack_bot
|
27
46
|
```
|
28
47
|
|
29
|
-
3.
|
48
|
+
3. Use `slack_bot` features inside your lane in `Fastfile` whenever you want.
|
49
|
+
|
50
|
+
## Features
|
51
|
+
Using this `slack_bot` plugin, you can:
|
52
|
+
|
53
|
+
- Post a message using [chat.postMessage](https://api.slack.com/methods/chat.postMessage) Slack API
|
54
|
+
- [x] Post a message to a _public_ channel
|
55
|
+
- [x] Post a message to a _private_ channel
|
56
|
+
- [x] Post a message to a _slack user_ (DM)
|
57
|
+
- [x] Post a message inside a _slack thread_ 🧵 (DM)
|
58
|
+
|
59
|
+
- Update a message using [chat.update](https://api.slack.com/methods/chat.update) Slack API
|
60
|
+
- [x] update a message in a channel
|
61
|
+
|
62
|
+
- List of files in a channel using [files.list](https://api.slack.com/methods/files.list) Slack API
|
63
|
+
- [x] A list of files in a channel, It can be filtered and sliced in various ways.
|
64
|
+
|
65
|
+
- Upload a file using [files.upload](https://api.slack.com/methods/files.upload) Slack API
|
66
|
+
- [x] Upload a file to a _public_ channel
|
67
|
+
- [x] Upload a file to a _private_ channel
|
68
|
+
- [x] Upload a file to a _slack user_ (DM)
|
69
|
+
- [x] Upload a file inside a _slack thread_ 🧵 (DM)
|
70
|
+
- [x] Upload a file with multiple channels/users
|
30
71
|
|
31
|
-
## Examples
|
32
72
|
|
33
|
-
|
73
|
+
## Examples (Post a message)
|
74
|
+
|
75
|
+
Let’s post a message to the default slack bot channel.
|
34
76
|
|
35
77
|
```ruby
|
36
78
|
# share on Slack
|
37
|
-
|
79
|
+
post_to_slack(message: "App successfully released!")
|
38
80
|
```
|
39
81
|
|
40
|
-
|
82
|
+
Let’s post a direct message to a slack user that unit tests CI has been failed.
|
41
83
|
|
42
84
|
```ruby
|
43
85
|
# share on Slack
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
86
|
+
post_to_slack(
|
87
|
+
message: "CI: Your unit tests on #{ENV['CI_COMMIT_REF_NAME']} failed",
|
88
|
+
channel: "@SlackUsername" # This can be Slack userID, instead of username i.e @UXXXXX
|
89
|
+
)
|
48
90
|
```
|
49
91
|
|
50
|
-
|
92
|
+
Let’s post a slack message to the `#ios-team` channel about the new test-flight build.
|
51
93
|
|
52
94
|
```ruby
|
53
95
|
lane :beta do
|
54
96
|
gym # Build the app and create .ipa file
|
55
97
|
pilot # Upload build to TestFlight
|
56
|
-
|
98
|
+
|
57
99
|
version_number = get_version_number # Get project version
|
58
100
|
build_number = get_build_number # Get build number
|
59
101
|
beta_release_name = "#{version_number}-#{build_number}-beta-release"
|
60
|
-
|
102
|
+
|
61
103
|
# share on Slack
|
62
104
|
post_to_slack(
|
63
105
|
message: "Hi team, we have a new test-flight beta build: #{beta_release_name}",
|
@@ -66,7 +108,7 @@ lane :beta do
|
|
66
108
|
end
|
67
109
|
```
|
68
110
|
|
69
|
-
|
111
|
+
Let’s post a slack message with custom payload.
|
70
112
|
|
71
113
|
```ruby
|
72
114
|
# share on Slack
|
@@ -93,18 +135,104 @@ post_to_slack(
|
|
93
135
|
)
|
94
136
|
```
|
95
137
|
|
96
|
-
|
138
|
+
Let’s post a slack message inside a slack thread 🧵
|
97
139
|
|
98
|
-
|
140
|
+
```ruby
|
141
|
+
lane :release do
|
142
|
+
# Start the release with slack release thread
|
143
|
+
release_thread = post_to_slack(
|
144
|
+
message: "Good morning team, CI has started the AppStore release. You can find more information inside this thread 🧵",
|
145
|
+
channel: "#ios-team"
|
146
|
+
)
|
147
|
+
|
148
|
+
# Important: Save this slack thread timestamp for futher slack messages
|
149
|
+
release_thread_ts = release_thread[:json]["ts"]
|
150
|
+
|
151
|
+
gym # Build the app and create .ipa file
|
152
|
+
|
153
|
+
# Post an update in release thread
|
154
|
+
post_to_slack(
|
155
|
+
message: "App has been build successfully! 💪",
|
156
|
+
channel: "#ios-team",
|
157
|
+
thread_ts: release_thread_ts
|
158
|
+
)
|
99
159
|
|
100
|
-
|
160
|
+
deliver # Upload build to AppStore
|
161
|
+
|
162
|
+
# Post an update in release thread
|
163
|
+
post_to_slack(
|
164
|
+
message: "App has been uploaded to the AppStore and submitted for Apple's review! 🚀",
|
165
|
+
channel: "#ios-team",
|
166
|
+
thread_ts: release_thread_ts
|
167
|
+
)
|
168
|
+
end
|
169
|
+
```
|
101
170
|
|
102
|
-
|
171
|
+
## Examples (Upload a file)
|
103
172
|
|
104
|
-
|
173
|
+
Let’s Upload a file to a slack channel that main branch unit tests has been failed, see scan logs.
|
105
174
|
|
106
|
-
|
175
|
+
```ruby
|
176
|
+
# File upload on Slack
|
177
|
+
file_upload_to_slack(
|
178
|
+
initial_comment: "CI: main-branch unit tests failed",
|
179
|
+
file_path: "scan.log",
|
180
|
+
channels: "#ios-team" # Comma-separated list of slack #channel names where the file will be shared
|
181
|
+
)
|
182
|
+
```
|
183
|
+
|
184
|
+
Let’s Upload a file to a slack user that your branch unit tests has been failed, see scan logs.
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
# File upload on Slack
|
188
|
+
file_upload_to_slack(
|
189
|
+
initial_comment: "CI: Your unit tests on #{ENV['CI_COMMIT_REF_NAME']} failed",
|
190
|
+
file_path: "scan.log",
|
191
|
+
channels: "@SlackUsername" # This can be Slack userID, instead of username i.e @UXXXXX
|
192
|
+
)
|
193
|
+
```
|
194
|
+
|
195
|
+
Let’s Upload a file inside a slack thread 🧵
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
lane :release do
|
199
|
+
# Start the release with slack release thread
|
200
|
+
release_thread = post_to_slack(
|
201
|
+
message: "Good morning team, CI has started the AppStore release. You can find more information inside this thread 🧵",
|
202
|
+
channel: "#ios-team"
|
203
|
+
)
|
204
|
+
|
205
|
+
# Important: Save this slack thread timestamp for futher slack messages
|
206
|
+
release_thread_ts = release_thread[:json]["ts"]
|
207
|
+
|
208
|
+
gym # Build the app and create .ipa file
|
209
|
+
|
210
|
+
# Post an update in release thread
|
211
|
+
post_to_slack(
|
212
|
+
message: "App has been build successfully! 💪",
|
213
|
+
channel: "#ios-team",
|
214
|
+
thread_ts: release_thread_ts
|
215
|
+
)
|
216
|
+
|
217
|
+
deliver # Upload build to AppStore
|
218
|
+
|
219
|
+
# Post an update in release thread
|
220
|
+
post_to_slack(
|
221
|
+
message: "App has been uploaded to the AppStore and submitted for Apple's review! 🚀",
|
222
|
+
channel: "#ios-team",
|
223
|
+
thread_ts: release_thread_ts
|
224
|
+
)
|
225
|
+
|
226
|
+
# Spaceship logs file upload on Slack
|
227
|
+
file_upload_to_slack(
|
228
|
+
initial_comment: "Deliver:: Spaceship logs",
|
229
|
+
file_path: "spaceship.log",
|
230
|
+
channels: "#ios-team",
|
231
|
+
thread_ts: release_thread_ts
|
232
|
+
)
|
233
|
+
end
|
234
|
+
```
|
107
235
|
|
108
|
-
## About
|
236
|
+
## About Fastlane
|
109
237
|
|
110
238
|
_fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
|
@@ -0,0 +1,176 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/slack_bot_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
FILE_UPLOAD_TO_SLACK_RESULT = :FILE_UPLOAD_TO_SLACK_RESULT
|
8
|
+
end
|
9
|
+
|
10
|
+
class FileUploadToSlackAction < Action
|
11
|
+
def self.run(params)
|
12
|
+
file_path = params[:file_path]
|
13
|
+
|
14
|
+
if params[:file_name].to_s.empty?
|
15
|
+
file_name = File.basename(file_path, ".*") # if file_path = "/path/file_name.jpeg" then will return "file_name"
|
16
|
+
else
|
17
|
+
file_name = params[:file_name]
|
18
|
+
end
|
19
|
+
|
20
|
+
if params[:file_type].to_s.empty?
|
21
|
+
file_type = File.extname(file_path)[1..-1] # if file_path = "/path/file_name.jpeg" then will return "jpeg"
|
22
|
+
else
|
23
|
+
file_type = params[:file_type]
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'faraday'
|
28
|
+
|
29
|
+
api_url = "https://slack.com/api/files.upload"
|
30
|
+
conn = Faraday.new(url: api_url) do |faraday|
|
31
|
+
faraday.request :multipart
|
32
|
+
faraday.request :url_encoded
|
33
|
+
faraday.adapter :net_http
|
34
|
+
end
|
35
|
+
|
36
|
+
payload = {
|
37
|
+
channels: params[:channels],
|
38
|
+
file: Faraday::FilePart.new(file_path, file_type),
|
39
|
+
filename: file_name,
|
40
|
+
filetype: file_type
|
41
|
+
}
|
42
|
+
|
43
|
+
payload[:title] = params[:title] unless params[:title].nil?
|
44
|
+
payload[:initial_comment] = params[:initial_comment] unless params[:initial_comment].nil?
|
45
|
+
payload[:thread_ts] = params[:thread_ts] unless params[:thread_ts].nil?
|
46
|
+
|
47
|
+
response = conn.post do |req|
|
48
|
+
req.headers['Authorization'] = "Bearer #{params[:api_token]}"
|
49
|
+
req.body = payload
|
50
|
+
end
|
51
|
+
|
52
|
+
result = self.formatted_result(response)
|
53
|
+
rescue => exception
|
54
|
+
UI.error("Exception: #{exception}")
|
55
|
+
return nil
|
56
|
+
else
|
57
|
+
UI.success("Successfully uploaded file to Slack! 🚀")
|
58
|
+
Actions.lane_context[SharedValues::FILE_UPLOAD_TO_SLACK_RESULT] = result
|
59
|
+
return result
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.formatted_result(response)
|
64
|
+
result = {
|
65
|
+
status: response[:status],
|
66
|
+
body: response.body || "",
|
67
|
+
json: self.parse_json(response.body) || {}
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.parse_json(value)
|
72
|
+
require 'json'
|
73
|
+
|
74
|
+
JSON.parse(value)
|
75
|
+
rescue JSON::ParserError
|
76
|
+
nil
|
77
|
+
end
|
78
|
+
|
79
|
+
#####################################################
|
80
|
+
# @!group Documentation
|
81
|
+
#####################################################
|
82
|
+
|
83
|
+
def self.description
|
84
|
+
"Upload a file to slack channel"
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.details
|
88
|
+
"Upload a file to slack channel or DM to a slack user"
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.available_options
|
92
|
+
[
|
93
|
+
FastlaneCore::ConfigItem.new(key: :api_token,
|
94
|
+
env_name: "FL_FILE_UPLOAD_TO_SLACK_BOT_TOKEN",
|
95
|
+
description: "Slack bot Token",
|
96
|
+
sensitive: true,
|
97
|
+
code_gen_sensitive: true,
|
98
|
+
is_string: true,
|
99
|
+
default_value: ENV["SLACK_API_TOKEN"],
|
100
|
+
default_value_dynamic: true,
|
101
|
+
optional: false),
|
102
|
+
FastlaneCore::ConfigItem.new(key: :channels,
|
103
|
+
env_name: "FL_FETCH_FILES_SLACK_CHANNELS",
|
104
|
+
description: "Comma-separated list of slack #channel names where the file will be shared",
|
105
|
+
is_string: true,
|
106
|
+
optional: false),
|
107
|
+
FastlaneCore::ConfigItem.new(key: :file_path,
|
108
|
+
env_name: "FL_FILE_UPLOAD_TO_SLACK_FILE_PATH",
|
109
|
+
description: "relative file path which will upload to slack",
|
110
|
+
is_string: true,
|
111
|
+
optional: false),
|
112
|
+
FastlaneCore::ConfigItem.new(key: :file_name,
|
113
|
+
env_name: "FL_FILE_UPLOAD_TO_SLACK_FILE_NAME",
|
114
|
+
description: "This is optional filename of the file",
|
115
|
+
is_string: true,
|
116
|
+
optional: true),
|
117
|
+
FastlaneCore::ConfigItem.new(key: :file_type,
|
118
|
+
env_name: "FL_FILE_UPLOAD_TO_SLACK_FILE_TYPE",
|
119
|
+
description: "This is optional filetype of the file",
|
120
|
+
is_string: true,
|
121
|
+
optional: true),
|
122
|
+
FastlaneCore::ConfigItem.new(key: :title,
|
123
|
+
env_name: "FL_FILE_UPLOAD_TO_SLACK_TITLE",
|
124
|
+
description: "This is optional Title of file",
|
125
|
+
is_string: true,
|
126
|
+
optional: true),
|
127
|
+
FastlaneCore::ConfigItem.new(key: :initial_comment,
|
128
|
+
env_name: "FL_FILE_UPLOAD_TO_SLACK_INITIAL_COMMENT",
|
129
|
+
description: "This is optional message text introducing the file",
|
130
|
+
is_string: true,
|
131
|
+
optional: true),
|
132
|
+
FastlaneCore::ConfigItem.new(key: :thread_ts,
|
133
|
+
env_name: "FL_FILE_UPLOAD_TO_SLACK_THREAD_TS",
|
134
|
+
description: "Provide another message's ts value to make this message a reply",
|
135
|
+
is_string: true,
|
136
|
+
optional: true)
|
137
|
+
]
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.authors
|
141
|
+
["crazymanish"]
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.example_code
|
145
|
+
[
|
146
|
+
'file_upload_to_slack(
|
147
|
+
channels: "slack_channel_name",
|
148
|
+
file_path: "fastlane/test.png"
|
149
|
+
)',
|
150
|
+
'file_upload_to_slack(
|
151
|
+
title: "This is test title",
|
152
|
+
channels: "slack_channel_name1, slack_channel_name2",
|
153
|
+
file_path: "fastlane/report.xml"
|
154
|
+
)',
|
155
|
+
'file_upload_to_slack(
|
156
|
+
title: "This is test title",
|
157
|
+
initial_comment: "This is test initial comment",
|
158
|
+
channels: "slack_channel_name",
|
159
|
+
file_path: "fastlane/screenshots.zip"
|
160
|
+
)',
|
161
|
+
'file_upload_to_slack(
|
162
|
+
title: "This is test title", # Optional, uploading file title
|
163
|
+
initial_comment: "This is test initial comment", # Optional, uploading file initial comment
|
164
|
+
channels: "slack_channel_name",
|
165
|
+
file_path: "fastlane/screenshots.zip",
|
166
|
+
thread_ts: thread_ts # Optional, Provide parent slack message `ts` value to upload this file as a reply.
|
167
|
+
)'
|
168
|
+
]
|
169
|
+
end
|
170
|
+
|
171
|
+
def self.is_supported?(platform)
|
172
|
+
true
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastlane-plugin-slack_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manish Rathi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- README.md
|
147
147
|
- lib/fastlane/plugin/slack_bot.rb
|
148
148
|
- lib/fastlane/plugin/slack_bot/actions/fetch_files_slack.rb
|
149
|
+
- lib/fastlane/plugin/slack_bot/actions/file_upload_to_slack.rb
|
149
150
|
- lib/fastlane/plugin/slack_bot/actions/post_to_slack.rb
|
150
151
|
- lib/fastlane/plugin/slack_bot/actions/update_slack_message.rb
|
151
152
|
- lib/fastlane/plugin/slack_bot/helper/slack_bot_helper.rb
|