Permalink
Browse files

move mailer to capistrano/notify/mail

  • Loading branch information...
1 parent 3adb505 commit 7e0bef123b920c3cc35b11c15b2328a9e23cddc1 @smith smith committed Mar 30, 2012
View
12 README.md
@@ -1,4 +1,4 @@
-# CapistranoNotifier [![Build Status](https://secure.travis-ci.org/cramerdev/capistrano-notifier.png)](https://secure.travis-ci.org/cramerdev/capistrano-notifier)
+# Capistrano Notifier [![Build Status](https://secure.travis-ci.org/cramerdev/capistrano-notifier.png)](https://secure.travis-ci.org/cramerdev/capistrano-notifier)
## Install
@@ -10,10 +10,12 @@ gem 'capistrano-notifier'
and then `bundle install`
-## Configure
+## Mail
+
+### Configure
```rb
-require 'capistrano/notifier'
+require 'capistrano/notifier/mail'
set :notify_method, :test # :smtp, :sendmail, or any other valid ActionMailer delivery method
set :notify_from, "capistrano@domain.com"
@@ -30,13 +32,13 @@ end
after 'deploy', 'deploy:notify'
```
-## Test
+### Test
```sh
cap deploy:notify
```
-### StatsD
+## StatsD
To notify StatsD, `require 'capistrano/notifier/statsd'` in your deploy.rb. When deploying it will look for a config/stats.yml and load the host and port from there. It should use the stages if you're using multistage.
View
131 lib/capistrano/notifier.rb
@@ -1,135 +1,6 @@
-require "action_mailer"
-require "active_support"
require 'capistrano/notifier/version'
-# Band-aid for issue with Capistrano
-# https://github.com/capistrano/capistrano/issues/168#issuecomment-4144687
-Capistrano::Configuration::Namespaces::Namespace.class_eval do
- def capture(*args)
- parent.capture *args
- end
-end
-
module Capistrano
- class Notifier
- def initialize(capistrano)
- @cap = capistrano
- end
-
- def perform
- mail = ActionMailer::Base.mail({
- :body => text,
- :delivery_method => notify_method,
- :from => from,
- :subject => subject,
- :to => to
- })
-
- mail.deliver
-
- puts ActionMailer::Base.deliveries if notify_method == :test
- end
-
- private
-
- def application
- cap.application.titleize
- end
-
- def body
-<<-BODY
-#{user} deployed
-#{application} branch
-#{branch} to
-#{stage} on
-#{now.strftime("%m/%d/%Y")} at
-#{now.strftime("%I:%M %p %Z")}
-
-#{git_range}
-#{git_log}
-BODY
- end
-
- def branch
- cap.branch
- end
-
- def cap
- @cap
- end
-
- def current_revision
- cap.current_revision[0,7]
- end
-
- def from
- cap.notify_from
- end
-
- def git_log
- `git log #{git_range} --no-merges --format=format:"%h %s (%an)"`
- end
-
- def git_range
- "#{previous_revision}..#{current_revision}"
- end
-
- def github_commit_prefix
- "#{github_prefix}/commit"
- end
-
- def github_compare_prefix
- "#{github_prefix}/compare"
- end
-
- def github_prefix
- "https://github.com/#{github_project}"
- end
-
- def github_project
- cap.notify_github_project
- end
-
- def html
- body.gsub(
- /([0-9a-f]{7})\.\.([0-9a-f]{7})/, "<a href=\"#{github_compare_prefix}/\\1...\\2\">\\1..\\2</a>"
- ).gsub(
- /^([0-9a-f]{7})/, "<a href=\"#{github_commit_prefix}/\\0\">\\0</a>"
- )
- end
-
- def previous_revision
- cap.previous_revision[0,7]
- end
-
- def notify_method
- cap.notify_method
- end
-
- def now
- @now ||= Time.new
- end
-
- def stage
- cap.stage
- end
-
- def subject
- "#{user} deployed #{application}@#{branch} to #{stage}"
- end
-
- def text
- body.gsub(/([0-9a-f]{7})\.\.([0-9a-f]{7})/, "#{github_compare_prefix}/\\1...\\2")
- end
-
- def to
- cap.notify_to
- end
-
- def user
- user = ENV['DEPLOYER']
- user = `git config --get user.name`.strip if user.nil?
- end
+ module Notifier
end
end
-
View
136 lib/capistrano/notifier/mail.rb
@@ -0,0 +1,136 @@
+require "action_mailer"
+require "active_support"
+
+# Band-aid for issue with Capistrano
+# https://github.com/capistrano/capistrano/issues/168#issuecomment-4144687
+Capistrano::Configuration::Namespaces::Namespace.class_eval do
+ def capture(*args)
+ parent.capture *args
+ end
+end
+
+module Capistrano
+ module Notifier
+ class Mail
+ def initialize(capistrano)
+ @cap = capistrano
+ end
+
+ def perform
+ mail = ActionMailer::Base.mail({
+ :body => text,
+ :delivery_method => notify_method,
+ :from => from,
+ :subject => subject,
+ :to => to
+ })
+
+ mail.deliver
+
+ puts ActionMailer::Base.deliveries if notify_method == :test
+ end
+
+ private
+
+ def application
+ cap.application.titleize
+ end
+
+ def body
+ <<-BODY
+ #{user} deployed
+ #{application} branch
+ #{branch} to
+ #{stage} on
+ #{now.strftime("%m/%d/%Y")} at
+ #{now.strftime("%I:%M %p %Z")}
+
+ #{git_range}
+ #{git_log}
+ BODY
+ end
+
+ def branch
+ cap.branch
+ end
+
+ def cap
+ @cap
+ end
+
+ def current_revision
+ cap.current_revision[0,7]
+ end
+
+ def from
+ cap.notify_from
+ end
+
+ def git_log
+ `git log #{git_range} --no-merges --format=format:"%h %s (%an)"`
+ end
+
+ def git_range
+ "#{previous_revision}..#{current_revision}"
+ end
+
+ def github_commit_prefix
+ "#{github_prefix}/commit"
+ end
+
+ def github_compare_prefix
+ "#{github_prefix}/compare"
+ end
+
+ def github_prefix
+ "https://github.com/#{github_project}"
+ end
+
+ def github_project
+ cap.notify_github_project
+ end
+
+ def html
+ body.gsub(
+ /([0-9a-f]{7})\.\.([0-9a-f]{7})/, "<a href=\"#{github_compare_prefix}/\\1...\\2\">\\1..\\2</a>"
+ ).gsub(
+ /^([0-9a-f]{7})/, "<a href=\"#{github_commit_prefix}/\\0\">\\0</a>"
+ )
+ end
+
+ def previous_revision
+ cap.previous_revision[0,7]
+ end
+
+ def notify_method
+ cap.notify_method
+ end
+
+ def now
+ @now ||= Time.new
+ end
+
+ def stage
+ cap.stage
+ end
+
+ def subject
+ "#{user} deployed #{application}@#{branch} to #{stage}"
+ end
+
+ def text
+ body.gsub(/([0-9a-f]{7})\.\.([0-9a-f]{7})/, "#{github_compare_prefix}/\\1...\\2")
+ end
+
+ def to
+ cap.notify_to
+ end
+
+ def user
+ user = ENV['DEPLOYER']
+ user = `git config --get user.name`.strip if user.nil?
+ end
+ end
+ end
+end
+
View
1 lib/capistrano/notifier/statsd.rb
@@ -1,4 +1,5 @@
require 'yaml'
+require 'active_support'
require 'capistrano'
require 'capistrano/notifier'
View
2 lib/capistrano/notifier/version.rb
@@ -1,5 +1,5 @@
module Capistrano
- class Notifier
+ module Notifier
VERSION = '0.0.3'
end
end
View
5 spec/capistrano-notifier_spec.rb
@@ -1,5 +0,0 @@
-require "spec_helper"
-
-describe Capistrano::Notifier do
- it { described_class.should be_a Class }
-end
View
6 spec/capistrano/notifier/mail_spec.rb
@@ -0,0 +1,6 @@
+require "spec_helper"
+require 'capistrano/notifier/mail'
+
+describe Capistrano::Notifier::Mail do
+ it { described_class.should be_a Class }
+end
View
0 spec/capistrano-notifier-statsd_spec.rb → spec/capistrano/notifier/statsd_spec.rb
File renamed without changes.
View
6 spec/capistrano/notifier_spec.rb
@@ -0,0 +1,6 @@
+require "spec_helper"
+require 'capistrano/notifier'
+
+describe Capistrano::Notifier do
+ it { described_class.should be_a Module }
+end

0 comments on commit 7e0bef1

Please sign in to comment.