capistrano3-notification 0.2.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21616767890c4e45b6ee17056648b909b7aa1739
4
- data.tar.gz: 4072825cf9dd634c6b6f9221c2e750275e61decf
3
+ metadata.gz: 9aa2470a772b323322ee37f0f767bf9a1c65e760
4
+ data.tar.gz: ca08eeb030e87bad7fd2566e94e3854c9b59438d
5
5
  SHA512:
6
- metadata.gz: 6021fccdb4ecf4dd2fe45455a30964d8dbd719dccd943bdff5d23297531c1017ec3bb6513c511fe6602d3aa6b1356a1442fe46f809dde7b7086a449596cd4335
7
- data.tar.gz: e5894c79f74446570284dd1bb91fbe2b79d580377748fc194f1848a606ab0711f5f682b052cbc5b297d28aa3e84a8810347edb199b6990d525c9b05be048e618
6
+ metadata.gz: a32d2b423915160307d754bd174352b18a9b91ae7d9a06987f9642017a87286fb19cbcf33089b2dee20558c599f40fe11b11426ca9ba51f898aec1a299760541
7
+ data.tar.gz: 70772b0ba2d3a6a9018477a8885eca81e65108225ff23065ae2830b232fe29d0ea41fb4ff10a1080324bca1b8aed50c09f85dec217d1d5e021ea7040232287f4
data/README.md CHANGED
@@ -1,13 +1,14 @@
1
1
  # Capistrano3::Notification
2
2
 
3
- Notification for capistrano3
3
+ Notification for capistrano3.
4
+ Sending notification to irc/slack/... after deployment completed.
4
5
 
5
6
  ## Installation
6
7
 
7
8
  Add this line to your application's Gemfile:
8
9
 
9
10
  ```ruby
10
- gem 'capistrano3-notification'
11
+ gem 'capistrano3-notification', require: false
11
12
  ```
12
13
 
13
14
  ## Usage
@@ -18,6 +19,8 @@ in `Capfile`:
18
19
  require 'capistrano3/notification'
19
20
  ```
20
21
 
22
+ ## Configuration
23
+
21
24
  ### IRC notification
22
25
 
23
26
  in `deploy.rb` or staging files:
@@ -45,6 +48,18 @@ set :notification, -> { "#{fetch(:application)} was deployed to #{fetch(:stage)}
45
48
 
46
49
  **contribute me!**
47
50
 
51
+ ## Notify manually
52
+
53
+ You can use `notify` method to send message.
54
+
55
+ ```ruby
56
+ # lib/capistrano/tasks/foo.rake
57
+
58
+ task :foo do
59
+ notify 'hello!'
60
+ end
61
+ ```
62
+
48
63
  ## Contributing
49
64
 
50
65
  1. Fork it ( https://github.com/masarakki/capistrano3-notification/fork )
@@ -1,3 +1,10 @@
1
1
  require 'capistrano3/notification/version'
2
+ require 'capistrano3/notification/adapter'
3
+ %w(slack irc).each do |adapter|
4
+ require "capistrano3/notification/#{adapter}"
5
+ end
6
+ require 'capistrano3/notification/dsl'
7
+
8
+ extend Capistrano3::Notification::DSL
2
9
 
3
10
  load File.expand_path('../notification/tasks/notification.rake', __FILE__)
@@ -0,0 +1,25 @@
1
+ require 'forwardable'
2
+
3
+ module Capistrano3
4
+ module Notification
5
+ class Adapter
6
+ extend Forwardable
7
+ attr_reader :env
8
+ def_delegators :@env, :fetch
9
+
10
+ def initialize(env)
11
+ @env = env
12
+ end
13
+
14
+ def notify(_message)
15
+ raise 'this is abstract class'
16
+ end
17
+
18
+ private
19
+
20
+ def user
21
+ fetch(:notifier)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ module Capistrano3
2
+ module Notification
3
+ module DSL
4
+ def notify(message)
5
+ return if dry_run?
6
+ [Capistrano3::Notification::IRC,
7
+ Capistrano3::Notification::Slack].each do |klass|
8
+ klass.new(self).notify(message)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ require 'shout-bot'
2
+
3
+ module Capistrano3
4
+ module Notification
5
+ class IRC < Adapter
6
+ def notify(message)
7
+ ShoutBot.shout(url) { |irc| irc.say message } if enabled?
8
+ end
9
+
10
+ private
11
+
12
+ def host
13
+ env.fetch(:irc_host)
14
+ end
15
+
16
+ def port
17
+ env.fetch(:irc_port)
18
+ end
19
+
20
+ def channel
21
+ env.fetch(:irc_channel)
22
+ end
23
+
24
+ def enabled?
25
+ user && host && port && channel && message
26
+ end
27
+
28
+ def url
29
+ "irc://#{user}@#{host}:#{port}/#{channel}"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,42 @@
1
+ require 'slack-notifier'
2
+
3
+ module Capistrano3
4
+ module Notification
5
+ class Slack < Adapter
6
+ def notify(message)
7
+ notifier_options = { username: user, channel: channel }.reject { |_x, y| y.nil? }
8
+ ping_options = {}.tap do |h|
9
+ h[icon_type] = icon if icon_type
10
+ end
11
+ ::Slack::Notifier.new(webhook_url, notifier_options).ping message, ping_options
12
+ end
13
+
14
+ private
15
+
16
+ def webhook_url
17
+ fetch(:slack_webhook_url)
18
+ end
19
+
20
+ def channel
21
+ fetch(:slack_channel)
22
+ end
23
+
24
+ def icon
25
+ fetch(:slack_icon) || nil
26
+ end
27
+
28
+ def icon_type
29
+ case icon
30
+ when /^:.+:/
31
+ :icon_emoji
32
+ when /^http/
33
+ :icon_url
34
+ end
35
+ end
36
+
37
+ def enabled?
38
+ user && channel && webhook_url
39
+ end
40
+ end
41
+ end
42
+ end
@@ -7,59 +7,9 @@ namespace :load do
7
7
  end
8
8
 
9
9
  namespace :notification do
10
- task :notify_auto do
11
- invoke 'notification:notify', fetch(:notification)
10
+ task :notify do
11
+ notify fetch(:notification)
12
12
  end
13
13
 
14
- task :notify, [:message] do |t, args|
15
- deprecated :irc_user, :notifier if fetch(:irc_user)
16
- deprecated :slack_user, :notifier if fetch(:slack_user)
17
-
18
- %w(irc slack).each do |adapter|
19
- invoke "notification:#{adapter}", args[:message]
20
- end
21
- t.reenable
22
- end
23
-
24
- task :irc, [:message] do |t, args|
25
- user = fetch(:irc_user) || fetch(:notifier)
26
- host = fetch(:irc_host)
27
- port = fetch(:irc_port)
28
- channel = fetch(:irc_channel)
29
- message = args[:message]
30
- next unless user && host && port && channel && message
31
- require 'shout-bot'
32
- url = "irc://#{user}@#{host}:#{port}/#{channel}"
33
- ShoutBot.shout(url) { |irc| irc.say message }
34
- t.reenable
35
- end
36
-
37
- task :slack, [:message] do |t, args|
38
- webhook_url = fetch(:slack_webhook_url)
39
- user = fetch(:slack_user) || fetch(:notifier)
40
- channel = fetch(:slack_channel)
41
- icon = fetch(:slack_icon) || nil
42
- message = args[:message]
43
- next unless user && channel && webhook_url && message
44
- require 'slack-notifier'
45
- notifier_options = { username: user, channel: channel }.reject { |_x, y| y.nil? }
46
- icon_type = case icon
47
- when /^:.+:/
48
- :icon_emoji
49
- when /^http/
50
- :icon_url
51
- end
52
- ping_options = {}.tap do |h|
53
- h[icon_type] = icon if icon_type
54
- end
55
- notifier = Slack::Notifier.new webhook_url, notifier_options
56
- notifier.ping message, ping_options
57
- t.reenable
58
- end
59
-
60
- def deprecated(old, new)
61
- puts format('%6s %s', 'WARN'.red, ":#{old} is deplicated. use set :#{new}, '#{fetch(old)}'")
62
- end
63
-
64
- after 'deploy:finished', 'notification:notify_auto'
14
+ after 'deploy:finished', 'notification:notify'
65
15
  end
@@ -1,5 +1,5 @@
1
1
  module Capistrano3
2
2
  module Notification
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '1.0.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano3-notification
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - masarakki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-02 00:00:00.000000000 Z
11
+ date: 2016-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -112,6 +112,10 @@ files:
112
112
  - capistrano3-notification.gemspec
113
113
  - lib/capistrano3-notification.rb
114
114
  - lib/capistrano3/notification.rb
115
+ - lib/capistrano3/notification/adapter.rb
116
+ - lib/capistrano3/notification/dsl.rb
117
+ - lib/capistrano3/notification/irc.rb
118
+ - lib/capistrano3/notification/slack.rb
115
119
  - lib/capistrano3/notification/tasks/notification.rake
116
120
  - lib/capistrano3/notification/version.rb
117
121
  homepage: https://github.com/masarakki/capistrano3-notification