capistrano-mailgun 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1,4 +1,7 @@
1
- ## 2012-10-?? - v1.1.0
1
+ ## 2012-11-?? - v1.2.0
2
+ * properly handle failures when running git-log
3
+
4
+ ## 2012-10-22 - v1.1.0
2
5
  * default subject now includes stage
3
6
  * built-in templates
4
7
  * support for custom messages
data/README.md CHANGED
@@ -95,6 +95,24 @@ above is just an example.
95
95
 
96
96
  Also, notice the use of `mailgun.build_recipients`. See documentation below for more information.
97
97
 
98
+ ## Disabling Emails
99
+
100
+ If you want to prevent sending any email notifications for any reason, you can set the `mailgun_off`
101
+ Capistrano variable either via the `set` command or with the `-s` commandline options when calling
102
+ `cap`.
103
+
104
+ If using the Capistrano multistage plugin, you can put the following into one of your stage files
105
+ that you want to disable notifications for:
106
+
107
+ set :mailgun_off, true
108
+
109
+ Or, when doing a normal deploy and you want to prevent notifications for this deploy, you can do the
110
+ following:
111
+
112
+ cap deploy -s mailgun_off=1
113
+
114
+ Heads up: Setting `mailgun_off` to **anything** will disable emails. This includes setting it to `false`.
115
+
98
116
  ## Capistrano Variables
99
117
 
100
118
  `Capistrano::Mailgun` leverages variables defined in Capistrano to reduce the amount of configuration
@@ -191,6 +209,14 @@ You would call it in the following manner:
191
209
 
192
210
  cap deploy -s mailgun_message="Fixes that really nasty bug where our site does not work"
193
211
 
212
+ ### mailgun_off
213
+
214
+ Setting `mailgun_off` to any value, either via the `-s` commandline switch or with `set` in your recipe
215
+ will completely disable any Mailgun notifications, regardless of whether they're sent with `mailgun.send_email`
216
+ or with the built-in `mailgun_notify` task.
217
+
218
+ See above `Disabling Emails` section for examples.
219
+
194
220
  ### github_url
195
221
 
196
222
  If your project is hosted on Github and you'd like to have links to the Github repository in the deployment
@@ -57,7 +57,10 @@ module Capistrano
57
57
  # Supports all options that the Mailgun API supports. In addition, it also accepts:
58
58
  # * +:text_template+ -- the path to the template for the text body. It will be processed and interpolated and set the +text+ field when doing the API call.
59
59
  # * +:html_template+ -- the path to the template for the html body. It will be processed and interpolated and set the +html+ field when doing the API call.
60
+ #
61
+ # If +mailgun_off+ is set, this function will do absolutely nothing.
60
62
  def send_email(options)
63
+ return if exists?(:mailgun_off)
61
64
  options = process_send_email_options(options)
62
65
 
63
66
  RestClient.post build_mailgun_uri( mailgun_api_key, mailgun_domain ), options
@@ -106,14 +109,23 @@ module Capistrano
106
109
  end
107
110
 
108
111
  # git log between +first_ref+ to +last_ref+
112
+ # memoizes the output so this function can be called multiple times without re-running
113
+ # FIXME: memoization does not account for arguments
114
+ #
115
+ # returns an array of 2-element arrays in the form of
116
+ # [ ref, log_text ]
109
117
  def log_output(first_ref, last_ref)
110
118
  return @log_output unless @log_output.nil?
111
119
 
112
- log_output = run_locally("git log --oneline #{ first_ref }..#{ last_ref }")
120
+ begin
121
+ log_output = run_locally("git log --oneline #{ first_ref }..#{ last_ref }")
113
122
 
114
- @log_output = log_output = log_output.split("\n").map do |line|
115
- fields = line.split("\s", 2)
116
- [ fields[0], fields[1] ]
123
+ @log_output = log_output = log_output.split("\n").map do |line|
124
+ fields = line.split("\s", 2)
125
+ [ fields[0], fields[1] ]
126
+ end
127
+ rescue
128
+ [ [ 'n/a', 'Log output not available.' ] ]
117
129
  end
118
130
  end
119
131
 
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Mailgun
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -132,7 +132,7 @@
132
132
  <ul>
133
133
  <% mailgun.log_output(latest_revision, real_revision).each do |line| %>
134
134
  <li>
135
- <% if fetch(:github_url, nil) %>
135
+ <% if fetch(:github_url, nil) && line[0] != 'n/a' %>
136
136
  <a href="<%= github_url %>/commit/<%= line[0] %>"><%= line[0] %></a>
137
137
  <% else %>
138
138
  <%= line[0] %>
@@ -140,6 +140,37 @@ describe Capistrano::Mailgun do
140
140
  end
141
141
  end
142
142
 
143
+ context "mailgun_off" do
144
+
145
+ context "when it is set" do
146
+ before do
147
+ config.load do
148
+ set :mailgun_off, true
149
+ end
150
+
151
+ mailgun.stub!(:proces_send_email_options => true)
152
+ end
153
+
154
+ it "should not send emails when mailgun_off is set" do
155
+ RestClient.should_not_receive(:post)
156
+ mailgun.send_email({})
157
+ end
158
+
159
+ end
160
+
161
+ context "when it is not set" do
162
+ before do
163
+ mailgun.stub!(:process_send_email_options => true)
164
+ end
165
+
166
+ it "should send emails when mailgun_off is not set" do
167
+ RestClient.should_receive(:post)
168
+ mailgun.send_email({})
169
+ end
170
+ end
171
+
172
+ end
173
+
143
174
  end
144
175
 
145
176
  context "#notify_of_deploy" do
@@ -269,4 +300,27 @@ describe Capistrano::Mailgun do
269
300
 
270
301
  end
271
302
 
303
+ context "#log_output" do
304
+
305
+ context "when it raises an error" do
306
+
307
+ before do
308
+ mailgun.should_receive(:run_locally).and_raise(Capistrano::LocalArgumentError.new)
309
+ end
310
+
311
+ it "should only return a 1-element array if an error is returned from git-log" do
312
+ result = mailgun.log_output('a', 'b')
313
+
314
+ result.class.should == Array
315
+ result.length.should == 1
316
+ end
317
+
318
+ it "should capture the error and not raise if git-log fails" do
319
+ lambda { mailgun.log_output('a', 'b') }.should_not raise_error
320
+ end
321
+
322
+ end
323
+
324
+ end
325
+
272
326
  end
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.1.0
4
+ version: 1.2.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: 2012-10-22 00:00:00.000000000 Z
12
+ date: 2012-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -83,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
83
  version: '0'
84
84
  segments:
85
85
  - 0
86
- hash: 4576376367349129326
86
+ hash: -2899719465359232847
87
87
  required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  none: false
89
89
  requirements:
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  segments:
94
94
  - 0
95
- hash: 4576376367349129326
95
+ hash: -2899719465359232847
96
96
  requirements: []
97
97
  rubyforge_project:
98
98
  rubygems_version: 1.8.24