capnotify 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -24,7 +24,7 @@ is made.
24
24
 
25
25
  Add this line to your application's Gemfile:
26
26
 
27
- gem "capnotify", "~> 0.1.6pre"
27
+ gem "capnotify", "~> 0.2"
28
28
 
29
29
  And then execute:
30
30
 
@@ -32,7 +32,7 @@ And then execute:
32
32
 
33
33
  Or install it yourself as:
34
34
 
35
- $ gem install capnotify --pre
35
+ $ gem install capnotify
36
36
 
37
37
  Then, in your `Capfile`, add the following line:
38
38
 
@@ -41,7 +41,8 @@ Then, in your `Capfile`, add the following line:
41
41
  ## Usage
42
42
 
43
43
  The current build of Capnotify is designed to be extended and doesn't provide much in the way
44
- of notifications out of the box. It does, however, provide a series of Capistrano callbacks
44
+ of notifications out of the box. It does, however, lay out a framework with default messages
45
+ and provides a series of Capistrano callbacks
45
46
  that you can hook into and leverage your existing notification system, be it IRC, Email,
46
47
  Hipchat, or Grove.io.
47
48
 
@@ -50,9 +51,14 @@ Following are a few examples for hooking up into these callbacks.
50
51
  ### Quickstart
51
52
 
52
53
  Capnotify can be used in your current deployment recipes and is easy to implement. The
53
- following examples will get you up and running with these callbacks.
54
+ following examples will get you up and running with these callbacks. When doing this, it's
55
+ up to you to hook the callbacks up to your existing notification system of choice, whether it's
56
+ a chat system like Grove.io and XMPP/Jabber or Twitter.
54
57
 
55
- #### Short Messages
58
+ Below you will see a basic overview of how to tap into Capnotify's built-in callbacks and leverage
59
+ the built-in messages.
60
+
61
+ ### Short Messages
56
62
 
57
63
  Capnotify has some built-in short messages right out of the box. If you'd like, for example,
58
64
  to send a short message notification when deployment starts and completes, it can be
@@ -67,17 +73,24 @@ done like the following:
67
73
  end
68
74
 
69
75
  In the case of the above example, replace the `SomeLib#send_message` call with your library's
70
- function.
76
+ function. The `capnotify_deploy_start_msg` and `capnotify_deploy_complete_msg` variables contain
77
+ some built-in messages that can be overridden by you in your recipes.
71
78
 
72
- A full list of available callbacks and built-in messages can be found below in the
73
- **Hooks and Callbacks** and **Messages** sections.
79
+ For example, to override `capnotify_deploy_start_msg`, you would do the following:
74
80
 
75
- #### Long Messages
81
+ set :capnotify_deploy_start_msg, "#{ capnotify.appname } deployment as BEGUN!"
76
82
 
77
- Capnotify also has built-in long message HTML templates and are primarily designed for
83
+ The above example uses a Capnotify built-in function `capnotify.appname` which builds a string
84
+ containing the `application` Capistrano variable and the `stage`. A full list of available callbacks
85
+ and built-in messages can be found in the wiki's
86
+ [Hooks and Callbacks](wiki/HooksAndCallbacks) and [Messages](wiki/Messages) sections.
87
+
88
+ ### Long Messages
89
+
90
+ Capnotify also has built-in long message Text/HTML templates and are primarily designed for
78
91
  building email messages, but don't necessarily need to be used for that.
79
92
 
80
- For an example of how to send an email, see the following:
93
+ For a basic example of how to use the built-in templates in your email library, see the following:
81
94
 
82
95
  on(:deploy_complete) do
83
96
  MyMailer.send_mail(
@@ -86,282 +99,40 @@ For an example of how to send an email, see the following:
86
99
  )
87
100
  end
88
101
 
102
+ Replace `MyMailer.send_email` with your email library's send method.
103
+
89
104
  The `capnotify_deployment_notification_text` and `capnotify_deployment_notification_html`
90
105
  Capistrano variables are lazily evaluated, and when called, will generate the deployment
91
106
  notification email bodies for text or html respectively.
92
107
 
93
- See the section **Built-in Templates** below for more information about templates and how
94
- to further customize them.
95
-
96
- ##### Components
97
-
98
- Long messages can be further customized through the use of Components. Using the
99
- `capnotify#components` function, you can add a `Capnotify::Component` which is a collection
100
- of information inside the body of an email. Capnotify comes with 2 built-in components:
101
- "Deployment Overview" and "Deployment Details" which contain the `ref`, `sha1`, deployer
102
- username, Github URL, deployment time, and repository information about the deployment.
103
-
104
- Some examples for extensions that could be added would be reports about deployment durations,
105
- commit logs, information about previous deploys, or custom email messages.
106
-
107
- A quick example of creating and appending a component to Capnotify is the following:
108
-
109
- capnotify.components << Capnotify::Component.new(:my_component) do |c|
110
- # this is the header that appears in the email:
111
- c.header = 'Deployment Overview'
112
-
113
- # initialize the content as a hash
114
- c.content = {}
115
-
116
- # build the collection of data
117
- c.content['Deployed by'] = capnotify.deployed_by
118
- c.content['Deployed at'] = Time.now
119
- c.content['Application'] = fetch(:application, '')
120
- c.content['Repository'] = fetch(:repository, '')
121
- end
122
-
123
- This above example is taken straight from the `Overview` extension that's built into
124
- Capnotify.
125
-
126
- This only scratched the surface of what you can do with this; for more information
127
- on Components, see the **Components** section below.
128
-
129
- #### More information
130
-
131
- In addition, to take the next step and create reusable code, you can create an
132
- Extension which can be packaged as a gem.
133
-
134
- See **Extensions** for information on building extensions.
135
-
136
- See **Hooks and Callbacks** for a list of available Capistrano callbacks.
137
-
138
- See **Components** for information on creating components.
139
-
140
- See **Built-in Templates** for information on customizing templates and replacing with
141
- your own templates.
142
-
143
- ## Hooks, Callbacks and Events
144
-
145
- Capnotify provides hooks and callbacks for common, notifiable tasks in addition
146
- to the standard Capistrano set.
147
-
148
- ### Default Hooks
108
+ See the section [Built-in Templates](wiki/Templates) in the wiki for more information about templates
109
+ and how to further customize them.
149
110
 
150
- Capnotify has a series of built-in default hooks that you can use to take action when
151
- certain events occur in your Capistrano recipes:
152
-
153
- * `deploy_start`
154
- * `deploy_complete`
155
- * `migrate_start`
156
- * `migrate_complete`
157
- * `maintenance_page_up`
158
- * `maintenance_page_down`
159
-
160
- Following are descriptions of each built-in hook with a brief description, purpose and
161
- time in which it is called, suggested associated messages
162
- (see **Messages** sections for more information about these) and an example of how to use it.
163
-
164
- #### deploy_start
165
-
166
- By default he `deploy_start` hook is called immediately before the
167
- `deploy` Capistrano task.
168
-
169
- Suggested message: `capnotify_deploy_start_msg`
170
-
171
- Example:
172
-
173
- on(:deploy_start) do
174
- MyService.notify( capnotify_deploy_start_msg )
175
- end
176
-
177
- #### deploy_complete
178
-
179
- By default the `deploy_complete` hook is called immediately after the `deploy`
180
- Capistrano task.
111
+ #### Long Messages
181
112
 
182
- Suggested message: `capnotify_deploy_complete_msg`
113
+ Capnotify also has built-in long message HTML templates and are primarily designed for
114
+ building email messages, but don't necessarily need to be used for that.
183
115
 
184
- Example:
116
+ For an example of how to send an email, see the following:
185
117
 
186
118
  on(:deploy_complete) do
187
- MyService.notify( capnotify_deploy_complete_msg )
188
- end
189
-
190
- #### migrate_start
191
-
192
- By default, the `migrate_start` hook is called immediately before `deploy:migrate`. This hook
193
- is designed to be used to notify DBAs of database changes or can be used to measure the
194
- elapsed time a migration takes.
195
-
196
- Suggested message: `capnotify_migrate_start_msg`
197
-
198
- Example:
199
-
200
- on(:migrate_start) do
201
- MyService.notify( capnotify_migrate_start_msg )
202
- end
203
-
204
- #### migrate_complete
205
-
206
- By default, the `migrate_complete` hook is called immediately after `deploy:migrate` finishes.
207
-
208
- Suggested message: `capnotify_migrate_complete_msg`
209
-
210
- Example:
211
-
212
- on(:migrate_complete) do
213
- MyService.notify( capnotify_migrate_complete_msg )
214
- end
215
-
216
- #### maintenance_page_up
217
-
218
- By default, the `maintenance_page_up` hook is called immediately before `deploy:web:disable`.
219
-
220
- Suggested message: `capnotify_maintenance_up_msg`
221
-
222
- Example:
223
-
224
- on(:maintenance_page_up) do
225
- MyService.notify( capnotify_maintenance_up_msg )
226
- end
227
-
228
- #### maintenance_page_down
229
-
230
- By default, the `maintenance_page_down` hook is called immediately after `deploy:web:enable`.
231
-
232
- Suggested message: `capnotify_maintenance_down_msg`
233
-
234
- Example:
235
-
236
- on(:maintenance_page_down) do
237
- MyService.notify( capnotify_maintenance_down_msg )
119
+ MyMailer.send_mail(
120
+ :text_body => capnotify_deployment_notification_text,
121
+ :html_body => capnotify_deployment_notification_html
122
+ )
238
123
  end
239
124
 
240
- ### Changing default callbacks
241
-
242
- Because not every Capistrano configuration is the same and not every application's needs match,
243
- Capnotify provides facilities to customize how the callbacks are called. In the event that your
244
- recipe uses different task names than the above, you can manually call the hooks using the
245
- `trigger` Capistrano function.
246
-
247
- For example, if you use a `deploy:api` task for deployment, but still want to leverage the
248
- `deploy_start` hook, you could do the following:
249
-
250
- before('deploy:api') { trigger :deploy_start }
251
- after('deploy:api') { trigger :deploy_complete }
252
-
253
- These hooks do not have to be triggered only inside `before`/`after` blocks; they can be
254
- called from anywhere by using `trigger :deploy_start`.
255
-
256
- ### Disabling default callbacks
257
-
258
- Setting the following Capistrano variables to `true` will disable the respective built-in
259
- hook pairs:
260
-
261
- * `capnotify_disable_deploy_hooks`
262
- * `capnotify_disable_migrate_hooks`
263
- * `capnotify_disable_maintenance_hooks`
264
-
265
- For example:
266
-
267
- set :capnotify_disable_deploy_hooks, true
268
-
269
- Will disable triggering both `deploy_start` and `deploy_complete`.
270
-
271
- These only affect the *built-in* hooks, so if you have an extension that defines its own, you
272
- should consult that extension's documentation for ways to disable its hooks. Extension
273
- developers are encouraged to implement the above methods in their own extensions for the sake
274
- of consistency.
275
-
276
- ## Built-in strings and functions
277
-
278
- Capnotify has a collection of built-in strings for messages that can be embedded or overridden.
279
- These are all built using the `capnotify.appname` function which contains the `application` and
280
- optional `stage` values (eg: `MyApplication production`).
281
-
282
- You can override these values by `set`ing the value in your recipe or extension. For example:
283
-
284
- set :capnotify_migrate_start_msg, "Migration has just begun!"
285
-
286
- ### capnotify.appname
287
-
288
- The `capnotify.appname` function calls the `capnotify_appname` Capistrano variable which,
289
- by default, combines the `application` and the optional `stage` variables. To override this,
290
- you can do something like the following example:
291
-
292
- set :capnotify_appname, "#{ application }/#{ branch } #{ stage.capitalize }"
293
-
294
- That will replace the behavior of the `capnotify.appname` calls.
295
-
296
- ### Short Messages
297
-
298
- The following messages are built-in using Capistrano variables. They can be overridden using
299
- the `set` command:
300
-
301
- * `capnotify_migrate_start_msg`
302
- * `capnotify_migrate_complete_msg`
303
- * `capnotify_deploy_start_msg`
304
- * `capnotify_deploy_complete_msg`
305
- * `capnotify_maintenance_up_msg`
306
- * `capnotify_maintenance_down_msg`
307
-
308
- ## Built-in Templates for Long Messages
309
-
310
- In addition to the Short Messages above, Capnotify comes with support for long-form messages
311
- for use in emails. There are built-in ERB templates for both HTML and Text emails.
312
-
313
- Two Capistrano variables are defined which build their associated templates when called, so
314
- the contents of the messages can be easily overridden if you'd like.
315
-
316
- ### capnotify_deployment_notification_html
317
-
318
- This will generate the HTML message, designed for notifying of a completed deployment. It
319
- will use the built-in template defined by `capnotify_deployment_notification_html_template_path`
320
- which points to the html template in this gem's `lib/capnotify/templates` directory.
321
-
322
- ### capnotify_deployment_notification_text
323
-
324
- This generates a plain-text message, designed for notifying of a completed deployment. It
325
- will use the built-in template defined by `capnotify_deployment_notification_text_template_path`
326
- which points to the html template in this gem's `lib/capnotify/templates` directory.
327
-
328
- ### Components
329
-
330
- At the core of each of these templates is the concept of Components. These components allow
331
- for the easy creation of sections in the email to put custom data and as an entry-point for
332
- extensions to add additional information to the emails/notifications.
333
-
334
- Each Component has a name which is used to reference it internally for working with
335
- it directly (i.e. deleting it from the email body or making changes to it after the fact).
336
- Outside of that, Components have the following properties:
337
-
338
- *Work in progress...*
339
-
340
- * header
341
- * custom css
342
- * custom css class
343
- * content
344
- * Hash
345
- * Array
346
- * String
347
- * custom templates
348
-
349
- also
350
-
351
- * appending / prepending components
352
- * deleting components
353
- * inserting components
354
- * getting component by name
355
- * lazy components
356
-
357
- This should probably be in the wiki rather than the readme.
125
+ The `capnotify_deployment_notification_text` and `capnotify_deployment_notification_html`
126
+ Capistrano variables are lazily evaluated, and when called, will generate the deployment
127
+ notification email bodies for text or html respectively.
358
128
 
359
- ## Extensions
129
+ See the section **Built-in Templates** below for more information about templates and how
130
+ to further customize them.
360
131
 
361
- It's possible to write extensions for Capnotify. Typically, these will be used to add new
362
- components to long messages.
132
+ ## More information
363
133
 
364
- Need to write this. This will probably wind up in the wiki instead of here.
134
+ The [Capnotify wiki](https://github.com/spikegrobstein/capnotify/wiki) is loaded with
135
+ documentation on all of the ins and outs of Capnotify.
365
136
 
366
137
  ## Contributing
367
138
 
data/lib/capnotify.rb CHANGED
@@ -49,7 +49,7 @@ module Capnotify
49
49
  # by default, the output should be: "STAGE APPNAME @ BRANCH"
50
50
  # override this to change the default behavior for capnotify.appname
51
51
  _cset(:capnotify_appname) do
52
- name = [ fetch(:stage, nil), fetch(:application, nil) ].compact.map{|c| c.capitalize}.join(" ")
52
+ name = [ fetch(:stage, nil), fetch(:application, nil) ].compact.join(" ")
53
53
  if fetch(:branch, nil)
54
54
  name = "#{ name } @ #{ branch }"
55
55
  end
@@ -113,39 +113,41 @@ module Capnotify
113
113
 
114
114
 
115
115
  on(:load) do
116
- # register the callbacks
117
- # These callbacks can be disabled by setting the following variables to a truthy value:
118
- # * capnotify_disable_deploy_hooks
119
- # * capnotify_disable_migrate_hooks
120
- # * capnotify_disable_maintenance_hooks
121
-
122
- # deploy start/complete
123
- unless fetch(:capnotify_disable_deploy_hooks, false)
124
- before('deploy') { trigger :deploy_start }
125
- after('deploy') { trigger :deploy_complete }
116
+ unless fetch(:capnotify_off, nil)
117
+ # register the callbacks
118
+ # These callbacks can be disabled by setting the following variables to a truthy value:
119
+ # * capnotify_disable_deploy_hooks
120
+ # * capnotify_disable_migrate_hooks
121
+ # * capnotify_disable_maintenance_hooks
122
+
123
+ # deploy start/complete
124
+ unless fetch(:capnotify_disable_deploy_hooks, false)
125
+ before('deploy') { trigger :deploy_start }
126
+ after('deploy') { trigger :deploy_complete }
127
+ end
128
+
129
+ # migration start/complete
130
+ unless fetch(:capnotify_disable_migrate_hooks, false)
131
+ before('deploy:migrate') { trigger :migrate_start }
132
+ after('deploy:migrate') { trigger :migrate_complete }
133
+ end
134
+
135
+ # maintenance start/complete
136
+ unless fetch(:capnotify_disable_maintenance_hooks, false)
137
+ after('deploy:web:disable') { trigger :maintenance_page_up }
138
+ after('deploy:web:enable') { trigger :maintenance_page_down }
139
+ end
140
+
141
+ # load the default plugins
142
+ # disable loading them by setting capnotify_disable_default_components to a truthy value
143
+ unless fetch(:capnotify_disable_default_components, false)
144
+ capnotify.load_default_plugins
145
+ end
146
+
147
+ # prints out a splash screen if capnotify_show_splash is set to true
148
+ # defaults to being silent.
149
+ capnotify.print_splash if fetch(:capnotify_show_splash, false)
126
150
  end
127
-
128
- # migration start/complete
129
- unless fetch(:capnotify_disable_migrate_hooks, false)
130
- before('deploy:migrate') { trigger :migrate_start }
131
- after('deploy:migrate') { trigger :migrate_complete }
132
- end
133
-
134
- # maintenance start/complete
135
- unless fetch(:capnotify_disable_maintenance_hooks, false)
136
- after('deploy:web:disable') { trigger :maintenance_page_up }
137
- after('deploy:web:enable') { trigger :maintenance_page_down }
138
- end
139
-
140
- # load the default plugins
141
- # disable loading them by setting capnotify_disable_default_components to a truthy value
142
- unless fetch(:capnotify_disable_default_components, false)
143
- capnotify.load_default_plugins
144
- end
145
-
146
- # prints out a splash screen if capnotify_show_splash is set to true
147
- # defaults to being silent.
148
- capnotify.print_splash if fetch(:capnotify_show_splash, false)
149
151
  end
150
152
 
151
153
  end
@@ -1,3 +1,3 @@
1
1
  module Capnotify
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -196,6 +196,67 @@ describe Capnotify do
196
196
 
197
197
  end
198
198
 
199
+ context "capnotify_off" do
200
+ context "when set" do
201
+
202
+ before do
203
+ # there has to be a better way of doing this...
204
+ # create a MockObject to handle the callbacks
205
+ class MockObject
206
+ end
207
+ MockObject.stub!(:deploy_start => true)
208
+ MockObject.stub!(:deploy_complete => true)
209
+ MockObject.stub!(:migrate_start => true)
210
+ MockObject.stub!(:migrate_complete => true)
211
+ MockObject.stub!(:maintenance_page_up => true)
212
+ MockObject.stub!(:maintenance_page_down => true)
213
+
214
+ config.load do
215
+ set :capnotify_off, true
216
+ # these don't get triggered unless something is defined.
217
+ on(:deploy_start) { MockObject.deploy_start }
218
+ on(:deploy_complete) { MockObject.deploy_complete }
219
+ on(:migrate_start) { MockObject.migrate_start }
220
+ on(:migrate_complete) { MockObject.migrate_complete }
221
+ on(:maintenance_page_up) { MockObject.maintenance_page_up }
222
+ on(:maintenance_page_down) { MockObject.maintenance_page_down }
223
+
224
+ # stub some tasks
225
+ namespace :deploy do
226
+ task(:default) {}
227
+ task(:migrate) {}
228
+ namespace :web do
229
+ task(:enable) {}
230
+ task(:disable) {}
231
+ end
232
+ end
233
+ end
234
+
235
+ config.trigger(:load)
236
+ end
237
+
238
+ it "should not load deploy hooks" do
239
+ MockObject.should_not_receive(:deploy_start)
240
+ MockObject.should_not_receive(:deploy_complete)
241
+ config.find_and_execute_task('deploy')
242
+ end
243
+
244
+ it "should not load migrate hooks" do
245
+ MockObject.should_not_receive(:migrate_start)
246
+ MockObject.should_not_receive(:migrate_complete)
247
+ config.find_and_execute_task('deploy:migrate')
248
+ end
249
+
250
+ it "should not load maintenance hooks" do
251
+ MockObject.should_not_receive(:maintenance_page_up)
252
+ MockObject.should_not_receive(:maintenance_page_down)
253
+ config.find_and_execute_task('deploy:web:enable')
254
+ config.find_and_execute_task('deploy:web:disable')
255
+ end
256
+
257
+ end
258
+ end
259
+
199
260
  context "capnotify_disable_default_components" do
200
261
 
201
262
  context "when it is set to true" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capnotify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
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: 2013-06-08 00:00:00.000000000 Z
12
+ date: 2013-06-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -153,7 +153,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
153
  version: '0'
154
154
  segments:
155
155
  - 0
156
- hash: -27722869543230501
156
+ hash: -3677415712418343694
157
157
  required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  none: false
159
159
  requirements:
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  version: '0'
163
163
  segments:
164
164
  - 0
165
- hash: -27722869543230501
165
+ hash: -3677415712418343694
166
166
  requirements: []
167
167
  rubyforge_project:
168
168
  rubygems_version: 1.8.24