capistrano-slack_notification 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e72e1677f4f337d523465026ab43fea05f32d22
4
- data.tar.gz: 12789f427d1f7aca2918d3cccef2577adb9d7eac
3
+ metadata.gz: 8b66e86a0a879cdff824b86b70a7815e65f2a15e
4
+ data.tar.gz: 3ecf96b8746375b1fc7ef8a4a60bb1ea82e78ec9
5
5
  SHA512:
6
- metadata.gz: 4d1afca5522d9ac6cb2f97b7405ab6a645229163861d5aadea83b9124fa759d8b0cbd19ed9301be67f9690be0e358bbf1398ec55f7ecbda533c34907c7d3ef2a
7
- data.tar.gz: 2f2abba849a4ac834e3294ff54eb9ac275c202ba436953d6cfc7faba8a440cb2bbed1b7545a12529b28da16a021c297422458f9b3a7d85831a6f7e5305d3ba7d
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
 
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module SlackNotification
3
- VERSION = '0.0.7'
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
@@ -18,11 +18,16 @@ namespace :slack do
18
18
  username
19
19
  }
20
20
 
21
- set :slack_path, -> {
22
- token = fetch(:slack_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
- def post_to_slack(message = '')
89
- post_to_slack_with fetch(:slack_default_body).merge(text: message)
90
- end
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
- def post_to_slack_with(body)
93
- run_locally do
94
- conn = Faraday.new(fetch :slack_endpoint) do |c|
95
- c.request :url_encoded
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
- res = conn.post fetch(:slack_path), body
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
- post_to_slack args[:message]
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
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-slack_notification
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - linyows