capistrano-notifications 0.0.1 → 0.0.3

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: 7206bacffdeab09b3d57eeb83820a09923c2aa90
4
- data.tar.gz: 46e25ffe6c17e06b479dc6756ce552460725a723
3
+ metadata.gz: d6b06e7740bac372fe30fde45fe126e4ce7844b4
4
+ data.tar.gz: bf6f315f2601a0fbdf945e9a68d9a27e6fb370c8
5
5
  SHA512:
6
- metadata.gz: c135f5e6cde1151e1b4096aa77540d126afeb11351a57252a5482af6912c2ebfe1ab03c5f78899d38f81dfeb5ca6de4dcd35e6795324a5b7fc6a42cab991c360
7
- data.tar.gz: c53393e19861dd3390d3d0c4c14cc0712c2597a8fb017dfb6d0639a213cb9574d184ce59cb41a72a95de07c9a6bef36ec0d90734792ba0cd055ab8d35dcb0115
6
+ metadata.gz: a76d78038ec573da4305e823351453928a5ae36cba1228a8d603d4d88437e631eaf858aa1767ca1c96e5b48741189f52f51afa464acb89286c0f967ad6a382ca
7
+ data.tar.gz: 327c0cf4b8dd9d3015f21b4dc2a53c58e0d4f743b4ccdf097ce0dd30882e2d9faa6348a4654881d15eb64e9ebfeb7ceb372237d0ae5baf5b50e451c5f4ad546c
data/.gitignore CHANGED
@@ -15,4 +15,5 @@ mkmf.log
15
15
 
16
16
  .ruby-version
17
17
  .ruby-gemset
18
- .idea
18
+ .idea
19
+ .gem
@@ -20,7 +20,8 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.7'
22
22
  spec.add_development_dependency 'rake', '~> 10.0'
23
- spec.add_development_dependency 'capistrano', '~> 3.3.5'
23
+ spec.add_development_dependency 'capistrano', '~> 3.3'
24
24
 
25
- spec.add_dependency 'faraday'
25
+ spec.add_dependency 'faraday', '~> 0.9'
26
+ spec.add_dependency 'activesupport', '~> 4.1'
26
27
  end
@@ -12,13 +12,13 @@ module Capistrano
12
12
  end
13
13
 
14
14
  def notify(members = [], message = '')
15
- members.each { |member| send_notification(member, message) }
15
+ Array.wrap(members).each { |member| send_notification(member, message) }
16
16
  end
17
17
 
18
18
  protected
19
19
 
20
20
  def send_notification(_member, _message)
21
- raise NoMethodError, 'send_notification is not defined.'
21
+ raise NoMethodError, 'send_notification is not implemented.'
22
22
  end
23
23
 
24
24
  end
@@ -6,7 +6,7 @@ module Capistrano
6
6
  attr_reader :team, :token
7
7
 
8
8
  protected
9
- def send_notification(_member, _message)
9
+ def send_notification(member, message, username = 'Capistrano Notification')
10
10
  connection = Faraday.new(url: "https://#{team}.slack.com") do |faraday|
11
11
  faraday.request :url_encoded
12
12
  faraday.adapter Faraday.default_adapter
@@ -16,13 +16,7 @@ module Capistrano
16
16
  req.headers['User-Agent'] = "Capistrano Notification #{Capistrano::Notifications::VERSION}"
17
17
  req.body = {
18
18
  token: token,
19
- payload: {
20
- channel: "#{_member}",
21
- username: "#{fetch(:application)} #{fetch(:env)}",
22
- text: _message,
23
- icon_emoji: ':grin:',
24
- mrkdwn: true
25
- }.to_json
19
+ payload: {channel: member, username: username, text: message, icon_emoji: ':grin:', mrkdwn: true}.to_json
26
20
  }
27
21
  end
28
22
  end
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Notifications
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
@@ -1,5 +1,7 @@
1
1
  require 'faraday'
2
2
  require 'json'
3
+ require 'active_support/core_ext/string'
4
+ require 'active_support/core_ext/array'
3
5
 
4
6
  module Capistrano
5
7
  module Notifications
@@ -1,49 +1,29 @@
1
1
  #
2
- # adapters:
2
+ # examples:
3
3
  #
4
- # * Slack
4
+ # * Slack
5
5
  #
6
- # example:
6
+ # set :notify, -> {
7
+ # {
8
+ # to: %w(@scorix #deploy),
9
+ # via: :slack,
10
+ # options: {team: 'my-team', token: 'token'}
11
+ # }
12
+ # }
7
13
  #
8
- # set :notify_adapter, :Slack
9
- #
10
- set :notify_adapter, -> { nil }
11
-
12
- #
13
- # default options:
14
- #
15
- # * Slack:
16
- #
17
- # team **required**
18
- #
19
- # token **required**
20
- #
21
- # example:
22
- #
23
- # set :notify_default_options, team: 'my-team', token: 'token'
24
- #
25
- set :notify_default_options, -> { {} }
26
-
27
- #
28
- # subscribers
29
- #
30
- # * Slack:
31
- #
32
- # subscribers could be a user, or a channel
33
- #
34
- # example:
35
- #
36
- # set :subscribers, -> { ['@scorix', '#deploy'] }
37
- #
38
- set :subscribers, -> { [] }
14
+ set :notify, -> { {} }
39
15
 
40
16
  namespace :notify do
41
17
 
18
+ def notify
19
+ fetch(:notify) { {} }
20
+ end
21
+
42
22
  def find_adapter
43
- adapter = fetch(:notify_adapter, nil)
23
+ adapter = notify[:via]
44
24
 
45
25
  if adapter
46
- adapter = Capistrano::Notifications::Adapter.const_get(adapter.to_sym).setup(fetch(:notify_default_options))
26
+ adapter = Capistrano::Notifications::Adapter.const_get(adapter.to_s.classify.to_sym).setup(notify[:options])
47
27
 
48
28
  begin
49
29
  yield adapter
@@ -55,17 +35,19 @@ namespace :notify do
55
35
 
56
36
  task :starting do
57
37
  find_adapter do |adapter|
58
- adapter.notify(fetch(:subscribers), "@#{local_user} is deploying branch #{fetch(:branch)}")
38
+ adapter.notify(notify[:to], "#{local_user} is deploying the `#{fetch(:branch)}` branch...")
59
39
  end
60
40
  end
61
41
 
62
42
  task :finishing do
63
43
  find_adapter do |adapter|
64
- adapter.notify(fetch(:subscribers), t(:revision_log_message,
65
- branch: fetch(:branch),
66
- user: "@#{local_user}",
67
- sha: fetch(:current_revision),
68
- release: fetch(:release_timestamp)))
44
+ adapter.notify(notify[:to],
45
+ t(:revision_log_message,
46
+ branch: fetch(:branch),
47
+ user: local_user,
48
+ sha: fetch(:current_revision),
49
+ release: fetch(:release_timestamp)),
50
+ "#{fetch(:application)} #{fetch(:env)}".titleize)
69
51
  end
70
52
  end
71
53
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-notifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - scorix
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-12 00:00:00.000000000 Z
11
+ date: 2015-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,28 +44,42 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.3.5
47
+ version: '3.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.3.5
54
+ version: '3.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: faraday
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '0.9'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '0'
82
+ version: '4.1'
69
83
  description: Send deploy notifications to subscribers.
70
84
  email:
71
85
  - scorix@gmail.com