Skip to content

Commit

Permalink
hack up support for capistrano 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
zachlipton committed Jun 24, 2014
1 parent b47ff95 commit 3f8732c
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 50 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Capistrano Notifier [![Build Status](https://secure.travis-ci.org/cramerdev/capistrano-notifier.png)](https://secure.travis-ci.org/cramerdev/capistrano-notifier)

## This fork
This fork of capistrano-notifier contains a somewhat hacked up set of patches to support capistrano 3.x. --zach

## Install

Expand Down
2 changes: 1 addition & 1 deletion capistrano-notifier.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |gem|
end

gem.add_dependency 'activesupport'
gem.add_dependency 'capistrano', '>= 2', '< 3'
gem.add_dependency 'capistrano', '>= 3'

gem.add_development_dependency 'rake'
gem.add_development_dependency 'rspec'
Expand Down
25 changes: 6 additions & 19 deletions lib/capistrano/notifier/base.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
class Capistrano::Notifier::Base
def initialize(capistrano)
@cap = capistrano
def initialize()
end

private

def application
cap.application
fetch :application
end

def branch
cap.respond_to?(:branch) ? cap.branch : 'master'
end

def cap
@cap
fetch :branch
end

def git_current_revision
cap.current_revision.try(:[], 0,7) if cap.respond_to?(:current_revision)
fetch(:current_revision).try(:[], 0,7)
end

def git_log
Expand All @@ -28,7 +23,7 @@ def git_log
end

def git_previous_revision
cap.previous_revision.try(:[], 0,7) if cap.respond_to?(:previous_revision)
fetch(:previous_revision).try(:[], 0,7)
end

def git_range
Expand All @@ -42,19 +37,11 @@ def now
end

def stage
cap.stage if cap.respond_to? :stage
fetch :stage
end

def user_name
user = ENV['DEPLOYER']
user = `git config --get user.name`.strip if user.nil?
end
end

# 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
41 changes: 13 additions & 28 deletions lib/capistrano/notifier/mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,7 @@ def notice(text, from, subject, to, format)

class Capistrano::Notifier::Mail < Capistrano::Notifier::Base
def self.load_into(configuration)
configuration.load do
namespace :deploy do
namespace :notify do
desc 'Send a deployment notification via email.'
task :mail do
Capistrano::Notifier::Mail.new(configuration).perform

if configuration.notifier_mail_options[:method] == :test
puts ActionMailer::Base.deliveries
end
end
end
end

after 'deploy:restart', 'deploy:notify:mail'
end
load File.expand_path("../../tasks/notifier.rake", __FILE__)
end

def perform
Expand All @@ -76,15 +61,15 @@ def perform_with_action_mailer(notifier = Capistrano::Notifier::Mailer)
end

def email_template
cap.notifier_mail_options[:template] || "mail.#{format.to_s}.erb"
fetch(:notifier_mail_options)[:template] || "mail.#{format.to_s}.erb"
end

def format
cap.notifier_mail_options[:format] || :text
fetch(:notifier_mail_options)[:format] || :text
end

def from
cap.notifier_mail_options[:from]
fetch(:notifier_mail_options)[:from]
end

def git_commit_prefix
Expand All @@ -100,23 +85,23 @@ def git_prefix
end

def github
cap.notifier_mail_options[:github]
fetch(:notifier_mail_options)[:github]
end

def giturl
cap.notifier_mail_options[:giturl]
fetch(:notifier_mail_options)[:giturl]
end

def notify_method
cap.notifier_mail_options[:method]
fetch(:notifier_mail_options)[:method]
end

def smtp_settings
cap.notifier_mail_options[:smtp_settings]
fetch(:notifier_mail_options)[:smtp_settings]
end

def subject
cap.notifier_mail_options[:subject] || "#{application.titleize} branch #{branch} deployed to #{stage}"
fetch(:notifier_mail_options)[:subject] || "#{application.titleize} branch #{branch} deployed to #{stage}"
end

def template(template_name)
Expand All @@ -130,18 +115,18 @@ def template(template_name)
end

def templates_path
cap.notifier_mail_options[:templates_path] || 'config/deploy/templates'
fetch(:notifier_mail_options)[:templates_path] || 'config/deploy/templates'
end

def text
template(email_template)
end

def to
cap.notifier_mail_options[:to]
fetch(:notifier_mail_options)[:to]
end
end

if Capistrano::Configuration.instance
Capistrano::Notifier::Mail.load_into(Capistrano::Configuration.instance)
if Capistrano::Configuration.env
Capistrano::Notifier::Mail.load_into(Capistrano::Configuration.env)
end
2 changes: 1 addition & 1 deletion lib/capistrano/notifier/templates/mail.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</table>

<h3>Compare:</h3>
<p><%= git_compare_prefix %>/<%= git_range.gsub('..', '...') %></p>
<p><%= git_compare_prefix %>/<%= git_range.nil? ? '' : git_range.gsub('..', '...')%></p>

<h3>Commits:</h3>
<%- git_log.split(/\n/).each do |commit| -%>
Expand Down
2 changes: 1 addition & 1 deletion lib/capistrano/notifier/templates/mail.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Environment: <%= stage %>
Time: <%= now.strftime("%m/%d/%Y") %> at <%= now.strftime("%I:%M %p %Z") %>

Compare:
<%= git_compare_prefix %>/<%= git_range.gsub('..', '...') %>
<%= git_compare_prefix %>/<%= git_range.nil? ? '' : git_range.gsub('..', '...')%>

Commits:
<%= git_log %>
20 changes: 20 additions & 0 deletions lib/capistrano/tasks/notifier.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
begin
require 'action_mailer'
rescue LoadError
require 'actionmailer'
end

namespace :deploy do
namespace :notify do
desc 'Send a deployment notification via email.'
task :mail do
Capistrano::Notifier::Mail.new().perform

if fetch(:notifier_mail_options)[:method] == :test
puts ActionMailer::Base.deliveries
end
end
end
end

after 'deploy:restart', 'deploy:notify:mail'

0 comments on commit 3f8732c

Please sign in to comment.