forked from gofullstack/capistrano-notifier
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor shared base class, spec cleanup
- Loading branch information
1 parent
5fffc51
commit 5142d1a
Showing
10 changed files
with
138 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
guard 'rspec', :version => 2 do | ||
watch(%r{^spec/.+_spec\.rb$}) | ||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } | ||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } | ||
watch('spec/spec_helper.rb') { "spec" } | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
module Capistrano | ||
module Notifier | ||
end | ||
end | ||
|
||
require 'active_support' | ||
require 'capistrano' | ||
require 'yaml' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,78 @@ | ||
require 'action_mailer' | ||
|
||
module Capistrano | ||
module Notifier | ||
class Mail < Base | ||
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 body | ||
<<-BODY.gsub(/^ {10}/, '') | ||
#{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 from | ||
cap.notifier_mail_options[:from] | ||
end | ||
|
||
def github_commit_prefix | ||
"#{github_prefix}/commit" | ||
end | ||
|
||
def github_compare_prefix | ||
"#{github_prefix}/compare" | ||
end | ||
|
||
def github_prefix | ||
"https://github.com/#{github}" | ||
end | ||
|
||
def github | ||
cap.notifier_mail_options[:github] | ||
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 notify_method | ||
cap.notifier_mail_options[:method] | ||
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.notifier_mail_options[:to] | ||
end | ||
end | ||
class Capistrano::Notifier::Mail < Capistrano::Notifier::Base | ||
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 body | ||
<<-BODY.gsub(/^ {6}/, '') | ||
#{user_name} 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 from | ||
cap.notifier_mail_options[:from] | ||
end | ||
|
||
def github_commit_prefix | ||
"#{github_prefix}/commit" | ||
end | ||
|
||
def github_compare_prefix | ||
"#{github_prefix}/compare" | ||
end | ||
|
||
def github_prefix | ||
"https://github.com/#{github}" | ||
end | ||
|
||
def github | ||
cap.notifier_mail_options[:github] | ||
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 notify_method | ||
cap.notifier_mail_options[:method] | ||
end | ||
|
||
|
||
def subject | ||
"#{application} branch #{branch} deployed to #{stage}" | ||
end | ||
|
||
def text | ||
body.gsub(/([0-9a-f]{7})\.\.([0-9a-f]{7})/, "#{github_compare_prefix}/\\1...\\2") | ||
end | ||
|
||
def to | ||
cap.notifier_mail_options[:to] | ||
end | ||
end |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters