capistrano-notifier 0.1.2 → 0.2.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.
- data/.travis.yml +17 -1
- data/README.md +3 -1
- data/capistrano-notifier.gemspec +13 -1
- data/lib/capistrano/notifier/base.rb +6 -2
- data/lib/capistrano/notifier/mail.rb +46 -11
- data/lib/capistrano/notifier/statsd.rb +3 -7
- data/lib/capistrano/notifier/version.rb +1 -1
- data/spec/capistrano/notifier/base_spec.rb +9 -0
- data/spec/capistrano/notifier/mail_spec.rb +20 -0
- data/spec/capistrano/notifier/statsd_spec.rb +3 -6
- metadata +2 -2
data/.travis.yml
CHANGED
@@ -1,9 +1,25 @@
|
|
1
|
+
env:
|
2
|
+
- TEST_ENV=default
|
3
|
+
- TEST_ENV=rails-2.3
|
4
|
+
- TEST_ENV=rails-3.0
|
5
|
+
- TEST_ENV=rails-3.1
|
6
|
+
- TEST_ENV=rails-3.2
|
1
7
|
rvm:
|
2
8
|
- 1.8.7
|
3
9
|
- 1.9.2
|
4
10
|
- 1.9.3
|
5
|
-
-
|
11
|
+
- jruby
|
12
|
+
- rbx
|
6
13
|
- ree
|
14
|
+
- ruby-head
|
15
|
+
matrix:
|
16
|
+
allow_failures:
|
17
|
+
- rvm: jruby
|
18
|
+
- rvm: rbx
|
19
|
+
- rvm: ruby-head
|
20
|
+
exclude:
|
21
|
+
- rvm: ruby-head
|
22
|
+
env: TEST_ENV=rails-2.3
|
7
23
|
notifications:
|
8
24
|
email:
|
9
25
|
- sysadmin@cramerdev.com
|
data/README.md
CHANGED
@@ -31,7 +31,7 @@ set :notifier_mail_options, {
|
|
31
31
|
```
|
32
32
|
|
33
33
|
If you specified `:method => test`, you can see the email that would be
|
34
|
-
generated in your console with `cap deploy:notify`.
|
34
|
+
generated in your console with `cap deploy:notify:mail`.
|
35
35
|
|
36
36
|
|
37
37
|
## StatsD
|
@@ -59,3 +59,5 @@ set :notifier_statsd_options, {
|
|
59
59
|
:port => "8125"
|
60
60
|
}
|
61
61
|
```
|
62
|
+
|
63
|
+
The `nc` ([Netcat](http://netcat.sourceforge.net/)) command is used to send messages to statsd and must be installed on the remote hosts. This is installed by default on most Unix machines.
|
data/capistrano-notifier.gemspec
CHANGED
@@ -15,7 +15,19 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = Capistrano::Notifier::VERSION
|
17
17
|
|
18
|
-
|
18
|
+
case ENV['TEST_ENV']
|
19
|
+
when 'rails-2.3'
|
20
|
+
gem.add_dependency 'actionmailer', '~> 2.3.0'
|
21
|
+
when 'rails-3.0'
|
22
|
+
gem.add_dependency 'actionmailer', '~> 3.0.0'
|
23
|
+
when 'rails-3.1'
|
24
|
+
gem.add_dependency 'actionmailer', '~> 3.1.0'
|
25
|
+
when 'rails-3.2'
|
26
|
+
gem.add_dependency 'actionmailer', '~> 3.2.0'
|
27
|
+
else
|
28
|
+
gem.add_dependency 'actionmailer'
|
29
|
+
end
|
30
|
+
|
19
31
|
gem.add_dependency 'activesupport'
|
20
32
|
gem.add_dependency 'capistrano', '>= 2'
|
21
33
|
|
@@ -18,18 +18,22 @@ class Capistrano::Notifier::Base
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def git_current_revision
|
21
|
-
cap.current_revision[0,7]
|
21
|
+
cap.current_revision[0,7] if cap.respond_to? :current_revision
|
22
22
|
end
|
23
23
|
|
24
24
|
def git_log
|
25
|
+
return unless git_range
|
26
|
+
|
25
27
|
`git log #{git_range} --no-merges --format=format:"%h %s (%an)"`
|
26
28
|
end
|
27
29
|
|
28
30
|
def git_previous_revision
|
29
|
-
cap.previous_revision[0,7]
|
31
|
+
cap.previous_revision[0,7] if cap.respond_to? :previous_revision
|
30
32
|
end
|
31
33
|
|
32
34
|
def git_range
|
35
|
+
return unless git_previous_revision && git_current_revision
|
36
|
+
|
33
37
|
"#{git_previous_revision}..#{git_current_revision}"
|
34
38
|
end
|
35
39
|
|
@@ -1,5 +1,33 @@
|
|
1
1
|
require 'capistrano/notifier'
|
2
|
-
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'action_mailer'
|
5
|
+
rescue LoadError => e
|
6
|
+
require 'actionmailer'
|
7
|
+
end
|
8
|
+
|
9
|
+
class Capistrano::Notifier::Mailer < ActionMailer::Base
|
10
|
+
|
11
|
+
if ActionMailer::Base.respond_to?(:mail)
|
12
|
+
def notice(text, from, subject, to, delivery_method)
|
13
|
+
mail({
|
14
|
+
:body => text,
|
15
|
+
:delivery_method => delivery_method,
|
16
|
+
:from => from,
|
17
|
+
:subject => subject,
|
18
|
+
:to => to
|
19
|
+
})
|
20
|
+
end
|
21
|
+
else
|
22
|
+
def notice(text, from, subject, to)
|
23
|
+
body text
|
24
|
+
from from
|
25
|
+
subject subject
|
26
|
+
recipients to
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
3
31
|
|
4
32
|
class Capistrano::Notifier::Mail < Capistrano::Notifier::Base
|
5
33
|
def self.load_into(configuration)
|
@@ -9,6 +37,10 @@ class Capistrano::Notifier::Mail < Capistrano::Notifier::Base
|
|
9
37
|
desc 'Send a deployment notification via email.'
|
10
38
|
task :mail do
|
11
39
|
Capistrano::Notifier::Mail.new(configuration).perform
|
40
|
+
|
41
|
+
if configuration.notifier_mail_options[:method] == :test
|
42
|
+
puts ActionMailer::Base.deliveries
|
43
|
+
end
|
12
44
|
end
|
13
45
|
end
|
14
46
|
end
|
@@ -18,20 +50,23 @@ class Capistrano::Notifier::Mail < Capistrano::Notifier::Base
|
|
18
50
|
end
|
19
51
|
|
20
52
|
def perform
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
})
|
53
|
+
if defined?(ActionMailer::Base) && ActionMailer::Base.respond_to?(:mail)
|
54
|
+
perform_with_action_mailer
|
55
|
+
else
|
56
|
+
perform_with_legacy_action_mailer
|
57
|
+
end
|
58
|
+
end
|
28
59
|
|
29
|
-
|
60
|
+
private
|
30
61
|
|
31
|
-
|
62
|
+
def perform_with_legacy_action_mailer(notifier = Capistrano::Notifier::Mailer)
|
63
|
+
notifier.delivery_method = notify_method
|
64
|
+
notifier.deliver_notice(text, from, subject, to)
|
32
65
|
end
|
33
66
|
|
34
|
-
|
67
|
+
def perform_with_action_mailer(notifier = Capistrano::Notifier::Mailer)
|
68
|
+
notifier.notice(text, from, subject, to, notify_method).deliver
|
69
|
+
end
|
35
70
|
|
36
71
|
def body
|
37
72
|
<<-BODY.gsub(/^ {6}/, '')
|
@@ -10,7 +10,7 @@ class Capistrano::Notifier::StatsD < Capistrano::Notifier::Base
|
|
10
10
|
namespace :notify do
|
11
11
|
desc 'Notify StatsD of deploy.'
|
12
12
|
task :statsd do
|
13
|
-
Capistrano::Notifier::StatsD.new(configuration).
|
13
|
+
run Capistrano::Notifier::StatsD.new(configuration).command
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -19,8 +19,8 @@ class Capistrano::Notifier::StatsD < Capistrano::Notifier::Base
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
|
22
|
+
def command
|
23
|
+
"echo #{packet.gsub('|', '\\|')} | nc -w 1 -u #{host} #{port}"
|
24
24
|
end
|
25
25
|
|
26
26
|
private
|
@@ -49,10 +49,6 @@ class Capistrano::Notifier::StatsD < Capistrano::Notifier::Base
|
|
49
49
|
options[:port]
|
50
50
|
end
|
51
51
|
|
52
|
-
def socket
|
53
|
-
@socket ||= UDPSocket.new
|
54
|
-
end
|
55
|
-
|
56
52
|
def with
|
57
53
|
case options[:with]
|
58
54
|
when :counter then "1|c"
|
@@ -21,4 +21,13 @@ describe Capistrano::Notifier::Base do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
|
+
|
25
|
+
describe "#git_*" do
|
26
|
+
context "on initial deploy" do
|
27
|
+
it { subject.send(:git_log).should be_nil }
|
28
|
+
it { subject.send(:git_range).should be_nil }
|
29
|
+
it { subject.send(:git_current_revision).should be_nil }
|
30
|
+
it { subject.send(:git_previous_revision).should be_nil }
|
31
|
+
end
|
32
|
+
end
|
24
33
|
end
|
@@ -29,6 +29,26 @@ describe Capistrano::Notifier::Mail do
|
|
29
29
|
subject.stub(:user_name).and_return "John Doe"
|
30
30
|
end
|
31
31
|
|
32
|
+
it 'delivers mail' do
|
33
|
+
configuration.load do |configuration|
|
34
|
+
set :notifier_mail_options, {
|
35
|
+
:github => 'example/example',
|
36
|
+
:method => :test,
|
37
|
+
:from => 'sender@example.com',
|
38
|
+
:to => 'example@example.com'
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
subject.perform
|
43
|
+
|
44
|
+
last_delivery = ActionMailer::Base.deliveries.last
|
45
|
+
|
46
|
+
last_delivery.to.should include 'example@example.com'
|
47
|
+
last_delivery.from.should include 'sender@example.com'
|
48
|
+
|
49
|
+
ActionMailer::Base.deliveries.clear
|
50
|
+
end
|
51
|
+
|
32
52
|
it { subject.send(:github).should == 'example/example' }
|
33
53
|
it { subject.send(:notify_method).should == :sendmail }
|
34
54
|
it { subject.send(:from).should == 'sender@example.com' }
|
@@ -19,12 +19,9 @@ describe Capistrano::Notifier::StatsD do
|
|
19
19
|
subject.send(:packet).should == "example.deploy:1|c"
|
20
20
|
end
|
21
21
|
|
22
|
-
it "
|
23
|
-
|
24
|
-
"example.deploy:1
|
25
|
-
)
|
26
|
-
|
27
|
-
subject.perform
|
22
|
+
it "creates a command" do
|
23
|
+
subject.command.should ==
|
24
|
+
"echo example.deploy:1\\|c | nc -w 1 -u 127.0.0.1 8125"
|
28
25
|
end
|
29
26
|
|
30
27
|
context "with a stage" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-06-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: actionmailer
|