capistrano_mailer 3.2.7 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +116 -0
- data/LICENSE.txt +23 -0
- data/README.md +268 -0
- data/Rakefile +24 -52
- data/lib/cap_mailer.rb +226 -180
- data/lib/capistrano/mailer.rb +45 -25
- data/lib/capistrano/mailer_recipes.rb +43 -0
- data/lib/capistrano_mailer.rb +2 -0
- data/lib/capistrano_mailer/version.rb +3 -0
- data/spec/create_gemset_spec.rb +44 -0
- data/spec/empty_gemset_spec.rb +32 -0
- data/spec/install_ruby_spec.rb +120 -0
- data/spec/rvm_paths_spec.rb +93 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/abort_matcher.rb +42 -0
- data/spec/support/capistrano.rb +24 -0
- data/test/build_gem_test.rb +18 -0
- data/views/cap_mailer/_message_body.html.erb +39 -0
- data/views/cap_mailer/_message_body.text.erb +22 -0
- data/views/cap_mailer/_section.html.erb +31 -31
- data/views/cap_mailer/_section.text.erb +23 -23
- data/views/cap_mailer/_section_custom.html.erb +2 -1
- data/views/cap_mailer/failed.notification_email.html.erb +1 -0
- data/views/cap_mailer/failed.notification_email.plain.erb +1 -0
- data/views/cap_mailer/notification_email.html.erb +1 -0
- data/views/cap_mailer/notification_email.plain.erb +1 -0
- metadata +103 -40
- data/MIT-LICENSE +0 -21
- data/README.rdoc +0 -198
- data/VERSION.yml +0 -5
- data/capistrano_mailer.gemspec +0 -55
- data/views/cap_mailer/notification_email.text.html.erb +0 -39
- data/views/cap_mailer/notification_email.text.plain.erb +0 -22
data/lib/cap_mailer.rb
CHANGED
@@ -1,180 +1,226 @@
|
|
1
|
-
class CapMailer < ActionMailer::Base
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
:
|
6
|
-
|
7
|
-
|
8
|
-
:
|
9
|
-
|
10
|
-
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
def self.
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
self.
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
:
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
{
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
:
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
:
|
152
|
-
:
|
153
|
-
:
|
154
|
-
:
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
:
|
162
|
-
:
|
163
|
-
:previous_release
|
164
|
-
:
|
165
|
-
:
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
:
|
173
|
-
:
|
174
|
-
:
|
175
|
-
:
|
176
|
-
:
|
177
|
-
:
|
178
|
-
|
179
|
-
|
180
|
-
|
1
|
+
class CapMailer < ActionMailer::Base
|
2
|
+
|
3
|
+
# In capistrano_mailer 4+ this uses ActiveSupport::InheritableOptions from Rails 3+
|
4
|
+
@@default_base_config ||= {
|
5
|
+
:sender_address => %("#{(defined?(Rails) ? Rails.env.capitalize : defined?(RAILS_ENV) ? RAILS_ENV.capitalize : defined?(ENV) ? ENV['RAILS_ENV'] : "")} Capistrano Deployment" <capistrano.mailer@example.com>),
|
6
|
+
:recipient_addresses => [],
|
7
|
+
# Customize the subject line
|
8
|
+
:subject_prepend => "[DEPLOYMENT]-[#{(defined?(Rails) ? Rails.env.capitalize : defined?(RAILS_ENV) ? RAILS_ENV.capitalize : defined?(ENV) ? ENV['RAILS_ENV'] : "")}] ",
|
9
|
+
:subject_append => nil,
|
10
|
+
# Include which sections of the deployment email?
|
11
|
+
:sections => %w(deployment release_data source_control latest_release previous_release other_deployment_info extra_information),
|
12
|
+
:site_name => "",
|
13
|
+
:email_content_type => "text/html",
|
14
|
+
# In Capistrano 4+ template_root becomes template_path
|
15
|
+
:template_root => "#{File.dirname(__FILE__)}/../views",
|
16
|
+
:template_prefixes => { :success => nil, :failure => "failed" },
|
17
|
+
:attach_log_on => :failure
|
18
|
+
}
|
19
|
+
|
20
|
+
cattr_accessor :default_base_config
|
21
|
+
attr_accessor :config, :options
|
22
|
+
attr_accessor :date, :time, :inferred_command, :task_name, :repo_end
|
23
|
+
|
24
|
+
def self.configure(&block)
|
25
|
+
yield @@default_base_config
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.configure_capistrano_mailer(&block)
|
29
|
+
raise "'configure_capistrano_mailer' is deprecated. Please update your capistrano_mailer configuration to use 'configure' instead of 'configure_capistrano_mailer'"
|
30
|
+
end
|
31
|
+
|
32
|
+
self.template_root = default_base_config[:template_root]
|
33
|
+
|
34
|
+
def self.reloadable?() false end
|
35
|
+
|
36
|
+
def config_from_cap_hash(cap, config = {})
|
37
|
+
default_base_config.dup.merge(config.reverse_merge({
|
38
|
+
:rails_env => cap[:rails_env],
|
39
|
+
:host => cap[:host],
|
40
|
+
:task_name => cap[:task_name],
|
41
|
+
:application => cap[:application],
|
42
|
+
:repository => cap[:repository],
|
43
|
+
:scm => cap[:scm],
|
44
|
+
:deploy_via => cap[:deploy_via],
|
45
|
+
:deploy_to => cap[:deploy_to],
|
46
|
+
:revision => cap[:revision],
|
47
|
+
:real_revision => cap[:real_revision],
|
48
|
+
:release_name => cap[:release_name],
|
49
|
+
:version_dir => cap[:version_dir],
|
50
|
+
:shared_dir => cap[:shared_dir],
|
51
|
+
:current_dir => cap[:current_dir],
|
52
|
+
:releases_path => cap[:releases_path],
|
53
|
+
:shared_path => cap[:shared_path],
|
54
|
+
:current_path => cap[:current_path],
|
55
|
+
:release_path => cap[:release_path],
|
56
|
+
:releases => cap[:releases],
|
57
|
+
:current_release => cap[:current_release],
|
58
|
+
:previous_release => cap[:previous_release],
|
59
|
+
:current_revision => cap[:current_revision],
|
60
|
+
:latest_revision => cap[:latest_revision],
|
61
|
+
:previous_revision => cap[:previous_revision],
|
62
|
+
:run_method => cap[:run_method],
|
63
|
+
:latest_release => cap[:latest_release]
|
64
|
+
|
65
|
+
#This does not appear to be a capistrano variable:
|
66
|
+
#:site_url => cap[:site_url]
|
67
|
+
}))
|
68
|
+
end
|
69
|
+
|
70
|
+
def notification_email(cap, config = {}, *args)
|
71
|
+
@config = config_from_cap_hash(cap.is_a?(Array) ? cap.first : cap, config)
|
72
|
+
@options = { :release_data => {}, :extra_information => {}, :data => {} }.merge(args.extract_options!)
|
73
|
+
|
74
|
+
@date = Date.today.to_s
|
75
|
+
@time = Time.now.strftime("%I:%M %p").to_s
|
76
|
+
@inferred_command = "cap #{@config[:rails_env]} #{@config[:task_name]}"
|
77
|
+
@task_name = @config[:task_name] || "unknown"
|
78
|
+
|
79
|
+
repo = @config[:repository]
|
80
|
+
x = repo.include?('/') ? repo.rindex('/') - 1 : repo.length
|
81
|
+
front = repo.slice(0..x)
|
82
|
+
back = repo.sub(front, '')
|
83
|
+
unless back == 'trunk'
|
84
|
+
x = front.include?('/') ? front.rindex('/') - 1 : front.length
|
85
|
+
front = front.slice(0..x)
|
86
|
+
end
|
87
|
+
@repo_end = repo.sub(front, '')
|
88
|
+
|
89
|
+
log = cap.fetch(:full_log)
|
90
|
+
fail_pattern = /^failed|rolling back/i
|
91
|
+
@job_status = (log =~ fail_pattern) ? :failure : cap.fetch(:mailer_status, :success)
|
92
|
+
template_prefix = @config[:template_prefixes][@job_status] ? "#{@config[:template_prefixes][@job_status]}." : ""
|
93
|
+
template_name = @config[:template_name] || "#{template_prefix}#{action_name}"
|
94
|
+
|
95
|
+
attach_log = case @config[:attach_log_on]
|
96
|
+
when Symbol, String
|
97
|
+
@job_status == @config[:attach_log_on].to_sym
|
98
|
+
when Array
|
99
|
+
@config[:attach_log_on].collect(&:to_sym).include? @job_status
|
100
|
+
else
|
101
|
+
false
|
102
|
+
end
|
103
|
+
|
104
|
+
# See: http://guides.rubyonrails.org/v2.3.11/action_mailer_basics.html#sending-emails-with-attachments
|
105
|
+
if attach_log
|
106
|
+
content_type "multipart/mixed"
|
107
|
+
|
108
|
+
part "multipart/alternative" do |alternative|
|
109
|
+
|
110
|
+
alternative.part "text/html" do |html|
|
111
|
+
html.body = render_message("#{template_name}.html", body_data_hash)
|
112
|
+
end if @config[:email_content_type] == "text/html"
|
113
|
+
|
114
|
+
alternative.part "text/plain" do |plain|
|
115
|
+
plain.body = render_message("#{template_name}.plain", body_data_hash)
|
116
|
+
end if @config[:email_content_type] == "text/plain"
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
attachment :content_type => "text/plain",
|
121
|
+
:body => log,
|
122
|
+
:filename => "deploy-log-#{Time.now.strftime("%Y-%m-%d-%H%M%S")}.txt"
|
123
|
+
else
|
124
|
+
content_type @config[:email_content_type]
|
125
|
+
body body_data_hash
|
126
|
+
end
|
127
|
+
|
128
|
+
subject "#{@job_status.to_s.upcase}: #{subject_line}"
|
129
|
+
recipients @config[:recipient_addresses]
|
130
|
+
from @config[:sender_address]
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
private
|
135
|
+
|
136
|
+
def subject_line
|
137
|
+
#The subject prepend and append are useful for people to setup filters in mail clients.
|
138
|
+
user = config[:user] ? " by #{config[:user]}" : ""
|
139
|
+
middle = config[:subject] ? config[:subject] : "[#{config[:rails_env].upcase}][#{repo_end}] #{inferred_command}#{user}"
|
140
|
+
"#{config[:subject_prepend]}#{middle}#{config[:subject_append]}"
|
141
|
+
end
|
142
|
+
|
143
|
+
def body_data_hash
|
144
|
+
options[:data].merge({
|
145
|
+
:section_data => section_data_hash,
|
146
|
+
:date => date,
|
147
|
+
:time => time,
|
148
|
+
:task_name => task_name,
|
149
|
+
:inferred_command => inferred_command,
|
150
|
+
:repo_end => repo_end,
|
151
|
+
:site_name => config[:site_name],
|
152
|
+
:site_url => config[:site_url],
|
153
|
+
:application => config[:application],
|
154
|
+
:sections => config[:sections]
|
155
|
+
})
|
156
|
+
end
|
157
|
+
|
158
|
+
def section_data_hash
|
159
|
+
{
|
160
|
+
:deployment => section_hash_deployment,
|
161
|
+
:source_control => section_hash_source_control,
|
162
|
+
:latest_release => section_hash_latest_release,
|
163
|
+
:previous_release => section_hash_previous_release,
|
164
|
+
:other_deployment_info => section_hash_other_deployment_info,
|
165
|
+
:release_data => options[:release_data],
|
166
|
+
:extra_information => options[:extra_information]
|
167
|
+
}
|
168
|
+
end
|
169
|
+
|
170
|
+
def section_hash_deployment
|
171
|
+
{
|
172
|
+
:date => date,
|
173
|
+
:time => time,
|
174
|
+
:rails_env => config[:rails_env],
|
175
|
+
:task_name => task_name,
|
176
|
+
:inferred_command => inferred_command,
|
177
|
+
:host => config[:host],
|
178
|
+
:release_name => config[:release_name],
|
179
|
+
:release_notes => config[:release_notes]
|
180
|
+
}
|
181
|
+
end
|
182
|
+
|
183
|
+
def section_hash_source_control
|
184
|
+
{
|
185
|
+
:revision => config[:revision],
|
186
|
+
:released => repo_end,
|
187
|
+
:repository => config[:repository],
|
188
|
+
:branch => config[:branch],
|
189
|
+
:scm => config[:scm],
|
190
|
+
:deploy_via => config[:deploy_via],
|
191
|
+
:deploy_to => config[:deploy_to]
|
192
|
+
}
|
193
|
+
end
|
194
|
+
|
195
|
+
def section_hash_latest_release
|
196
|
+
{
|
197
|
+
:latest_release => config[:latest_release],
|
198
|
+
:latest_revision => config[:latest_revision],
|
199
|
+
:release_path => config[:release_path],
|
200
|
+
:real_revision => config[:real_revision],
|
201
|
+
:current_path => config[:current_path]
|
202
|
+
}
|
203
|
+
end
|
204
|
+
|
205
|
+
def section_hash_previous_release
|
206
|
+
{
|
207
|
+
:current_release => config[:current_release],
|
208
|
+
:current_revision => config[:current_revision],
|
209
|
+
:previous_release => config[:previous_release],
|
210
|
+
:previous_revision => config[:previous_revision],
|
211
|
+
:releases => config[:releases]
|
212
|
+
}
|
213
|
+
end
|
214
|
+
|
215
|
+
def section_hash_other_deployment_info
|
216
|
+
{
|
217
|
+
:version_dir => config[:version_dir],
|
218
|
+
:shared_dir => config[:shared_dir],
|
219
|
+
:current_dir => config[:current_dir],
|
220
|
+
:releases_path => config[:releases_path],
|
221
|
+
:shared_path => config[:shared_path],
|
222
|
+
:run_method => config[:run_method],
|
223
|
+
:ip_address => config[:ip_address]
|
224
|
+
}
|
225
|
+
end
|
226
|
+
end
|
data/lib/capistrano/mailer.rb
CHANGED
@@ -1,25 +1,45 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
require '
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
|
1
|
+
require 'capistrano_mailer/version'
|
2
|
+
|
3
|
+
require 'capistrano'
|
4
|
+
|
5
|
+
unless Capistrano::Configuration.respond_to?(:instance)
|
6
|
+
abort 'capistrano/mailer requires Capistrano 2'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'capistrano/log_with_awesome'
|
10
|
+
require 'action_mailer'
|
11
|
+
|
12
|
+
require 'cap_mailer'
|
13
|
+
|
14
|
+
module CapistranoMailer
|
15
|
+
end
|
16
|
+
|
17
|
+
module Capistrano
|
18
|
+
class Configuration
|
19
|
+
module CapistranoMailer
|
20
|
+
def send_notification_email(cap, config = {}, *args)
|
21
|
+
CapMailer.deliver_notification_email(cap, config, *args)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
include CapistranoMailer
|
26
|
+
|
27
|
+
module Execution
|
28
|
+
protected
|
29
|
+
def __rollback_with_mailer!
|
30
|
+
set :mailer_status, :failure
|
31
|
+
find_and_execute_task "deploy:notify"
|
32
|
+
__rollback_without_mailer!
|
33
|
+
end
|
34
|
+
|
35
|
+
alias_method :__rollback_without_mailer!, :rollback!
|
36
|
+
alias_method :rollback!, :__rollback_with_mailer!
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
Capistrano.plugin :mailer, Capistrano::Configuration::CapistranoMailer
|
42
|
+
|
43
|
+
if cap = Capistrano::Configuration.instance
|
44
|
+
cap.load("#{File.expand_path(File.dirname(__FILE__))}/mailer_recipes.rb")
|
45
|
+
end
|