capistrano3-notifier 0.5.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8c6b26db000c8cc4076ac491f8345825a1b226c7
4
+ data.tar.gz: 940bd24c608aec2c7e8d3efb32ddc884626296d6
5
+ SHA512:
6
+ metadata.gz: 62c6d92d9f4e3152690cc87066cbe94d5e526f6be259a103527c169b5e3d9e5eda247d5c5e447c825381c171aaef02cca177432f7b752609bc87bd67fbd97ca0
7
+ data.tar.gz: 86fdd5549c72fe58d3008884fb6e60b6a9b3ed21b336f3a8be4d382be0d40f3e187eea295085d6dc5c4b5a531aaa110b81ce4699b2cd2429df0344ffa0f75634
data/.gitignore ADDED
@@ -0,0 +1,19 @@
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
18
+ .DS_Store
19
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format d
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.1.5
5
+ - 2.2.0
6
+ script: bundle exec rake spec
7
+ cache: bundler
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Justin Campbell
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,138 @@
1
+ # Capistrano3 Notifier [![Build Status](https://secure.travis-ci.org/applicaster/capistrano3-notifier.png)](https://secure.travis-ci.org/applicaster/capistrano3-notifier)
2
+
3
+ ##Rewrite of [Capistrano Notifier](https://github.com/gofullstack/capistrano-notifier) Gem for Capistrano3
4
+
5
+ ## Install
6
+
7
+ In your Gemfile:
8
+
9
+ ```rb
10
+ gem 'capistrano3-notifier'
11
+ ```
12
+
13
+ and then `bundle install`
14
+
15
+ `cap` needs to be invoked with Bundler for the `require` statements
16
+ below to work properly. You can do so with either `bundle exec cap`, or
17
+ with `bundle install --binstubs` and making sure `bin` is high up in your
18
+ `$PATH`.`
19
+
20
+
21
+ ## Mail
22
+
23
+ ```rb
24
+ require 'capistrano/notifier/mail'
25
+
26
+ set :notifier_mail_options, {
27
+ method: :test, # :smtp, :sendmail, or any other valid ActionMailer delivery method
28
+ from: 'capistrano@domain.com',
29
+ to: ['john@doe.com', 'jane@doe.com'],
30
+ subject: "Successfully deployed #{application.titleize} to #{stage}", # OPTIONAL
31
+ github: 'MyCompany/project-name'
32
+ }
33
+ ```
34
+
35
+ If you specified `method: :test`, you can see the email that would be
36
+ generated in your console with `cap deploy:notify:mail`.
37
+
38
+ If you specified `method: :smtp`, you can specify `:smtp_settings`
39
+
40
+ For example:
41
+
42
+ ```rb
43
+ set :notifier_mail_options, {
44
+ method: :smtp,
45
+ from: 'capistrano@domain.com',
46
+ to: ['john@doe.com', 'jane@doe.com'],
47
+ github: 'MyCompany/project-name',
48
+ smtp_settings: {
49
+ address: "smtp.gmail.com",
50
+ port: 587,
51
+ domain: "gmail.com",
52
+ authentication: "plain",
53
+ enable_starttls_auto: true,
54
+ user_name: MY_USERNAME,
55
+ password: MY_PASSWORD
56
+ }
57
+ }
58
+ ```
59
+
60
+ ### Templates
61
+
62
+ This gem comes with two different ERB templates that are used to generate the body of the email. To choose from each one of them, you can set the `format` option to either `:html` - for HTML emails - or `:text` - for plain text.
63
+
64
+ The following are the default values for the template options:
65
+
66
+ - `format`: `:text`
67
+ - `templates_path`: `"config/deploy/templates"`
68
+ - `template`: `"mail.#{format}.erb"`. Note the dependency of this option on `format`.
69
+
70
+ The relationship between these variables might seem a bit complex but provides great flexibility. The logic used is as follows:
71
+
72
+ - If the file exists in `"#{templates_path}/#{template}"`, then use that one. With no option set, this will default to `config/deploy/templates/mail.text.erb`.
73
+
74
+ - If the file doesn't exist in the previous path, load `"#{template}"` from one of the gem's templates, either `mail.text.erb` or `mail.html.erb`. With no options set, this will default to `mail.text.erb` due to how the `template` option is generated. See above.
75
+
76
+ For those interested in creating customized templates, it is important to know that you can use any of the variables defined in capistrano by prefixing it with the `cap` method like below:
77
+
78
+ ```rb
79
+ <%= fetch(:any_variable_defined_in_capistrano) %>
80
+ ```
81
+
82
+ The following is a list of some popular variables that don't require the use of the `cap.` prefix:
83
+
84
+ - `application`: Name of the application.
85
+ - `branch`: Name of the branch to be deployed.
86
+ - `git_commit_prefix`: URL of the format `"#{git_prefix}/commit"`.
87
+ - `git_compare_prefix`: URL of the format `"#{git_prefix}/compare"`.
88
+ - `git_current_revision`: Commit for current revision.
89
+ - `git_log`: Simplified log of commits in the `git_range`.
90
+ - `git_prefix`: URL to the github repository. Depends on `giturl` or `github` variables.
91
+ - `git_previous_revision`: Commit for previous revision.
92
+ - `git_range`: Range of commits between previous and current revision. Example: xxx..yyy
93
+ - `github_range`: Range of commits between previous and current revision in GitHub format. Example: xxx...yyy
94
+ - `github`: URL path to the GitHub respository. Ex: 'MyCompany/project-name'.
95
+ - `giturl`: Base URL to the repository.
96
+ - `now`: Current time.
97
+ - `stage`: Name of the stage from the capistrano multistage extension.
98
+ - `user_name`: Name of the local git author.
99
+
100
+ ## StatsD
101
+
102
+ ```rb
103
+ require 'capistrano/notifier/statsd'
104
+ ```
105
+
106
+ A counter of 1 will be sent with the key `application.stage.deploy` if using
107
+ multistage, or `application.deploy` if not. To use a gauge instead of a counter,
108
+ use `with: :gauge`:
109
+
110
+ ```rb
111
+ set :notifier_statsd_options, {
112
+ with: :gauge
113
+ }
114
+ ```
115
+
116
+ If you want to specify a host:port other than
117
+ 127.0.0.1:8125, you can do so like this:
118
+
119
+ ```rb
120
+ set :notifier_statsd_options, {
121
+ host: "10.0.0.1",
122
+ port: "8125"
123
+ }
124
+ ```
125
+
126
+ You can define the pattern that will be used to define the key.
127
+ In the example the key will be 'test.deployment.example'
128
+
129
+ ```rb
130
+ set :application, 'example'
131
+ set :stage, 'test'
132
+
133
+ set :notifier_statsd_options, {
134
+ pattern: "#{stage}.deployment.#{application}"
135
+ }
136
+ ```
137
+
138
+ The `nc` ([Netcat](http://netcat.sourceforge.net/)) command is used to send messages to statsd and must be installed on the remote hosts. This is installed by default on most Unix machines.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ begin
2
+ require 'bundler/gem_tasks'
3
+ rescue LoadError
4
+ puts "Ruby >= 1.9 required for build tasks"
5
+ end
6
+
7
+ require 'rspec/core/rake_task'
8
+
9
+ task default: :spec
10
+
11
+ desc "Run the test suite"
12
+ RSpec::Core::RakeTask.new
13
+
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/capistrano/notifier/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Justin Campbell", "Nathan L Smith", "Vitaly Gorodetsky"]
6
+ gem.email = ["sysadmin@cramerdev.com"]
7
+ gem.summary = %q{Capistrano3 Notifier}
8
+ gem.description = %q{Simple notification hooks for Capistrano3}
9
+ gem.homepage = "http://github.com/cramerdev/capistrano-notifier"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- spec/*`.split("\n")
14
+ gem.name = "capistrano3-notifier"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Capistrano::Notifier::VERSION
17
+
18
+ gem.add_dependency 'actionmailer', '~> 4.0'
19
+ gem.add_dependency 'capistrano', '~> 3.0'
20
+
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'rspec', '~> 3.0'
23
+ gem.add_development_dependency 'timecop'
24
+ gem.add_development_dependency 'pry'
25
+ end
@@ -0,0 +1,135 @@
1
+ module Capistrano
2
+ module Notifier
3
+ module Helpers
4
+ module Mail
5
+ def application
6
+ fetch :application
7
+ end
8
+
9
+ def branch
10
+ fetch(:branch, "master")
11
+ end
12
+
13
+ def git_current_revision
14
+ fetch :current_revision
15
+ end
16
+
17
+ def git_previous_revision
18
+ fetch :previous_revision
19
+ end
20
+
21
+ def git_range(ranger = "..")
22
+ return unless git_previous_revision && git_current_revision
23
+ "#{git_previous_revision}#{ranger}#{git_current_revision}"
24
+ end
25
+
26
+ def github_range
27
+ git_range("...")
28
+ end
29
+
30
+ def git_log_command
31
+ notifier_mail_options[:log_command]
32
+ end
33
+
34
+ def git_log
35
+ return unless git_range
36
+ command =
37
+ git_log_command || 'git log #{git_range} --no-merges --format=format:"%h %s (%an)"'
38
+
39
+ system_call(command)
40
+ end
41
+
42
+ def now
43
+ @now ||= Time.now
44
+ end
45
+
46
+ def stage
47
+ fetch :stage
48
+ end
49
+
50
+ def user_name
51
+ ENV['DEPLOYER'] || system_call("git config --get user.name").strip
52
+ end
53
+
54
+ def notifier_mail_options
55
+ @notifier_mail_options ||= fetch :notifier_mail_options
56
+ end
57
+
58
+ def email_format
59
+ notifier_mail_options[:format] || :text
60
+ end
61
+
62
+ def email_template
63
+ notifier_mail_options[:template] || "mail.#{email_format.to_s}.erb"
64
+ end
65
+
66
+ def email_from
67
+ notifier_mail_options[:from]
68
+ end
69
+
70
+ def github
71
+ notifier_mail_options[:github]
72
+ end
73
+
74
+ def giturl
75
+ notifier_mail_options[:giturl]
76
+ end
77
+
78
+ def git_prefix
79
+ giturl ? giturl : "https://github.com/#{github}"
80
+ end
81
+
82
+ def git_commit_prefix
83
+ "#{git_prefix}/commit"
84
+ end
85
+
86
+ def git_compare_prefix
87
+ "#{git_prefix}/compare"
88
+ end
89
+
90
+ def delivery_method
91
+ notifier_mail_options[:method]
92
+ end
93
+
94
+ def notifier_smtp_settings
95
+ notifier_mail_options[:smtp_settings]
96
+ end
97
+
98
+ def email_subject
99
+ notifier_mail_options[:subject] ||
100
+ "#{application} branch #{branch} deployed to #{stage}"
101
+ end
102
+
103
+ def render_template(template_name)
104
+ config_file = "#{templates_path}/#{template_name}"
105
+
106
+ unless File.exists?(config_file)
107
+ config_file = File.join(File.dirname(__FILE__),'..', "templates/#{template_name}")
108
+ end
109
+
110
+ ERB.new(File.read(config_file), nil, '-').result(binding)
111
+ end
112
+
113
+ def templates_path
114
+ notifier_mail_options[:templates_path] || 'config/deploy/templates'
115
+ end
116
+
117
+ def email_text
118
+ render_template(email_template)
119
+ end
120
+
121
+ def email_to
122
+ notifier_mail_options[:to]
123
+ end
124
+
125
+ def content_type_for_format(format = nil)
126
+ format == :html ? 'text/html' : 'text/plain'
127
+ end
128
+
129
+ def system_call(command)
130
+ `#{command}`
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,68 @@
1
+ module Capistrano
2
+ module Notifier
3
+ module Helpers
4
+ module StatsD
5
+ def application
6
+ fetch :application
7
+ end
8
+
9
+ def stage
10
+ fetch :stage
11
+ end
12
+
13
+ def notifier_statsd_options
14
+ @notifier_statsd_options ||= fetch :notifier_statsd_options
15
+ end
16
+
17
+ def statsd_defaults
18
+ { host: "127.0.0.1", port: "8125", with: :counter }
19
+ end
20
+
21
+ def statsd_host
22
+ statsd_options[:host]
23
+ end
24
+
25
+ def statsd_options
26
+ @statsd_options ||= if notifier_statsd_options
27
+ statsd_defaults.merge notifier_statsd_options
28
+ else
29
+ statsd_defaults
30
+ end
31
+ end
32
+
33
+ def statsd_packet
34
+ "#{statsd_pattern}:#{statsd_with}".gsub('|', '\\|')
35
+ end
36
+
37
+ def statsd_pattern
38
+ statsd_options.fetch(:pattern){ statsd_default_pattern }
39
+ end
40
+
41
+ def statsd_default_pattern
42
+ if stage
43
+ "#{application}.#{stage}.deploy"
44
+ else
45
+ "#{application}.deploy"
46
+ end
47
+ end
48
+
49
+ def statsd_port
50
+ statsd_options[:port]
51
+ end
52
+
53
+ def statsd_with
54
+ case statsd_options[:with]
55
+ when :counter
56
+ "1|c"
57
+ when :gauge
58
+ "1|g"
59
+ end
60
+ end
61
+
62
+ def statsd_notifier_command
63
+ "echo -n #{statsd_packet} | nc -w 1 -u #{statsd_host} #{statsd_port}"
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,28 @@
1
+ require 'action_mailer'
2
+ require 'capistrano/notifier/helpers/mail'
3
+ include Capistrano::Notifier::Helpers::Mail
4
+
5
+ namespace :deploy do
6
+ namespace :notify do
7
+ desc "Send a deployment notification via email."
8
+ task :mail do
9
+ run_locally do
10
+ ActionMailer::Base.smtp_settings = notifier_smtp_settings
11
+ ActionMailer::Base.mail({
12
+ body: email_text,
13
+ delivery_method: delivery_method,
14
+ content_type: content_type_for_format(email_format),
15
+ from: email_from,
16
+ subject: email_subject,
17
+ to: email_to
18
+ }).deliver
19
+
20
+ if delivery_method == :test
21
+ puts ActionMailer::Base.deliveries
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ after "deploy:updated", "deploy:notify:mail"
@@ -0,0 +1,15 @@
1
+ require 'capistrano/notifier/helpers/statsd'
2
+ include Capistrano::Notifier::Helpers::StatsD
3
+
4
+ namespace :deploy do
5
+ namespace :notify do
6
+ desc "Notify StatsD of deploy."
7
+ task :statsd do
8
+ on roles(:app) do |host|
9
+ execute statsd_notifier_command
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ after "deploy:updated", "deploy:notify:statsd"
@@ -0,0 +1,42 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5
+ </head>
6
+ <body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0">
7
+ <h3>Details:</h3>
8
+ <table>
9
+ <tbody>
10
+ <tr>
11
+ <td><strong>Deployer:</strong></td>
12
+ <td><%= user_name %></td>
13
+ </tr>
14
+ <tr>
15
+ <td><strong>Application:</strong></td>
16
+ <td><%= application %></td>
17
+ </tr>
18
+ <tr>
19
+ <td><strong>Branch:</strong></td>
20
+ <td><%= branch %></td>
21
+ </tr>
22
+ <tr>
23
+ <td><strong>Environment:</strong></td>
24
+ <td><%= stage %></td>
25
+ </tr>
26
+ <tr>
27
+ <td><strong>Time:</strong></td>
28
+ <td><%= now.strftime("%m/%d/%Y") %> at <%= now.strftime("%H:%M %Z") %></td>
29
+ </tr>
30
+ </tbody>
31
+ </table>
32
+
33
+ <h3>Compare:</h3>
34
+ <p><%= git_compare_prefix %>/<%= github_range %></p>
35
+
36
+ <h3>Commits:</h3>
37
+ <%- git_log.split(/\n/).each do |commit| -%>
38
+ <p><%= commit %></p>
39
+ <%- end if git_log -%>
40
+
41
+ </body>
42
+ </html>
@@ -0,0 +1,11 @@
1
+ Deployer: <%= user_name %>
2
+ Application: <%= application %>
3
+ Branch: <%= branch %>
4
+ Environment: <%= stage %>
5
+ Time: <%= now.strftime("%m/%d/%Y") %> at <%= now.strftime("%H:%M %Z") %>
6
+
7
+ Compare:
8
+ <%= git_compare_prefix %>/<%= github_range %>
9
+
10
+ Commits:
11
+ <%= git_log %>
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Notifier
3
+ VERSION = '0.5.0'
4
+ end
5
+ end
File without changes
@@ -0,0 +1,4 @@
1
+ Application: <%= application %>
2
+
3
+ Compare:
4
+ <%= git_compare_prefix %>/<%= github_range %>
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+ require 'capistrano/setup'
3
+ require 'capistrano/deploy'
4
+ require 'capistrano/notifier/mail'
5
+
6
+ describe "deploy:notify:mail" do
7
+ before do
8
+ Capistrano::Configuration.reset!.tap do |cfg|
9
+ cfg.set :application, "test-app"
10
+ cfg.set :stage, "test-stage"
11
+ cfg.set :notifier_mail_options, {
12
+ method: :test,
13
+ from: '"Deploy Notification" <deploy@example.com>',
14
+ to: ['deploy+test-app@example.com'],
15
+ github: 'applicaster/test-app',
16
+ }
17
+ end
18
+ end
19
+
20
+ it "works" do
21
+ Rake::Task["deploy:notify:mail"].invoke
22
+ expect(ActionMailer::Base.deliveries.first.subject)
23
+ .to eq("test-app branch master deployed to test-stage")
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ require 'capistrano/setup'
3
+ require 'capistrano/deploy'
4
+ require 'capistrano/notifier/statsd'
5
+
6
+ describe "deploy:notify:statsd" do
7
+ before do
8
+ Capistrano::Configuration.reset!.tap do |cfg|
9
+ cfg.set :application, "test-app"
10
+ cfg.set :stage, "test-stage"
11
+ cfg.set :notifier_statsd_options, {
12
+ host: "10.0.0.1",
13
+ port: "8125"
14
+ }
15
+ end
16
+ end
17
+
18
+ it "works" do
19
+ Rake::Task["deploy:notify:statsd"].invoke
20
+ end
21
+ end
@@ -0,0 +1,325 @@
1
+ require 'spec_helper'
2
+ require 'capistrano/notifier/helpers/mail'
3
+
4
+ describe Capistrano::Notifier::Helpers::Mail do
5
+ let(:configuration) { Capistrano::Configuration.new }
6
+ let(:dummy_class) { configuration.extend(Capistrano::Notifier::Helpers::Mail) }
7
+
8
+ before do
9
+ dummy_class.set(:notifier_mail_options, {})
10
+ end
11
+
12
+ describe "#application" do
13
+ before { dummy_class.set(:application, "testapp") }
14
+
15
+ it "fetches :application from Capistrano configuration" do
16
+ expect(dummy_class.application).to eq("testapp")
17
+ end
18
+ end
19
+
20
+ describe "#branch" do
21
+ context "when :branch is set in Capistrano configuration" do
22
+ before { dummy_class.set(:branch, "dev") }
23
+
24
+ it "fetches :branch from Capistrano configuration" do
25
+ expect(dummy_class.branch).to eq("dev")
26
+ end
27
+ end
28
+
29
+ context "when :branch is not set in Capistrano configuration" do
30
+ it "returns 'master'" do
31
+ expect(dummy_class.branch).to eq("master")
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "#git_current_revision" do
37
+ before { dummy_class.set(:current_revision, "949af5c") }
38
+
39
+ it "fetches :current_revision from Capistrano configuration" do
40
+ expect(dummy_class.git_current_revision).to eq("949af5c")
41
+ end
42
+ end
43
+
44
+ describe "#git_previous_revision" do
45
+ before { dummy_class.set(:previous_revision, "949af5c") }
46
+
47
+ it "fetches :previous_revision from Capistrano configuration" do
48
+ expect(dummy_class.git_previous_revision).to eq("949af5c")
49
+ end
50
+ end
51
+
52
+ describe "#git_range" do
53
+ context "when :current_revision and :previous_revision are set" do
54
+ before do
55
+ dummy_class.set(:current_revision, "949af5c")
56
+ dummy_class.set(:previous_revision, "0469d2d")
57
+ end
58
+
59
+ it "returns revisions range in git log format" do
60
+ expect(dummy_class.git_range).to eq("0469d2d..949af5c")
61
+ end
62
+ end
63
+
64
+ context "when :current_revision and :previous_revision are empty" do
65
+ it { expect(dummy_class.git_range).to eq(nil) }
66
+ end
67
+ end
68
+
69
+ describe "#git_log_command" do
70
+ before do
71
+ dummy_class.set(:notifier_mail_options, { log_command: "my command" })
72
+ end
73
+
74
+ it "fetches :log_command from :notifier_mail_options in Capistrano configuration" do
75
+ expect(dummy_class.git_log_command).to eq("my command")
76
+ end
77
+ end
78
+
79
+ describe "#git_log" do
80
+ before { allow(dummy_class).to receive(:git_range) { "0469d2d..949af5c" } }
81
+
82
+ context "when #git_range returns nil" do
83
+ before { allow(dummy_class).to receive(:git_range) { nil } }
84
+
85
+ it { expect(dummy_class.git_log).to eq(nil) }
86
+ end
87
+
88
+ context "when :log_command is set" do
89
+ before do
90
+ dummy_class.set(:notifier_mail_options, { log_command: "my command" })
91
+ end
92
+
93
+ it "runs system call with custom command" do
94
+ expect(dummy_class).to receive(:system_call).with("my command")
95
+ dummy_class.git_log
96
+ end
97
+ end
98
+
99
+ context "when :log_command not set" do
100
+ before { allow(dummy_class).to receive(:git_log_command) { nil } }
101
+
102
+ it "runs system call with deafult command" do
103
+ expect(dummy_class)
104
+ .to receive(:system_call)
105
+ .with('git log #{git_range} --no-merges --format=format:"%h %s (%an)"')
106
+
107
+ dummy_class.git_log
108
+ end
109
+ end
110
+ end
111
+
112
+ describe "#now" do
113
+ it "returns instance of Time.now" do
114
+ expect(Time).to receive(:now)
115
+ dummy_class.now
116
+ end
117
+ end
118
+
119
+ describe "#stage" do
120
+ before { dummy_class.set(:stage, "test") }
121
+
122
+ it "fetches :stage from Capistrano configuration" do
123
+ expect(dummy_class.stage).to eq("test")
124
+ end
125
+ end
126
+
127
+ describe "#user_name" do
128
+ context "when ENV['DEPLOYER'] is set" do
129
+ before do
130
+ allow(ENV).to receive(:[]).with("DEPLOYER") { "me" }
131
+ end
132
+
133
+ it { expect(dummy_class.user_name).to eq("me") }
134
+ end
135
+
136
+ context "when ENV['DEPLOYER'] not set" do
137
+ it "runs 'git config --get user.name'" do
138
+ expect(dummy_class)
139
+ .to receive(:system_call).with("git config --get user.name")
140
+ .and_return("")
141
+ dummy_class.user_name
142
+ end
143
+ end
144
+ end
145
+
146
+ describe "#notifier_mail_options" do
147
+ it "fetches :notifier_mail_options from Capistrano configuration" do
148
+ expect(dummy_class.notifier_mail_options).to eq({})
149
+ end
150
+ end
151
+
152
+ describe "#email_format" do
153
+ it "deafults to :text" do
154
+ expect(dummy_class.email_format).to eq(:text)
155
+ end
156
+
157
+ context "when set in :notifier_mail_options" do
158
+ before { dummy_class.set(:notifier_mail_options, { format: :plain }) }
159
+
160
+ it "works" do
161
+ expect(dummy_class.email_format).to eq(:plain)
162
+ end
163
+ end
164
+ end
165
+
166
+ describe "#email_template" do
167
+ it "deafults to 'mail.text.erb'" do
168
+ expect(dummy_class.email_template).to eq("mail.text.erb")
169
+ end
170
+
171
+ context "when set in :notifier_mail_options" do
172
+ before { dummy_class.set(:notifier_mail_options, { template: "mail.erb" }) }
173
+
174
+ it "works" do
175
+ expect(dummy_class.email_template).to eq("mail.erb")
176
+ end
177
+ end
178
+ end
179
+
180
+ describe "#email_from" do
181
+ before { dummy_class.set(:notifier_mail_options, { from: "test" }) }
182
+
183
+ it "works" do
184
+ expect(dummy_class.email_from).to eq("test")
185
+ end
186
+ end
187
+
188
+ describe "#github" do
189
+ before { dummy_class.set(:notifier_mail_options, { github: "test" }) }
190
+
191
+ it "works" do
192
+ expect(dummy_class.github).to eq("test")
193
+ end
194
+ end
195
+
196
+ describe "#giturl" do
197
+ before { dummy_class.set(:notifier_mail_options, { giturl: "test" }) }
198
+
199
+ it "works" do
200
+ expect(dummy_class.giturl).to eq("test")
201
+ end
202
+ end
203
+
204
+ describe "#git_prefix" do
205
+ before do
206
+ allow(dummy_class).to receive(:giturl) { "http://giturl" }
207
+ end
208
+
209
+ it "deafults to #giturl" do
210
+ expect(dummy_class.git_prefix).to eq("http://giturl")
211
+ end
212
+
213
+ context "when :notifier_mail_options not set" do
214
+ before do
215
+ allow(dummy_class).to receive(:giturl)
216
+ end
217
+
218
+ it "works" do
219
+ expect(dummy_class.git_prefix).to eq("https://github.com/")
220
+ end
221
+ end
222
+ end
223
+
224
+ describe "#git_commit_prefix" do
225
+ before do
226
+ allow(dummy_class).to receive(:git_prefix)
227
+ end
228
+
229
+ it "works" do
230
+ expect(dummy_class.git_commit_prefix).to eq("/commit")
231
+ end
232
+ end
233
+
234
+ describe "#git_compare_prefix" do
235
+ before do
236
+ allow(dummy_class).to receive(:git_prefix)
237
+ end
238
+
239
+ it "works" do
240
+ expect(dummy_class.git_compare_prefix).to eq("/compare")
241
+ end
242
+ end
243
+
244
+ describe "#delivery_method" do
245
+ before { dummy_class.set(:notifier_mail_options, { method: "test" }) }
246
+
247
+ it "works" do
248
+ expect(dummy_class.delivery_method).to eq("test")
249
+ end
250
+ end
251
+
252
+ describe "#notifier_smtp_settings" do
253
+ before { dummy_class.set(:notifier_mail_options, { smtp_settings: "test" }) }
254
+
255
+ it "works" do
256
+ expect(dummy_class.notifier_smtp_settings).to eq("test")
257
+ end
258
+ end
259
+
260
+ describe "#email_text" do
261
+ let(:templates_path) do
262
+ File.expand_path(File.join(__FILE__, '..','..','..','..','..','fixtures','templates'))
263
+ end
264
+
265
+ before do
266
+ allow(dummy_class).to receive(:templates_path) { templates_path }
267
+ allow(dummy_class).to receive(:application) { "testapp" }
268
+ allow(dummy_class).to receive(:github) { "applicaster/capistrano3-notifier" }
269
+ allow(dummy_class).to receive(:github_range) { "0469d2d...949af5c" }
270
+ end
271
+
272
+ it "renders email template" do
273
+ expect(dummy_class.email_text).to eq(
274
+ "Application: testapp\n\nCompare:\n"\
275
+ "https://github.com/applicaster/capistrano3-notifier/compare/0469d2d...949af5c\n"
276
+ )
277
+ end
278
+ end
279
+
280
+ describe "#email_subject" do
281
+ before do
282
+ allow(dummy_class).to receive(:application) { "testapp" }
283
+ allow(dummy_class).to receive(:branch) { "testbranch" }
284
+ allow(dummy_class).to receive(:stage) { "teststage" }
285
+ end
286
+
287
+ it "defaults to '#application branch #branch deployed to #stage'" do
288
+ expect(dummy_class.email_subject).to eq("testapp branch testbranch deployed to teststage")
289
+ end
290
+
291
+ it "can be set via :notifier_mail_options" do
292
+ dummy_class.set(:notifier_mail_options, { subject: "test subject" })
293
+ expect(dummy_class.email_subject).to eq("test subject")
294
+ end
295
+ end
296
+
297
+ describe "#templates_path" do
298
+ it "defaults to 'config/deploy/templates'" do
299
+ expect(dummy_class.templates_path).to eq("config/deploy/templates")
300
+ end
301
+
302
+ it "can be set via :notifier_mail_options" do
303
+ dummy_class.set(:notifier_mail_options, { templates_path: "templates" })
304
+ expect(dummy_class.templates_path).to eq("templates")
305
+ end
306
+ end
307
+
308
+ describe "#email_to" do
309
+ before { dummy_class.set(:notifier_mail_options, { to: "test" }) }
310
+
311
+ it "works" do
312
+ expect(dummy_class.email_to).to eq("test")
313
+ end
314
+ end
315
+
316
+ describe "#content_type_for_format" do
317
+ it "defaults to 'text/plain'" do
318
+ expect(dummy_class.content_type_for_format).to eq("text/plain")
319
+ end
320
+
321
+ it "returns 'text/html' if :html is passed as option" do
322
+ expect(dummy_class.content_type_for_format(:html)).to eq("text/html")
323
+ end
324
+ end
325
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require 'capistrano/notifier/helpers/statsd'
3
+
4
+ describe Capistrano::Notifier::Helpers::StatsD do
5
+ let(:configuration) { Capistrano::Configuration.new }
6
+ let(:dummy_class) { configuration.extend(Capistrano::Notifier::Helpers::StatsD) }
7
+
8
+ before do
9
+ dummy_class.set(:application, "test-app")
10
+ dummy_class.set(:stage, "test-stage")
11
+ dummy_class.set(:notifier_statsd_options, {})
12
+ end
13
+
14
+ describe "#statsd_notifier_command" do
15
+ it "works" do
16
+ expect(dummy_class.statsd_notifier_command)
17
+ .to eq("echo -n test-app.test-stage.deploy:1\\|c | nc -w 1 -u 127.0.0.1 8125")
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ require 'timecop'
2
+ require 'capistrano/all'
3
+
4
+ RSpec.configure do |config|
5
+ config.around :each do |example|
6
+ Timecop.freeze 2012, 1, 1 do
7
+ example.run
8
+ end
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano3-notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Campbell
8
+ - Nathan L Smith
9
+ - Vitaly Gorodetsky
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2015-02-17 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: actionmailer
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '4.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '4.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: capistrano
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '3.0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '3.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rspec
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '3.0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '3.0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: timecop
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: pry
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ description: Simple notification hooks for Capistrano3
100
+ email:
101
+ - sysadmin@cramerdev.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - LICENSE
111
+ - README.md
112
+ - Rakefile
113
+ - capistrano3-notifier.gemspec
114
+ - lib/capistrano/notifier/helpers/mail.rb
115
+ - lib/capistrano/notifier/helpers/statsd.rb
116
+ - lib/capistrano/notifier/mail.rb
117
+ - lib/capistrano/notifier/statsd.rb
118
+ - lib/capistrano/notifier/templates/mail.html.erb
119
+ - lib/capistrano/notifier/templates/mail.text.erb
120
+ - lib/capistrano/notifier/version.rb
121
+ - lib/capistrano3-notifier.rb
122
+ - spec/fixtures/templates/mail.text.erb
123
+ - spec/integration/capistrano/notifier/mail_spec.rb
124
+ - spec/integration/capistrano/notifier/statsd_spec.rb
125
+ - spec/lib/capistrano/notifier/helpers/mail_spec.rb
126
+ - spec/lib/capistrano/notifier/helpers/statsd_spec.rb
127
+ - spec/spec_helper.rb
128
+ homepage: http://github.com/cramerdev/capistrano-notifier
129
+ licenses: []
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.2.2
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Capistrano3 Notifier
151
+ test_files:
152
+ - spec/fixtures/templates/mail.text.erb
153
+ - spec/integration/capistrano/notifier/mail_spec.rb
154
+ - spec/integration/capistrano/notifier/statsd_spec.rb
155
+ - spec/lib/capistrano/notifier/helpers/mail_spec.rb
156
+ - spec/lib/capistrano/notifier/helpers/statsd_spec.rb
157
+ - spec/spec_helper.rb