capistrano-slack_notification 0.0.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +20 -2
- data/lib/capistrano/slack_notification/version.rb +1 -1
- data/lib/capistrano/tasks/slack_notification.rake +33 -20
- data/misc/capistrano-icon.png +0 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b66e86a0a879cdff824b86b70a7815e65f2a15e
|
4
|
+
data.tar.gz: 3ecf96b8746375b1fc7ef8a4a60bb1ea82e78ec9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab8235df16b61cda6d4591dbc5fdb25e5e9f35a178f04744492f87c5cd8400ada4cb7aa4ffe403cf955ba487e36daf3cb69e91a5cc7c5c04acba9cf70c6105c8
|
7
|
+
data.tar.gz: 8caac8579ce6fb0ac1333e6ff45f1499634d41210f713ddf9a107d36c3799931b7003b002e946fc7eb2b6ef5859d046f0c1d8a38b6d2be786b20c09f22e7fa65
|
data/README.md
CHANGED
@@ -30,13 +30,15 @@ $ gem install capistrano-slack_notification
|
|
30
30
|
Usage
|
31
31
|
-----
|
32
32
|
|
33
|
-
Capfile
|
33
|
+
### Capfile
|
34
34
|
|
35
35
|
```ruby
|
36
36
|
require 'capistrano/slack_notification'
|
37
37
|
```
|
38
38
|
|
39
|
-
config.rb
|
39
|
+
### config/deploy.rb
|
40
|
+
|
41
|
+
if use webhook
|
40
42
|
|
41
43
|
```ruby
|
42
44
|
set :slack_channel, '#general'
|
@@ -48,6 +50,22 @@ after 'deploy:finishing', 'slack:deploy:finish'
|
|
48
50
|
after 'deploy:finishing_rollback', 'slack:deploy:rollback'
|
49
51
|
```
|
50
52
|
|
53
|
+
if use api that needs channel_id
|
54
|
+
|
55
|
+
```sh
|
56
|
+
$ cap production "slack:channel[general]"
|
57
|
+
#general: C038M2LE1
|
58
|
+
```
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
set :slack_channel, 'C038M2LE1'
|
62
|
+
set :slack_token, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
63
|
+
|
64
|
+
after 'deploy:started', 'slack:deploy:start'
|
65
|
+
after 'deploy:finishing', 'slack:deploy:finish'
|
66
|
+
after 'deploy:finishing_rollback', 'slack:deploy:rollback'
|
67
|
+
```
|
68
|
+
|
51
69
|
Contributing
|
52
70
|
------------
|
53
71
|
|
@@ -18,11 +18,16 @@ namespace :slack do
|
|
18
18
|
username
|
19
19
|
}
|
20
20
|
|
21
|
-
set :
|
22
|
-
token
|
23
|
-
"/api/chat.postMessage#{"?token=#{token}" if token}"
|
21
|
+
set :slack_post_message_api_endpoint, -> {
|
22
|
+
"/api/chat.postMessage?token=#{fetch(:slack_token)}"
|
24
23
|
}
|
25
24
|
|
25
|
+
set :slack_channel_list_api_endpoint, -> {
|
26
|
+
"/api/channels.list?exclude_archived=1&token=#{fetch(:slack_token)}"
|
27
|
+
}
|
28
|
+
|
29
|
+
set :slack_path, -> { fetch(:slack_post_message_api_endpoint) }
|
30
|
+
|
26
31
|
set :slack_stage, -> {
|
27
32
|
stage = fetch(:stage)
|
28
33
|
stage.to_s == 'production' ? ":warning: #{stage}" : stage
|
@@ -41,7 +46,7 @@ namespace :slack do
|
|
41
46
|
|
42
47
|
set :slack_start_body, -> {
|
43
48
|
text = "Started deploying to #{fetch(:slack_stage)} by @#{fetch(:slack_deployer)}" +
|
44
|
-
" (branch #{fetch(:branch)})"
|
49
|
+
" (branch #{fetch(:branch)})"
|
45
50
|
|
46
51
|
fetch(:slack_default_body).merge(
|
47
52
|
attachments: JSON.dump([{
|
@@ -85,24 +90,22 @@ namespace :slack do
|
|
85
90
|
)
|
86
91
|
}
|
87
92
|
|
88
|
-
|
89
|
-
|
90
|
-
|
93
|
+
set :slack_client, -> {
|
94
|
+
Faraday.new(fetch :slack_endpoint) do |c|
|
95
|
+
c.request :url_encoded
|
96
|
+
c.adapter Faraday.default_adapter
|
91
97
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
c.
|
96
|
-
c.adapter Faraday.default_adapter
|
97
|
-
|
98
|
-
v = Faraday::VERSION.split('.')
|
99
|
-
if v.join('.').to_f >= 0.9
|
100
|
-
c.options.timeout = 5
|
101
|
-
c.options.open_timeout = 5
|
102
|
-
end
|
98
|
+
v = Faraday::VERSION.split('.')
|
99
|
+
if v.join('.').to_f >= 0.9
|
100
|
+
c.options.timeout = 5
|
101
|
+
c.options.open_timeout = 5
|
103
102
|
end
|
103
|
+
end
|
104
|
+
}
|
104
105
|
|
105
|
-
|
106
|
+
def post_to_slack_with(body)
|
107
|
+
run_locally do
|
108
|
+
res = fetch(:slack_client).post fetch(:slack_path), body
|
106
109
|
|
107
110
|
if ENV['DEBUG']
|
108
111
|
require 'awesome_print'
|
@@ -114,7 +117,17 @@ namespace :slack do
|
|
114
117
|
|
115
118
|
desc 'Post message to Slack (ex. cap production "slack:notify[yo!])"'
|
116
119
|
task :post, :message do |t, args|
|
117
|
-
|
120
|
+
post_to_slack_with fetch(:slack_default_body).merge(text: args[:message])
|
121
|
+
end
|
122
|
+
|
123
|
+
desc 'Get channel ID by channel name from Slack (ex. cap production "slack:channel[general])"'
|
124
|
+
task :channel, :channel_name do |t, args|
|
125
|
+
run_locally do
|
126
|
+
res = fetch(:slack_client).post fetch(:slack_channel_list_api_endpoint)
|
127
|
+
body = JSON.load(res.body)
|
128
|
+
channel = body['channels'].find { |ch| ch['name'] == args[:channel_name] }
|
129
|
+
puts "##{args[:channel_name]}: #{channel['id']}"
|
130
|
+
end
|
118
131
|
end
|
119
132
|
|
120
133
|
namespace :deploy do
|
data/misc/capistrano-icon.png
CHANGED
Binary file
|