capistrano-mailgun 0.1.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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-mailgun.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Spike Grobstein
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # Capistrano-Mailgun
2
+
3
+ *Bust a cap in your deployment notifications*
4
+
5
+ Send emails with erb template bodies easily from inside your capistrano recipes.
6
+
7
+ Although built primarily for sending notification emails of deploys, it also includes nice helper methods
8
+ for sending any kind of email via the Mailgun API.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'capistrano-mailgun'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install capistrano-mailgun
23
+
24
+ In your `Capfile`, add:
25
+
26
+ require 'capistrano-mailgun'
27
+
28
+ ## Quickstart
29
+
30
+ To send a notification after deploy, add the following to your `deploy.rb` file:
31
+
32
+ require 'capistrano-mailgun'
33
+
34
+ set :mailgun_api_key, 'key-12345678901234567890123456789012' # your mailgun API key
35
+ set :mailgun_domain, 'example.com' # your mailgun email domain
36
+ set :mailgun_from, 'deployment@example.com' # who the email will appear to come from
37
+ set :mailgun_recipients, [ 'you@example.com', 'otherguy@example.com' ] # who will receive the email
38
+
39
+ # create an after:deploy hook
40
+ # pass it the path to an erb template.
41
+ # The erb template will have visibility into all your capistrano variables.
42
+ after(:deploy) { mailgun.notify_of_deploy File.join(File.dirname(__FILE__), 'mail.erb') }
43
+
44
+ You should then create a `mail.erb` file in the same directory as `deploy.rb`:
45
+
46
+ <%= application %> has just been deployed by <%= deployer_name %>, yay!
47
+
48
+ That's it. When you do a deploy, it should automatically send an email.
49
+
50
+ ## Capistrano Variables
51
+
52
+ `capistrano-mailgun` leverages variables defined in Capistrano to reduce the amount of configuration
53
+ you need to do. The following are all variables it supports:
54
+
55
+ ### mailgun_api_key (required)
56
+
57
+ Your API key. This MUST include the `key-` prefix.
58
+
59
+ ### mailgun_domain (required)
60
+
61
+ The domain of your Mailgun account. This is used when calling the API and is required.
62
+
63
+ ### mailgun_from (required for notify_of_deploy)
64
+
65
+ The email address that your notifications will appear to come from (by default).
66
+
67
+ ### mailgun_recipients (required for notify_of_deploy)
68
+
69
+ An array of email addresses who should recieve a notification when a deployment completes.
70
+
71
+ You can optionally only specify just the part of the email address before the @ and `capistrano-mailgun` will
72
+ automatically append the `mailgun_recipient_domain` to it. See `mailgun_recipient_domain`.
73
+
74
+ ### mailgun_recipient_domain
75
+
76
+ The domain that will be automatically appended to incomplete email addresses in the `mailgun_recipients`.
77
+
78
+ ### mailgun_subject
79
+
80
+ The subject to be used in deployment emails. This defaults to:
81
+
82
+ [Deployment] #{ application.capitalize } complete
83
+
84
+ Setting this will override the default.
85
+
86
+ ## Function API
87
+
88
+ `capistrano-mailgun` has a couple of methods to enable you to send emails easily. The following are the functions:
89
+
90
+ ### mailgun.notify_of_deploy(erb_path)
91
+
92
+ Given a path to an erb template file, it will send an email to recipients specified using the above
93
+ Capistrano variables.
94
+
95
+ See Quickstart, above, for an example.
96
+
97
+ ### mailgun.send_email( template, subject, recipients, from_address )
98
+
99
+ Given a path to a template, subject, recipients and a from\_address, send an email via the Mailgun API.
100
+
101
+ This function exists for convenience if you want to change the default behavior or notify during other events
102
+ triggered by Capistrano. `mailgun.send_email` adheres to the same behavior for recipients (automatically adding
103
+ the domain to the email addresses) as the regular `mailgun.notify_of_deploy` function.
104
+
105
+ The template will also be executed in the context of the recipe and will have access to everything that
106
+ capistrano has access to.
107
+
108
+ ### deployer_username
109
+
110
+ This is a default capistrano variable that is defined in the gyem. It will use the `git config user.name` if `scm` is
111
+ configured as `:git` or use `whoami` if not. This is handy if you want to notify people of which user
112
+ actually did the deployment.
113
+
114
+ ## Limitations
115
+
116
+ * Only supports plain-text emails. This should be fixed in the next release.
117
+ * Only supports ERB for templates. This should be changed in a future release.
118
+ * Simpler support for specifying templates? Should not need to pass absolute path, hopefully.
119
+ * Extremely limited access to Mailgun parameters. Eventually I'd like to add support for better customization of this.
120
+
121
+ ## Contributing
122
+
123
+ 1. Fork it
124
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
125
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
126
+ 4. Push to the branch (`git push origin my-new-feature`)
127
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/capistrano-mailgun/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Spike Grobstein"]
6
+ gem.email = ["spike@ticketevolution.com"]
7
+ gem.description = %q{Notify of deploys and other actions using mailgun}
8
+ gem.summary = %q{Notify of deploys and other actions using mailgun}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "capistrano-mailgun"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Capistrano::Mailgun::VERSION
17
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Mailgun
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,64 @@
1
+ require "capistrano-mailgun/version"
2
+ require 'restclient'
3
+ require 'erb'
4
+
5
+
6
+ module Capistrano
7
+ module Mailgun
8
+
9
+ # simple wrapper for sending an email with a given template
10
+ def send_email(template, subject, recipients, from_address)
11
+ RestClient.post "https://api:#{ mailgun_api_key }@api.mailgun.net/v2/#{ mailgun_domain }/messages",
12
+ :from => from_address,
13
+ :to => build_recipients( recipients ).join(','),
14
+ :subject => subject,
15
+ :text => ERB.new( File.open( find_template(template), 'r' ).read ).result(self.binding)
16
+ end
17
+
18
+ # does a deploy notification leveraging variables defined in capistrano.
19
+ def notify_of_deploy(template_name)
20
+ send_email( template_name, mailgun_subject, build_recipients( mailgun_recipients ), mailgun_from )
21
+ end
22
+
23
+ # kinda unused function for locating a provided template
24
+ def find_template(t)
25
+ return t
26
+ File.join( File.dirname(__FILE__), t )
27
+ end
28
+
29
+ private
30
+
31
+ # regenerates the recipients list using hte mailgun_domain for any reciients without domains
32
+ def build_recipients(recipients)
33
+ recipients.map do |r|
34
+ if r.match /.+?@.+?$/
35
+ r
36
+ else
37
+ "#{ r }@#{ mailgun_recipient_domain }"
38
+ end
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+
45
+ Capistrano::Configuration.instance.load do
46
+ Capistrano.plugin :mailgun, Capistrano::Mailgun
47
+
48
+ set(:mailgun_subject) { "[Deployment] #{ application.capitalize } completed" }
49
+
50
+ set(:mailgun_api_key) { abort "Please set mailgun_api_key accordingly" }
51
+ set(:mailgun_domain) { abort "Please set mailgun_domain accordingly" }
52
+ set(:mailgun_from) { abort "Please set mailgun_from to your desired From field" }
53
+ set(:mailgun_recipients) { abort "Please specify mailgun_recipients" }
54
+ set(:mailgun_recipient_domain) { abort "Please set mailgun_recipient_domain accordingly" }
55
+
56
+ set(:deployer_username) do
57
+ if fetch(:scm, nil).to_sym == :git
58
+ `git config user.name`.chomp
59
+ else
60
+ `whoami`.chomp
61
+ end
62
+ end
63
+
64
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-mailgun
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Spike Grobstein
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-11 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Notify of deploys and other actions using mailgun
15
+ email:
16
+ - spike@ticketevolution.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - capistrano-mailgun.gemspec
27
+ - lib/capistrano-mailgun.rb
28
+ - lib/capistrano-mailgun/version.rb
29
+ homepage: ''
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.24
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Notify of deploys and other actions using mailgun
53
+ test_files: []
54
+ has_rdoc: