capistrano-notifier 0.0.2 → 0.1.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 ADDED
@@ -0,0 +1,10 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - ruby-head
6
+ - ree
7
+ notifications:
8
+ email:
9
+ - sysadmin@cramerdev.com
10
+
data/Gemfile CHANGED
@@ -3,6 +3,8 @@ source :rubygems
3
3
  gemspec
4
4
 
5
5
  group :development, :test do
6
+ gem 'rake'
7
+
6
8
  group :darwin do
7
9
  gem 'rb-fsevent'
8
10
  gem 'growl'
data/Guardfile CHANGED
@@ -1,6 +1,6 @@
1
1
  guard 'rspec', :version => 2 do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
4
  watch('spec/spec_helper.rb') { "spec" }
5
5
  end
6
6
 
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # CapistranoNotifier
1
+ # Capistrano Notifier [![Build Status](https://secure.travis-ci.org/cramerdev/capistrano-notifier.png)](https://secure.travis-ci.org/cramerdev/capistrano-notifier)
2
+
2
3
 
3
4
  ## Install
4
5
 
@@ -10,29 +11,51 @@ gem 'capistrano-notifier'
10
11
 
11
12
  and then `bundle install`
12
13
 
13
- ## Configure
14
+ `cap` needs to be invoked with Bundler for the `require` statements
15
+ below to work properly. You can do so with either `bundle exec cap`, or
16
+ with `bundle install --binstubs` and making sure `bin` is high up in your
17
+ `$PATH`.`
18
+
19
+
20
+ ## Mail
14
21
 
15
22
  ```rb
16
- require 'capistrano-notifier'
23
+ require 'capistrano/notifier/mail'
24
+
25
+ set :notifier_mail_options, {
26
+ :method => :test, # :smtp, :sendmail, or any other valid ActionMailer delivery method
27
+ :from => 'capistrano@domain.com',
28
+ :to => ['john@doe.com', 'jane@doe.com'],
29
+ :github => 'MyCompany/project-name'
30
+ }
31
+ ```
32
+
33
+ If you specified `:method => test`, you can see the email that would be
34
+ generated in your console with `cap deploy:notify`.
17
35
 
18
- set :notify_method, :test # :smtp, :sendmail, or any other valid ActionMailer delivery method
19
- set :notify_from, "capistrano@domain.com"
20
- set :notify_to, ["john@doe.com", "jane@doe.com"]
21
- set :notify_github_project, "MyCompany/project-name"
22
36
 
23
- namespace :deploy do
24
- desc "Capistrano Notifier"
25
- task :notify do
26
- Capistrano::Notifier.new(self).perform
27
- end
28
- end
37
+ ## StatsD
29
38
 
30
- after 'deploy', 'deploy:notify'
39
+ ```rb
40
+ require 'capistrano/notifier/statsd'
31
41
  ```
32
42
 
33
- ## Test
43
+ A counter of 1 will be sent with the key `application.stage.deploy` if using
44
+ multistage, or `application.deploy` if not. To use a gauge instead of a counter,
45
+ use `:with => :gauge`:
34
46
 
35
- ```sh
36
- cap deploy:notify
47
+ ```rb
48
+ set :notifier_statsd_options, {
49
+ :with => :gauge
50
+ }
37
51
  ```
38
52
 
53
+ If you want to specify a host:port other than
54
+ 127.0.0.1:8125, you can do so like this:
55
+
56
+ ```rb
57
+ set :notifier_statsd_options, {
58
+ :host => "10.0.0.1",
59
+ :port => "8125"
60
+ }
61
+ ```
@@ -1,23 +1,25 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/capistrano_notifier/version', __FILE__)
2
+ require File.expand_path('../lib/capistrano/notifier/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["Justin Campbell"]
6
- gem.email = ["justin@justincampbell.me"]
5
+ gem.authors = ["Justin Campbell", "Nathan L Smith"]
6
+ gem.email = ["sysadmin@cramerdev.com"]
7
7
  gem.description = %q{Capistrano Notifier}
8
8
  gem.summary = %q{Capistrano Notifier}
9
- gem.homepage = "http://github.com/CramerDev/capistrano-notifier"
9
+ gem.homepage = "http://github.com/cramerdev/capistrano-notifier"
10
10
 
11
11
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
12
  gem.files = `git ls-files`.split("\n")
13
13
  gem.test_files = `git ls-files -- spec/*`.split("\n")
14
14
  gem.name = "capistrano-notifier"
15
15
  gem.require_paths = ["lib"]
16
- gem.version = CapistranoNotifier::VERSION
16
+ gem.version = Capistrano::Notifier::VERSION
17
17
 
18
18
  gem.add_dependency 'actionmailer'
19
19
  gem.add_dependency 'activesupport'
20
+ gem.add_dependency 'capistrano', '>= 2'
20
21
 
21
22
  gem.add_development_dependency 'guard-rspec'
22
23
  gem.add_development_dependency 'rspec'
24
+ gem.add_development_dependency 'timecop'
23
25
  end
@@ -0,0 +1,11 @@
1
+ module Capistrano
2
+ module Notifier
3
+ end
4
+ end
5
+
6
+ require 'active_support'
7
+ require 'active_support/core_ext'
8
+ require 'capistrano'
9
+
10
+ require 'capistrano/notifier/base'
11
+
@@ -0,0 +1,56 @@
1
+ class Capistrano::Notifier::Base
2
+ def initialize(capistrano)
3
+ @cap = capistrano
4
+ end
5
+
6
+ private
7
+
8
+ def application
9
+ cap.application
10
+ end
11
+
12
+ def branch
13
+ cap.branch
14
+ end
15
+
16
+ def cap
17
+ @cap
18
+ end
19
+
20
+ def git_current_revision
21
+ cap.current_revision[0,7]
22
+ end
23
+
24
+ def git_log
25
+ `git log #{git_range} --no-merges --format=format:"%h %s (%an)"`
26
+ end
27
+
28
+ def git_previous_revision
29
+ cap.previous_revision[0,7]
30
+ end
31
+
32
+ def git_range
33
+ "#{git_previous_revision}..#{git_current_revision}"
34
+ end
35
+
36
+ def now
37
+ @now ||= Time.now
38
+ end
39
+
40
+ def stage
41
+ cap.stage if cap.respond_to? :stage
42
+ end
43
+
44
+ def user_name
45
+ user = ENV['DEPLOYER']
46
+ user = `git config --get user.name`.strip if user.nil?
47
+ end
48
+ end
49
+
50
+ # Band-aid for issue with Capistrano
51
+ # https://github.com/capistrano/capistrano/issues/168#issuecomment-4144687
52
+ Capistrano::Configuration::Namespaces::Namespace.class_eval do
53
+ def capture(*args)
54
+ parent.capture *args
55
+ end
56
+ end
@@ -0,0 +1,97 @@
1
+ require 'capistrano/notifier'
2
+ require 'action_mailer'
3
+
4
+ class Capistrano::Notifier::Mail < Capistrano::Notifier::Base
5
+ def self.load_into(configuration)
6
+ configuration.load do
7
+ namespace :deploy do
8
+ namespace :notify do
9
+ desc 'Send a deployment notification via email.'
10
+ task :mail do
11
+ Capistrano::Notifier::Mail.new(configuration).perform
12
+ end
13
+ end
14
+ end
15
+
16
+ after 'deploy', 'deploy:notify:mail'
17
+ end
18
+ end
19
+
20
+ def perform
21
+ mail = ActionMailer::Base.mail({
22
+ :body => text,
23
+ :delivery_method => notify_method,
24
+ :from => from,
25
+ :subject => subject,
26
+ :to => to
27
+ })
28
+
29
+ mail.deliver
30
+
31
+ puts ActionMailer::Base.deliveries if notify_method == :test
32
+ end
33
+
34
+ private
35
+
36
+ def body
37
+ <<-BODY.gsub(/^ {6}/, '')
38
+ #{user_name} deployed
39
+ #{application.titleize} branch
40
+ #{branch} to
41
+ #{stage} on
42
+ #{now.strftime("%m/%d/%Y")} at
43
+ #{now.strftime("%I:%M %p %Z")}
44
+
45
+ #{git_range}
46
+ #{git_log}
47
+ BODY
48
+ end
49
+
50
+ def from
51
+ cap.notifier_mail_options[:from]
52
+ end
53
+
54
+ def github_commit_prefix
55
+ "#{github_prefix}/commit"
56
+ end
57
+
58
+ def github_compare_prefix
59
+ "#{github_prefix}/compare"
60
+ end
61
+
62
+ def github_prefix
63
+ "https://github.com/#{github}"
64
+ end
65
+
66
+ def github
67
+ cap.notifier_mail_options[:github]
68
+ end
69
+
70
+ def html
71
+ body.gsub(
72
+ /([0-9a-f]{7})\.\.([0-9a-f]{7})/, "<a href=\"#{github_compare_prefix}/\\1...\\2\">\\1..\\2</a>"
73
+ ).gsub(
74
+ /^([0-9a-f]{7})/, "<a href=\"#{github_commit_prefix}/\\0\">\\0</a>"
75
+ )
76
+ end
77
+
78
+ def notify_method
79
+ cap.notifier_mail_options[:method]
80
+ end
81
+
82
+ def subject
83
+ "#{application.titleize} branch #{branch} deployed to #{stage}"
84
+ end
85
+
86
+ def text
87
+ body.gsub(/([0-9a-f]{7})\.\.([0-9a-f]{7})/, "#{github_compare_prefix}/\\1...\\2")
88
+ end
89
+
90
+ def to
91
+ cap.notifier_mail_options[:to]
92
+ end
93
+ end
94
+
95
+ if Capistrano::Configuration.instance
96
+ Capistrano::Notifier::Mail.load_into(Capistrano::Configuration.instance)
97
+ end
@@ -0,0 +1,66 @@
1
+ require 'capistrano/notifier'
2
+ require 'socket'
3
+
4
+ class Capistrano::Notifier::StatsD < Capistrano::Notifier::Base
5
+ DEFAULTS = { :host => "127.0.0.1", :port => "8125", :with => :counter }
6
+
7
+ def self.load_into(configuration)
8
+ configuration.load do
9
+ namespace :deploy do
10
+ namespace :notify do
11
+ desc 'Notify StatsD of deploy.'
12
+ task :statsd do
13
+ Capistrano::Notifier::StatsD.new(configuration).perform
14
+ end
15
+ end
16
+ end
17
+
18
+ after 'deploy', 'deploy:notify:statsd'
19
+ end
20
+ end
21
+
22
+ def perform
23
+ socket.send packet, 0, host, port
24
+ end
25
+
26
+ private
27
+
28
+ def host
29
+ options[:host]
30
+ end
31
+
32
+ def options
33
+ if cap.respond_to? :notifier_statsd_options
34
+ cap.notifier_statsd_options.reverse_merge DEFAULTS
35
+ else
36
+ DEFAULTS
37
+ end
38
+ end
39
+
40
+ def packet
41
+ if stage
42
+ "#{application}.#{stage}.deploy:#{with}"
43
+ else
44
+ "#{application}.deploy:#{with}"
45
+ end
46
+ end
47
+
48
+ def port
49
+ options[:port]
50
+ end
51
+
52
+ def socket
53
+ @socket ||= UDPSocket.new
54
+ end
55
+
56
+ def with
57
+ case options[:with]
58
+ when :counter then "1|c"
59
+ when :gauge then "1|g"
60
+ end
61
+ end
62
+ end
63
+
64
+ if Capistrano::Configuration.instance
65
+ Capistrano::Notifier::StatsD.load_into(Capistrano::Configuration.instance)
66
+ end
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Notifier
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'capistrano/notifier/mail'
3
+
4
+ describe Capistrano::Notifier::Mail do
5
+ let(:configuration) { Capistrano::Configuration.new }
6
+ subject { described_class.new configuration }
7
+
8
+ before :each do
9
+ configuration.load do |configuration|
10
+ set :notifier_mail_options, {
11
+ :github => 'example/example',
12
+ :method => :sendmail,
13
+ :from => 'sender@example.com',
14
+ :to => 'example@example.com'
15
+ }
16
+
17
+ set :application, 'example'
18
+ set :branch, 'master'
19
+ set :stage, 'test'
20
+
21
+ set :current_revision, '12345670000000000000000000000000'
22
+ set :previous_revision, '890abcd0000000000000000000000000'
23
+ end
24
+
25
+ subject.stub(:git_log).and_return <<-LOG.gsub /^ {6}/, ''
26
+ 1234567 This is the current commit (John Doe)
27
+ 890abcd This is the previous commit (John Doe)
28
+ LOG
29
+ subject.stub(:user_name).and_return "John Doe"
30
+ end
31
+
32
+ it { subject.send(:github).should == 'example/example' }
33
+ it { subject.send(:notify_method).should == :sendmail }
34
+ it { subject.send(:from).should == 'sender@example.com' }
35
+ it { subject.send(:to).should == 'example@example.com' }
36
+
37
+ it "creates a subject" do
38
+ subject.send(:subject).should == "Example branch master deployed to test"
39
+ end
40
+
41
+ it "renders a plaintext email" do
42
+ subject.send(:body).should == <<-BODY.gsub(/^ {6}/, '')
43
+ John Doe deployed
44
+ Example branch
45
+ master to
46
+ test on
47
+ 01/01/2012 at
48
+ 12:00 AM #{Time.now.zone}
49
+
50
+ 890abcd..1234567
51
+ 1234567 This is the current commit (John Doe)
52
+ 890abcd This is the previous commit (John Doe)
53
+
54
+ BODY
55
+ end
56
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+ require 'capistrano/notifier/statsd'
3
+
4
+ describe Capistrano::Notifier::StatsD do
5
+ let(:configuration) { Capistrano::Configuration.new }
6
+ subject { described_class.new configuration }
7
+
8
+ before :each do
9
+ configuration.load do |configuration|
10
+ set :application, 'example'
11
+ end
12
+ end
13
+
14
+ it "sets defaults" do
15
+ subject.send(:host).should == '127.0.0.1'
16
+ subject.send(:port).should == '8125'
17
+ subject.send(:with).should == '1|c'
18
+ end
19
+
20
+ it "creates a packet" do
21
+ subject.send(:packet).should == "example.deploy:1|c"
22
+ end
23
+
24
+ it "sends a packet" do
25
+ UDPSocket.any_instance.should_receive(:send).once.with(
26
+ "example.deploy:1|c", 0, "127.0.0.1", "8125"
27
+ )
28
+
29
+ subject.perform
30
+ end
31
+
32
+ context "with a stage" do
33
+ before :each do
34
+ configuration.load do |configuration|
35
+ set :application, 'example'
36
+ set :stage, 'test'
37
+ end
38
+ end
39
+
40
+ it "creates a packet" do
41
+ subject.send(:packet).should == "example.test.deploy:1|c"
42
+ end
43
+ end
44
+
45
+ context "with statsd options" do
46
+ before :each do
47
+ configuration.load do |configuration|
48
+ set :notifier_statsd_options, {
49
+ :host => '10.0.0.1',
50
+ :port => '1234'
51
+ }
52
+
53
+ set :application, 'example'
54
+ end
55
+ end
56
+
57
+ it "uses the options" do
58
+ subject.send(:host).should == '10.0.0.1'
59
+ subject.send(:port).should == '1234'
60
+ end
61
+ end
62
+
63
+ context "with a gauge" do
64
+ before :each do
65
+ configuration.load do |configuration|
66
+ set :notifier_statsd_options, {
67
+ :with => :gauge
68
+ }
69
+
70
+ set :application, 'example'
71
+ end
72
+ end
73
+
74
+ it { subject.send(:with).should == "1|g" }
75
+ end
76
+
77
+ context "with an uppercase application" do
78
+ before :each do
79
+ configuration.load do
80
+ set :application, 'Example'
81
+ end
82
+
83
+ it "lowercases the application" do
84
+ subject.send(:packet).should == "example.deploy:1|c"
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,6 @@
1
+ require "spec_helper"
2
+ require 'capistrano/notifier'
3
+
4
+ describe Capistrano::Notifier do
5
+ it { described_class.should be_a Module }
6
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,9 @@
1
- require "capistrano-notifier"
1
+ require 'timecop'
2
2
 
3
+ RSpec.configure do |config|
4
+ config.around :each do |example|
5
+ Timecop.freeze 2012, 1, 1 do
6
+ example.run
7
+ end
8
+ end
9
+ end
metadata CHANGED
@@ -1,19 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Justin Campbell
9
+ - Nathan L Smith
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-03-02 00:00:00.000000000 Z
13
+ date: 2012-05-02 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: actionmailer
16
- requirement: &70218232046560 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
17
18
  none: false
18
19
  requirements:
19
20
  - - ! '>='
@@ -21,21 +22,47 @@ dependencies:
21
22
  version: '0'
22
23
  type: :runtime
23
24
  prerelease: false
24
- version_requirements: *70218232046560
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
25
31
  - !ruby/object:Gem::Dependency
26
32
  name: activesupport
27
- requirement: &70218232045940 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
28
42
  none: false
29
43
  requirements:
30
44
  - - ! '>='
31
45
  - !ruby/object:Gem::Version
32
46
  version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: capistrano
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '2'
33
55
  type: :runtime
34
56
  prerelease: false
35
- version_requirements: *70218232045940
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '2'
36
63
  - !ruby/object:Gem::Dependency
37
64
  name: guard-rspec
38
- requirement: &70218232044940 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
39
66
  none: false
40
67
  requirements:
41
68
  - - ! '>='
@@ -43,10 +70,31 @@ dependencies:
43
70
  version: '0'
44
71
  type: :development
45
72
  prerelease: false
46
- version_requirements: *70218232044940
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
47
79
  - !ruby/object:Gem::Dependency
48
80
  name: rspec
49
- requirement: &70218232044360 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: timecop
97
+ requirement: !ruby/object:Gem::Requirement
50
98
  none: false
51
99
  requirements:
52
100
  - - ! '>='
@@ -54,10 +102,15 @@ dependencies:
54
102
  version: '0'
55
103
  type: :development
56
104
  prerelease: false
57
- version_requirements: *70218232044360
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
58
111
  description: Capistrano Notifier
59
112
  email:
60
- - justin@justincampbell.me
113
+ - sysadmin@cramerdev.com
61
114
  executables: []
62
115
  extensions: []
63
116
  extra_rdoc_files: []
@@ -65,18 +118,27 @@ files:
65
118
  - .gitignore
66
119
  - .rspec
67
120
  - .rvmrc
121
+ - .travis.yml
68
122
  - Gemfile
69
123
  - Guardfile
70
124
  - LICENSE
71
125
  - README.md
72
126
  - Rakefile
73
127
  - capistrano-notifier.gemspec
74
- - lib/capistrano-notifier.rb
75
- - lib/capistrano_notifier.rb
76
- - lib/capistrano_notifier/version.rb
77
- - spec/capistrano_notifier_spec.rb
128
+ - lib/capistrano/notifier.rb
129
+ - lib/capistrano/notifier/base.rb
130
+ - lib/capistrano/notifier/mail.rb
131
+ - lib/capistrano/notifier/statsd.rb
132
+ - lib/capistrano/notifier/templates/mail.erb
133
+ - lib/capistrano/notifier/templates/mail.html.erb
134
+ - lib/capistrano/notifier/templates/mail.text.erb
135
+ - lib/capistrano/notifier/templates/mail.txt.erb
136
+ - lib/capistrano/notifier/version.rb
137
+ - spec/capistrano/notifier/mail_spec.rb
138
+ - spec/capistrano/notifier/statsd_spec.rb
139
+ - spec/capistrano/notifier_spec.rb
78
140
  - spec/spec_helper.rb
79
- homepage: http://github.com/CramerDev/capistrano-notifier
141
+ homepage: http://github.com/cramerdev/capistrano-notifier
80
142
  licenses: []
81
143
  post_install_message:
82
144
  rdoc_options: []
@@ -96,10 +158,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
158
  version: '0'
97
159
  requirements: []
98
160
  rubyforge_project:
99
- rubygems_version: 1.8.17
161
+ rubygems_version: 1.8.23
100
162
  signing_key:
101
163
  specification_version: 3
102
164
  summary: Capistrano Notifier
103
165
  test_files:
104
- - spec/capistrano_notifier_spec.rb
166
+ - spec/capistrano/notifier/mail_spec.rb
167
+ - spec/capistrano/notifier/statsd_spec.rb
168
+ - spec/capistrano/notifier_spec.rb
105
169
  - spec/spec_helper.rb
@@ -1 +0,0 @@
1
- require 'capistrano_notifier'
@@ -1,133 +0,0 @@
1
- require "action_mailer"
2
- require "active_support"
3
- require "capistrano_notifier/version"
4
-
5
- Capistrano::Configuration::Namespaces::Namespace.class_eval do
6
- def capture(*args)
7
- parent.capture *args
8
- end
9
- end
10
-
11
- module Capistrano
12
- class Notifier
13
- def initialize(capistrano)
14
- @cap = capistrano
15
- end
16
-
17
- def perform
18
- mail = ActionMailer::Base.mail({
19
- :body => text,
20
- :delivery_method => notify_method,
21
- :from => from,
22
- :subject => subject,
23
- :to => to
24
- })
25
-
26
- mail.deliver
27
-
28
- puts ActionMailer::Base.deliveries if notify_method == :test
29
- end
30
-
31
- private
32
-
33
- def application
34
- cap.application.titleize
35
- end
36
-
37
- def body
38
- <<-BODY
39
- #{user} deployed
40
- #{application} branch
41
- #{branch} to
42
- #{stage} on
43
- #{now.strftime("%m/%d/%Y")} at
44
- #{now.strftime("%I:%M %p %Z")}
45
-
46
- #{git_range}
47
- #{git_log}
48
- BODY
49
- end
50
-
51
- def branch
52
- cap.branch
53
- end
54
-
55
- def cap
56
- @cap
57
- end
58
-
59
- def current_revision
60
- cap.current_revision[0,7]
61
- end
62
-
63
- def from
64
- cap.notify_from
65
- end
66
-
67
- def git_log
68
- `git log #{git_range} --no-merges --format=format:"%h %s (%an)"`
69
- end
70
-
71
- def git_range
72
- "#{previous_revision}..#{current_revision}"
73
- end
74
-
75
- def github_commit_prefix
76
- "#{github_prefix}/commit"
77
- end
78
-
79
- def github_compare_prefix
80
- "#{github_prefix}/compare"
81
- end
82
-
83
- def github_prefix
84
- "https://github.com/#{github_project}"
85
- end
86
-
87
- def github_project
88
- cap.notify_github_project
89
- end
90
-
91
- def html
92
- body.gsub(
93
- /([0-9a-f]{7})\.\.([0-9a-f]{7})/, "<a href=\"#{github_compare_prefix}/\\1...\\2\">\\1..\\2</a>"
94
- ).gsub(
95
- /^([0-9a-f]{7})/, "<a href=\"#{github_commit_prefix}/\\0\">\\0</a>"
96
- )
97
- end
98
-
99
- def previous_revision
100
- cap.previous_revision[0,7]
101
- end
102
-
103
- def notify_method
104
- cap.notify_method
105
- end
106
-
107
- def now
108
- @now ||= Time.new
109
- end
110
-
111
- def stage
112
- cap.stage
113
- end
114
-
115
- def subject
116
- "#{user} deployed #{application}@#{branch} to #{stage}"
117
- end
118
-
119
- def text
120
- body.gsub(/([0-9a-f]{7})\.\.([0-9a-f]{7})/, "#{github_compare_prefix}/\\1...\\2")
121
- end
122
-
123
- def to
124
- cap.notify_to
125
- end
126
-
127
- def user
128
- user = ENV['DEPLOYER']
129
- user = `git config --get user.name`.strip if user.nil?
130
- end
131
- end
132
- end
133
-
@@ -1,3 +0,0 @@
1
- module CapistranoNotifier
2
- VERSION = "0.0.2"
3
- end
@@ -1,5 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Capistrano::Notifier do
4
- it { described_class.should be_a Class }
5
- end