slackistrano 0.1.1 → 0.1.2

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: 40a1bb96232995fa01ec31424aa78f09a2812660
4
- data.tar.gz: 3b6b45e2546a3b336fcb38af43256ae08ad9f951
3
+ metadata.gz: d3998c3aea514c9828cf3e3ab08e2ab68d91b897
4
+ data.tar.gz: 6734a8944a889eba842e5e201a556fd66a065eb0
5
5
  SHA512:
6
- metadata.gz: af928b2ea2c32aefb7cfaf0af1f89ec519caf391e4e02e152a50e25b5e68dd9a363846079e1826fb6c4aeac5412c17de4d2b4de6a09d0d7593a788bc9d79d2a7
7
- data.tar.gz: 4a6c9f5f152ff9819f7d5f07601ef5d944c6dc63598ff37e84cc070c7d206405e67110fd59b960e1f79ba0996e838b645d63047834bd004c80a40a444f682f97
6
+ metadata.gz: 92b28a925c578cfc17f16ad244403cee548612508aecb0fa4e4cb7be4ff62f09f06700fcc5956b3d1b3fb0f584779fad8848787623dd0f10a8bcb4cdba42f3df
7
+ data.tar.gz: b59697ca1b2001a6660e8bf85d5b18d85d39be16dcad9a1bd7232c3ef3df035a31f64f559790ca5a0b47fe9a71a17653acfbf7d86e73cee22a08efefcad7113b
data/README.md CHANGED
@@ -31,14 +31,21 @@ You have two options to notify a channel in Slack when you deploy:
31
31
  1. Using *Incoming WebHooks* integration, offering more options but requires one of the five free integrations. This is the default option.
32
32
  2. Using *Slackbot*, which will not use one of the five free integrations. Enable via the `:slack_via_slackbot` option.
33
33
 
34
- In both case, you need to enable the integration inside Slack and get the token that will be needed later.
34
+ In both case, you need to enable the integration inside Slack and get the token and/or webhook url that will be needed later.
35
+
36
+
35
37
 
36
38
  Require the library in your application's Capfile:
37
39
 
38
40
  require 'slackistrano'
39
41
 
40
- Set your team and token in your application's config/deploy.rb:
42
+ If you post using *Incoming Webhooks* you need to set your webhook url in your application's config/deploy.rb:
43
+
44
+ set :slack_webhook, "https://hooks.slack.com/services/XXX/XXX/XXX"
45
+
46
+ If you choose to post using *Slackbot* you **must** set your team and and token in your application's config/deploy.rb:
41
47
 
48
+ set :slack_via_slackbot, true
42
49
  set :slack_team, "supremegolf"
43
50
  set :slack_token, "xxxxxxxxxxxxxxxxxxxxxxxx"
44
51
 
@@ -54,7 +61,6 @@ Optionally, override the other slack settings:
54
61
  set :slack_msg_starting, ->{ "#{ENV['USER'] || ENV['USERNAME']} has started deploying branch #{fetch :branch} of #{fetch :application} to #{fetch :rails_env, 'production'}." }
55
62
  set :slack_msg_finished, ->{ "#{ENV['USER'] || ENV['USERNAME']} has finished deploying branch #{fetch :branch} of #{fetch :application} to #{fetch :rails_env, 'production'}." }
56
63
  set :slack_msg_failed, ->{ "*ERROR!* #{ENV['USER'] || ENV['USERNAME']} failed to deploy branch #{fetch :branch} of #{fetch :application} to #{fetch :rails_env, 'production'}." }
57
- set :slack_via_slackbot, ->{ false } # Set to true to send the message via slackbot instead of webhook
58
64
 
59
65
  **Note**: You may wish to disable one of the notifications if another service (ex:
60
66
  Honeybadger) also displays a deploy notification.
data/lib/slackistrano.rb CHANGED
@@ -5,20 +5,47 @@ require 'json'
5
5
  load File.expand_path("../slackistrano/tasks/slack.rake", __FILE__)
6
6
 
7
7
  module Slackistrano
8
- def self.post(team: nil, token: nil, via_slackbot: false, payload: {})
9
- if via_slackbot
10
- uri = URI(URI.encode("https://#{team}.slack.com/services/hooks/slackbot?token=#{token}&channel=#{payload[:channel]}"))
11
8
 
12
- Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
13
- response = http.request_post uri.request_uri, payload[:text]
14
- end
9
+ #
10
+ #
11
+ #
12
+ def self.post(team: nil, token: nil, webhook: nil, via_slackbot: false, payload: {})
13
+ if via_slackbot
14
+ post_as_slackbot(team: team, token: token, webhook: webhook, payload: payload)
15
15
  else
16
- uri = URI("https://#{team}.slack.com/services/hooks/incoming-webhook")
17
- res = Net::HTTP.post_form(uri, 'token' => token, 'payload' => payload.to_json)
16
+ post_as_webhook(team: team, token: token, webhook: webhook, payload: payload)
18
17
  end
19
18
  rescue => e
20
19
  puts "There was an error notifying Slack."
21
20
  puts e.inspect
22
21
  end
22
+
23
+ #
24
+ #
25
+ #
26
+ def self.post_as_slackbot(team: nil, token: nil, webhook: webhook, payload: {})
27
+ uri = URI(URI.encode("https://#{team}.slack.com/services/hooks/slackbot?token=#{token}&channel=#{payload[:channel]}"))
28
+
29
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
30
+ http.request_post uri.request_uri, payload[:text]
31
+ end
32
+ end
33
+
34
+ #
35
+ #
36
+ #
37
+ def self.post_as_webhook(team: nil, token: nil, webhook: webhook, payload: {})
38
+ params = {'payload' => payload.to_json}
39
+
40
+ if webhook.nil?
41
+ webhook = "https://#{team}.slack.com/services/hooks/incoming-webhook"
42
+ params.merge!('token' => token)
43
+ end
44
+
45
+ uri = URI(webhook)
46
+ Net::HTTP.post_form(uri, params)
47
+ end
48
+
49
+
23
50
  end
24
51
 
@@ -8,6 +8,7 @@ namespace :slack do
8
8
  Slackistrano.post(
9
9
  team: fetch(:slack_team),
10
10
  token: fetch(:slack_token),
11
+ webhook: fetch(:slack_webhook),
11
12
  via_slackbot: fetch(:slack_via_slackbot),
12
13
  payload: {
13
14
  channel: fetch(:slack_channel),
@@ -27,6 +28,7 @@ namespace :slack do
27
28
  Slackistrano.post(
28
29
  team: fetch(:slack_team),
29
30
  token: fetch(:slack_token),
31
+ webhook: fetch(:slack_webhook),
30
32
  via_slackbot: fetch(:slack_via_slackbot),
31
33
  payload: {
32
34
  channel: fetch(:slack_channel),
@@ -46,6 +48,7 @@ namespace :slack do
46
48
  Slackistrano.post(
47
49
  team: fetch(:slack_team),
48
50
  token: fetch(:slack_token),
51
+ webhook: fetch(:slack_webhook),
49
52
  via_slackbot: fetch(:slack_via_slackbot),
50
53
  payload: {
51
54
  channel: fetch(:slack_channel),
@@ -68,8 +71,12 @@ after 'deploy:failed', 'slack:deploy:failed'
68
71
 
69
72
  namespace :load do
70
73
  task :defaults do
71
- set :slack_team, ->{ nil } # If URL is 'team.slack.com', value is 'team'. Required.
72
- set :slack_token, ->{ nil } # Token from Incoming WebHooks. Required.
74
+
75
+ set :slack_team, ->{ nil } # If URL is 'team.slack.com', value is 'team'.
76
+ set :slack_token, ->{ nil } # Token from Incoming WebHooks.
77
+ set :slack_webhook, ->{ nil } # Incoming WebHook URL.
78
+ set :slack_via_slackbot, ->{ false } # Set to true to send the message via slackbot instead of webhook
79
+
73
80
  set :slack_channel, ->{ nil } # Channel to post to. Optional. Defaults to WebHook setting.
74
81
  set :slack_icon_url, ->{ 'http://gravatar.com/avatar/885e1c523b7975c4003de162d8ee8fee?r=g&s=40' }
75
82
  set :slack_icon_emoji, ->{ nil } # Emoji to use. Overrides icon_url. Must be a string (ex: ':shipit:')
@@ -80,6 +87,5 @@ namespace :load do
80
87
  set :slack_msg_starting, ->{ "#{ENV['USER'] || ENV['USERNAME']} has started deploying branch #{fetch :branch} of #{fetch :application} to #{fetch :stage, 'an unknown stage'}." }
81
88
  set :slack_msg_finished, ->{ "#{ENV['USER'] || ENV['USERNAME']} has finished deploying branch #{fetch :branch} of #{fetch :application} to #{fetch :stage, 'an unknown stage'}." }
82
89
  set :slack_msg_failed, ->{ "*ERROR!* #{ENV['USER'] || ENV['USERNAME']} failed to deploy branch #{fetch :branch} of #{fetch :application} to #{fetch :stage, 'an unknown stage'}." }
83
- set :slack_via_slackbot, ->{ false } # Set to true to send the message via slackbot instead of webhook
84
90
  end
85
91
  end
@@ -1,3 +1,3 @@
1
1
  module Slackistrano
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
data/spec/tasks_spec.rb CHANGED
@@ -41,6 +41,7 @@ describe Slackistrano do
41
41
  set "slack_run_#{stage}".to_sym, ->{ true }
42
42
  set :slack_team, ->{ 'team' }
43
43
  set :slack_token, ->{ 'token' }
44
+ set :slack_webhook, ->{ 'webhook' }
44
45
  set :slack_channel, ->{ 'channel' }
45
46
  set :slack_icon_url, ->{ 'http://icon.url' }
46
47
  set :slack_icon_emoji, ->{ ':emoji:' }
@@ -48,6 +49,7 @@ describe Slackistrano do
48
49
  expect(Slackistrano).to receive(:post).with(
49
50
  team: 'team',
50
51
  token: 'token',
52
+ webhook: 'webhook',
51
53
  via_slackbot: false,
52
54
  payload: {
53
55
  channel: 'channel',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slackistrano
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Hallstrom
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-03 00:00:00.000000000 Z
11
+ date: 2014-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano