capistrano-mailgun 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/README.md +12 -0
- data/capistrano-mailgun.gemspec +2 -1
- data/lib/capistrano-mailgun.rb +29 -9
- data/lib/capistrano-mailgun/version.rb +1 -1
- data/lib/templates/default.html.erb +13 -2
- data/lib/templates/default.txt.erb +6 -1
- data/spec/capistrano-mailgun_spec.rb +79 -0
- metadata +3 -8
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 2013-01-30 - v1.3.0
|
2
|
+
* added option to include list of servers deployed to in email notification
|
3
|
+
* fixed a bug where requiring `capistrano-mailgun` after you load `deploy.rb` would cause variables to be overwritten with defaults.
|
4
|
+
* don't call `mailgun.log_output` twice in html template
|
5
|
+
* fixed an issue where, depending on when `mailgun_notify` is called, it may or may not use the correct revisions when building the commit log.
|
6
|
+
|
1
7
|
## 2012-11-?? - v1.2.0
|
2
8
|
* properly handle failures when running git-log
|
3
9
|
|
data/README.md
CHANGED
@@ -217,6 +217,18 @@ or with the built-in `mailgun_notify` task.
|
|
217
217
|
|
218
218
|
See above `Disabling Emails` section for examples.
|
219
219
|
|
220
|
+
### mailgun_include_servers
|
221
|
+
|
222
|
+
Tnis variable is set to `false` by default. Setting to true will add the list of servers that are included in
|
223
|
+
the `deploy:update_code` task, which is any server that got code deployed to it.
|
224
|
+
|
225
|
+
This is useful for when you deploy to only a subset of servers using Capistrano's `HOSTS` or `ROLES` environment
|
226
|
+
variables in your deploy.
|
227
|
+
|
228
|
+
To enable the inclusion of the server list, you can add the following to your deployment configuration:
|
229
|
+
|
230
|
+
set :mailgun_include_servers, true
|
231
|
+
|
220
232
|
### github_url
|
221
233
|
|
222
234
|
If your project is hosted on Github and you'd like to have links to the Github repository in the deployment
|
data/capistrano-mailgun.gemspec
CHANGED
data/lib/capistrano-mailgun.rb
CHANGED
@@ -14,21 +14,32 @@ module Capistrano
|
|
14
14
|
|
15
15
|
Capistrano.plugin :mailgun, Capistrano::Mailgun
|
16
16
|
|
17
|
-
|
17
|
+
def _cset(name, *args, &block)
|
18
|
+
unless exists?(name)
|
19
|
+
set(name, *args, &block)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
_cset(:mailgun_subject) do
|
18
24
|
[ "[Deployment]", fetch(:stage, '').to_s.capitalize, fetch(:application, '').capitalize, 'deploy completed'].join(' ').gsub(/\s+/, ' ')
|
19
25
|
end
|
20
26
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
_cset(:mailgun_api_key) { abort "Please set mailgun_api_key accordingly" }
|
28
|
+
_cset(:mailgun_domain) { abort "Please set mailgun_domain accordingly" }
|
29
|
+
_cset(:mailgun_from) { abort "Please set mailgun_from to your desired From field" }
|
30
|
+
_cset(:mailgun_recipients) { abort "Please specify mailgun_recipients" }
|
31
|
+
_cset(:mailgun_recipient_domain) { abort "Please set mailgun_recipient_domain accordingly" }
|
32
|
+
|
33
|
+
# some internal variables that mailgun will use as the app runs
|
34
|
+
_cset(:mailgun_deploy_servers) { find_servers_for_task( find_task('deploy:update_code') ) }
|
26
35
|
|
27
36
|
# set these to nil to not use, or set to path to your custom template
|
28
|
-
|
29
|
-
|
37
|
+
_cset :mailgun_text_template, :deploy_text
|
38
|
+
_cset :mailgun_html_template, :deploy_html
|
30
39
|
|
31
|
-
|
40
|
+
_cset :mailgun_include_servers, false
|
41
|
+
|
42
|
+
_cset(:deployer_username) do
|
32
43
|
if fetch(:scm, '').to_sym == :git
|
33
44
|
`git config user.name`.chomp
|
34
45
|
else
|
@@ -36,6 +47,13 @@ module Capistrano
|
|
36
47
|
end
|
37
48
|
end
|
38
49
|
|
50
|
+
# before update_code, fetch the current revision
|
51
|
+
# this is needed to ensure that no matter when capistrano-mailgun fetches the commit logs that it
|
52
|
+
# has the correct starting point.
|
53
|
+
before 'deploy:update_code' do
|
54
|
+
set :mailgun_previous_revision, fetch(:current_revision, nil) # the revision that's currently deployed at this moment
|
55
|
+
end
|
56
|
+
|
39
57
|
# default mailgun email tasks
|
40
58
|
desc <<-DESC
|
41
59
|
Send a mailgun deployment notification.
|
@@ -118,6 +136,8 @@ module Capistrano
|
|
118
136
|
return @log_output unless @log_output.nil?
|
119
137
|
|
120
138
|
begin
|
139
|
+
raise "Ref missing" if first_ref.nil? || last_ref.nil? # jump to resque block.
|
140
|
+
|
121
141
|
log_output = run_locally("git log --oneline #{ first_ref }..#{ last_ref }")
|
122
142
|
|
123
143
|
@log_output = log_output = log_output.split("\n").map do |line|
|
@@ -124,13 +124,24 @@
|
|
124
124
|
</div>
|
125
125
|
<% end %>
|
126
126
|
|
127
|
-
<%
|
127
|
+
<% if fetch(:mailgun_include_servers, false) %>
|
128
|
+
<div id="mailgun_servers" class="section">
|
129
|
+
<h2>Deployed to:</h2>
|
130
|
+
<ul>
|
131
|
+
<% fetch(:mailgun_deploy_servers).each do |server| %>
|
132
|
+
<li><%= server.host %></l>
|
133
|
+
<% end %>
|
134
|
+
</ul>
|
135
|
+
</div>
|
136
|
+
<% end %>
|
137
|
+
|
138
|
+
<% log_output = mailgun.log_output(fetch(:mailgun_previous_revision, nil), fetch(:real_revision, nil)) %>
|
128
139
|
<% unless log_output.count == 0 %>
|
129
140
|
<div class="log">
|
130
141
|
<h2>Log:</h2>
|
131
142
|
|
132
143
|
<ul>
|
133
|
-
<%
|
144
|
+
<% log_output.each do |line| %>
|
134
145
|
<li>
|
135
146
|
<% if fetch(:github_url, nil) && line[0] != 'n/a' %>
|
136
147
|
<a href="<%= github_url %>/commit/<%= line[0] %>"><%= line[0] %></a>
|
@@ -16,7 +16,12 @@ Release: <%= fetch(:release_name, 'N/A') %>
|
|
16
16
|
<% end %>
|
17
17
|
|
18
18
|
<% if fetch(:url, nil) %>WWW: <%= fetch(:url) %><% end %>
|
19
|
-
<%
|
19
|
+
<% if fetch(:mailgun_include_servers, false) %>
|
20
|
+
Deployed to the following servers:
|
21
|
+
<% fetch(:mailgun_deploy_servers).each do |server| %> - <%= server.host %>
|
22
|
+
<% end %>
|
23
|
+
<% end %>
|
24
|
+
<% log_output = mailgun.log_output(fetch(:mailgun_previous_revision, nil), fetch(:real_revision, nil)) %>
|
20
25
|
<% unless log_output.count == 0 %>
|
21
26
|
Log:
|
22
27
|
---------------------------------------------------------------------------------
|
@@ -263,6 +263,85 @@ describe Capistrano::Mailgun do
|
|
263
263
|
|
264
264
|
end
|
265
265
|
|
266
|
+
context "collecting deployment servers" do
|
267
|
+
let(:server_hostnames) { config.fetch(:mailgun_deploy_servers).map(&:host) }
|
268
|
+
|
269
|
+
before do
|
270
|
+
config.load do
|
271
|
+
load 'deploy'
|
272
|
+
|
273
|
+
set :application, 'rspec-app'
|
274
|
+
set :repository, 'foo'
|
275
|
+
|
276
|
+
set :current_revision, nil
|
277
|
+
set :latest_revision, ''
|
278
|
+
set :release_name, ''
|
279
|
+
set :real_revision, ''
|
280
|
+
|
281
|
+
role :web, 'server-a'
|
282
|
+
role :app, 'server-b'
|
283
|
+
|
284
|
+
role :web, 'server-c', :no_release => true
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
context "#mailgun_deploy_servers" do
|
289
|
+
|
290
|
+
it "should find servers that are included in 'deploy'" do
|
291
|
+
server_hostnames.count.should == 2
|
292
|
+
server_hostnames.should include('server-a')
|
293
|
+
server_hostnames.should include('server-b')
|
294
|
+
end
|
295
|
+
|
296
|
+
it "should not find servers that are not included in 'deploy'" do
|
297
|
+
server_hostnames.should_not include('server-c')
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
context "templates" do
|
302
|
+
let(:result) { mailgun.send(:process_send_email_options, { :text_template => :deploy_text, :html_template => :deploy_html }) }
|
303
|
+
|
304
|
+
before do
|
305
|
+
require 'capistrano/recipes/deploy/scm/git'
|
306
|
+
Capistrano::Deploy::SCM::Git.any_instance.stub(:query_revision => '')
|
307
|
+
mailgun.stub!(:log_output => [])
|
308
|
+
end
|
309
|
+
|
310
|
+
context "when mailgun_include_servers is set to true" do
|
311
|
+
before do
|
312
|
+
config.load { set :mailgun_include_servers, true }
|
313
|
+
end
|
314
|
+
|
315
|
+
it "should include the servers in the text template" do
|
316
|
+
result[:text].should match('server-a')
|
317
|
+
end
|
318
|
+
|
319
|
+
it "should include the servers in the html template" do
|
320
|
+
result[:html].should match('server-a')
|
321
|
+
result[:html].should match('mailgun_servers')
|
322
|
+
end
|
323
|
+
|
324
|
+
end
|
325
|
+
|
326
|
+
context "when mailgun_include_servers is set to false" do
|
327
|
+
before do
|
328
|
+
config.load { set :mailgun_include_servers, false }
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should not include the servers in the text template" do
|
332
|
+
result[:text].should_not match('server-a')
|
333
|
+
end
|
334
|
+
|
335
|
+
it "should not include the servers in the html template" do
|
336
|
+
result[:html].should_not match('server-a')
|
337
|
+
result[:html].should_not match('mailgun_servers')
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
end
|
342
|
+
|
343
|
+
end
|
344
|
+
|
266
345
|
context "#process_send_email_options" do
|
267
346
|
let(:test_mailgun_domain) { 'example.com' }
|
268
347
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-mailgun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
@@ -81,18 +81,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
81
|
- - ! '>='
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
|
-
segments:
|
85
|
-
- 0
|
86
|
-
hash: -2899719465359232847
|
87
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
85
|
none: false
|
89
86
|
requirements:
|
90
87
|
- - ! '>='
|
91
88
|
- !ruby/object:Gem::Version
|
92
89
|
version: '0'
|
93
|
-
segments:
|
94
|
-
- 0
|
95
|
-
hash: -2899719465359232847
|
96
90
|
requirements: []
|
97
91
|
rubyforge_project:
|
98
92
|
rubygems_version: 1.8.24
|
@@ -105,3 +99,4 @@ test_files:
|
|
105
99
|
- spec/fixtures/text_body.erb
|
106
100
|
- spec/integration_spec.rb
|
107
101
|
- spec/spec_helper.rb
|
102
|
+
has_rdoc:
|