cap_gun 0.0.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +12 -0
- data/.gitignore +3 -0
- data/MIT-LICENSE +1 -1
- data/{README.rdoc → README.markdown} +21 -17
- data/Rakefile +35 -18
- data/VERSION +1 -0
- data/cap_gun.gemspec +63 -83
- data/examples/cap_gun_example.rb +66 -0
- data/examples/example_helper.rb +19 -0
- data/examples/presenter_example.rb +86 -0
- data/lib/cap_gun.rb +19 -103
- data/lib/cap_gun/presenter.rb +133 -0
- data/version.yml +4 -0
- metadata +41 -26
- data/spec/cap_gun_spec.rb +0 -154
data/.autotest
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'autotest/menu'
|
2
|
+
|
3
|
+
Autotest.add_hook :initialize do |at|
|
4
|
+
at.clear_mappings
|
5
|
+
|
6
|
+
at.add_mapping(%r%lib/(.*)\.rb$%) { |filename, match|
|
7
|
+
at.files_matching %r%^spec/#{match[1]}.*\.rb$%
|
8
|
+
}
|
9
|
+
at.add_mapping(%r%^spec/.*\.rb$%) { |filename, match|
|
10
|
+
filename
|
11
|
+
}
|
12
|
+
end
|
data/.gitignore
ADDED
data/MIT-LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
# CapGun
|
2
2
|
|
3
|
-
|
3
|
+
## DESCRIPTION
|
4
4
|
|
5
5
|
Tell everyone about your releases! Send email notification after Capistrano deployments! Rule the world!
|
6
6
|
|
@@ -10,7 +10,7 @@ Setup and configuration are done entirely inside your deploy.rb file to keep it
|
|
10
10
|
|
11
11
|
This even includes the Net::SMTP TLS hack inside as a vendored dependancy to allow super easy email sending without setting up an MTA.
|
12
12
|
|
13
|
-
|
13
|
+
## CONFIG
|
14
14
|
|
15
15
|
In your Capistrano config file (usually deploy.rb):
|
16
16
|
|
@@ -27,51 +27,55 @@ In your Capistrano config file (usually deploy.rb):
|
|
27
27
|
}
|
28
28
|
|
29
29
|
# define the options for the actual emails that go out -- :recipients is the only required option
|
30
|
-
set :cap_gun_email_envelope, {
|
30
|
+
set :cap_gun_email_envelope, {
|
31
|
+
:from => "project.deployer@example.com", # Note, don't use the form "Someone project.deploy@example.com" as it'll blow up with ActionMailer 2.3+
|
32
|
+
:recipients => %w[joe@example.com, jane@example.com]
|
33
|
+
}
|
31
34
|
|
32
35
|
# register email as a callback after restart
|
33
36
|
after "deploy:restart", "cap_gun:email"
|
34
37
|
|
35
38
|
# Test everything out by running "cap cap_gun:email"
|
36
39
|
|
37
|
-
|
40
|
+
## USAGE
|
38
41
|
|
39
42
|
Good news: it just works.
|
40
43
|
|
44
|
+
By default CapGun includes info like the user who is deploying and what server its being deployed to. CapGun is biased for git (patches accepted for other SCMs), so it will include details like your current branch, the revisions since last deployment, the current commit being deployed.
|
45
|
+
|
41
46
|
Want to make the notifications even better and explain _why_ you're deploying?
|
42
47
|
Just include a comment in the cap command like so, and CapGun will add the comment to the email notification.
|
43
48
|
|
44
49
|
cap -s comment="fix for bug #303" deploy
|
45
50
|
|
46
|
-
|
51
|
+
## REQUIREMENTS
|
47
52
|
|
48
53
|
* Capistrano 2+
|
49
54
|
* A Gmail account to send from, or an MTA (mail transport agent) installed locally to send from
|
50
55
|
* Something to deploy
|
51
56
|
|
52
|
-
|
57
|
+
## TODO & KNOWN ISSUES
|
53
58
|
|
54
59
|
* displays the release times in UTC (Capistrano default) - could be flipped to specified time zone
|
55
|
-
* some stuff will probably break on windows
|
60
|
+
* some stuff will probably break on windows - patches welcome
|
56
61
|
|
57
|
-
|
62
|
+
## INSTALL
|
58
63
|
|
59
|
-
* sudo gem install cap_gun and gem unpack into your vendor/plugins
|
64
|
+
* `sudo gem install cap_gun` and gem unpack into your vendor/plugins
|
60
65
|
* or just grab the tarball from github (see below)
|
61
66
|
|
67
|
+
## URLS
|
62
68
|
|
63
|
-
|
64
|
-
|
65
|
-
*
|
66
|
-
*
|
67
|
-
* Git: git clone git://github.com/relevance/cap_gun.git
|
68
|
-
* RDocs: http://thinkrelevance.rubyforge.org/cap_gun/
|
69
|
+
* Log bugs, issues, and suggestions at GitHub: http://github.com/relevance/cap_gun/issues
|
70
|
+
* View source: http://github.com/relevance/cap_gun
|
71
|
+
* Continuos Integration: http://runcoderun.com/relevance/cap_gun
|
72
|
+
* RDocs: http://thinkrelevance.rubyforge.org/cap_gun
|
69
73
|
|
70
74
|
== LICENSE
|
71
75
|
|
72
76
|
(The MIT License)
|
73
77
|
|
74
|
-
Copyright (c)
|
78
|
+
Copyright (c) 2009 Relevance, Inc. - http://thinkrelevance.com
|
75
79
|
|
76
80
|
Permission is hereby granted, free of charge, to any person obtaining
|
77
81
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
@@ -1,19 +1,36 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "cap_gun"
|
5
|
+
gemspec.summary = "Bang! You're deployed."
|
6
|
+
gemspec.email = "opensource@thinkrelevance.com"
|
7
|
+
gemspec.homepage = "http://github.com/relevance/cap_gun"
|
8
|
+
gemspec.description = 'Super simple capistrano deployment notifications.'
|
9
|
+
gemspec.authors = ["Rob Sanheim", "Muness Alrubaie", "Relevance"]
|
10
|
+
gemspec.add_development_dependency "micronaut"
|
11
|
+
gemspec.add_development_dependency "mocha"
|
12
|
+
end
|
13
|
+
Jeweler::GemcutterTasks.new
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
16
|
+
end
|
5
17
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
begin
|
19
|
+
require 'micronaut/rake_task'
|
20
|
+
Micronaut::RakeTask.new(:examples) do |examples|
|
21
|
+
examples.pattern = 'examples/**/*_example.rb'
|
22
|
+
examples.ruby_opts << '-Ilib -Iexamples'
|
23
|
+
end
|
24
|
+
|
25
|
+
Micronaut::RakeTask.new(:rcov) do |examples|
|
26
|
+
examples.pattern = 'examples/**/*_example.rb'
|
27
|
+
examples.rcov_opts = %[-Ilib -Iexamples --exclude "gems/*,/Library/Ruby/*,config/*" --text-summary --sort coverage]
|
28
|
+
examples.rcov = true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if RUBY_VERSION =~ /1.8/
|
33
|
+
task :default => [:check_dependencies, :rcov]
|
34
|
+
else
|
35
|
+
task :default => [:check_dependencies, :examples]
|
36
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/cap_gun.gemspec
CHANGED
@@ -1,87 +1,67 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
|
2
|
-
|
3
|
-
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{cap_gun}
|
5
|
+
s.version = "0.2.0"
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Rob Sanheim", "Muness Alrubaie", "Relevance"]
|
9
|
+
s.date = %q{2009-06-21}
|
10
|
+
s.description = %q{Super simple capistrano deployment notifications.}
|
11
|
+
s.email = %q{opensource@thinkrelevance.com}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"README.markdown"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".autotest",
|
17
|
+
".gitignore",
|
18
|
+
"CHANGELOG",
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README.markdown",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"cap_gun.gemspec",
|
24
|
+
"examples/cap_gun_example.rb",
|
25
|
+
"examples/example_helper.rb",
|
26
|
+
"examples/presenter_example.rb",
|
27
|
+
"init.rb",
|
28
|
+
"install.rb",
|
29
|
+
"lib/cap_gun.rb",
|
30
|
+
"lib/cap_gun/presenter.rb",
|
31
|
+
"manifest.txt",
|
32
|
+
"tasks/cap_bot_tasks.rake",
|
33
|
+
"vendor/action_mailer_tls/README",
|
34
|
+
"vendor/action_mailer_tls/init.rb",
|
35
|
+
"vendor/action_mailer_tls/lib/smtp_tls.rb",
|
36
|
+
"vendor/action_mailer_tls/sample/mailer.yml.sample",
|
37
|
+
"vendor/action_mailer_tls/sample/smtp_gmail.rb",
|
38
|
+
"version.yml"
|
39
|
+
]
|
40
|
+
s.homepage = %q{http://github.com/relevance/cap_gun}
|
41
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubyforge_project = %q{thinkrelevance}
|
44
|
+
s.rubygems_version = %q{1.3.4}
|
45
|
+
s.summary = %q{Bang! You're deployed.}
|
46
|
+
s.test_files = [
|
47
|
+
"examples/cap_gun_example.rb",
|
48
|
+
"examples/example_helper.rb",
|
49
|
+
"examples/presenter_example.rb"
|
50
|
+
]
|
14
51
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
- !ruby/object:Gem::Dependency
|
19
|
-
name: echoe
|
20
|
-
type: :development
|
21
|
-
version_requirement:
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: "0"
|
27
|
-
version:
|
28
|
-
description: Super simple capistrano deployments.
|
29
|
-
email: opensource@thinkrelevance.com
|
30
|
-
executables: []
|
52
|
+
if s.respond_to? :specification_version then
|
53
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
54
|
+
s.specification_version = 3
|
31
55
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
- lib/cap_gun.rb
|
45
|
-
- manifest.txt
|
46
|
-
- MIT-LICENSE
|
47
|
-
- Rakefile
|
48
|
-
- README.rdoc
|
49
|
-
- spec/cap_gun_spec.rb
|
50
|
-
- tasks/cap_bot_tasks.rake
|
51
|
-
- vendor/action_mailer_tls/init.rb
|
52
|
-
- vendor/action_mailer_tls/lib/smtp_tls.rb
|
53
|
-
- vendor/action_mailer_tls/README
|
54
|
-
- vendor/action_mailer_tls/sample/mailer.yml.sample
|
55
|
-
- vendor/action_mailer_tls/sample/smtp_gmail.rb
|
56
|
-
has_rdoc: true
|
57
|
-
homepage: http://opensource.thinkrelevance.com/wiki/cap_gun
|
58
|
-
post_install_message:
|
59
|
-
rdoc_options:
|
60
|
-
- --line-numbers
|
61
|
-
- --inline-source
|
62
|
-
- --title
|
63
|
-
- Cap_gun
|
64
|
-
- --main
|
65
|
-
- README.rdoc
|
66
|
-
require_paths:
|
67
|
-
- lib
|
68
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
-
requirements:
|
70
|
-
- - ">="
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
version: "0"
|
73
|
-
version:
|
74
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
-
requirements:
|
76
|
-
- - ">="
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
version: "1.2"
|
79
|
-
version:
|
80
|
-
requirements: []
|
81
|
-
|
82
|
-
rubyforge_project: thinkrelevance
|
83
|
-
rubygems_version: 1.3.0
|
84
|
-
specification_version: 2
|
85
|
-
summary: Bang! You're deployed!
|
86
|
-
test_files:
|
87
|
-
- spec/cap_gun_spec.rb
|
56
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
57
|
+
s.add_development_dependency(%q<spicycode-micronaut>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<spicycode-micronaut>, [">= 0"])
|
61
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<spicycode-micronaut>, [">= 0"])
|
65
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[example_helper])
|
2
|
+
|
3
|
+
describe CapGun do
|
4
|
+
|
5
|
+
it "uses action mailer hack" do
|
6
|
+
Net::SMTP.new('').respond_to?(:starttls, true).should == true
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "mail settings" do
|
10
|
+
|
11
|
+
it "raises if we don't have settings" do
|
12
|
+
capistrano = stub_everything
|
13
|
+
lambda {
|
14
|
+
CapGun::Mailer.load_mailer_config(capistrano)
|
15
|
+
}.should raise_error(ArgumentError, "You must define ActionMailer settings in 'cap_gun_action_mailer_config'")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "gets action mailer config from capistrano" do
|
19
|
+
capistrano = stub(:cap_gun_action_mailer_config => {:account => "foo@gmail.com", :password => "password"}, :exists? => true)
|
20
|
+
capistrano.stubs(:[]).returns({:recipients => 'foo'})
|
21
|
+
CapGun::Mailer.load_mailer_config(capistrano)
|
22
|
+
ActionMailer::Base.smtp_settings.should == {:account => "foo@gmail.com", :password => "password"}
|
23
|
+
end
|
24
|
+
|
25
|
+
it "raises if don't have a cap gun email envelope" do
|
26
|
+
capistrano = stub_everything(:cap_gun_action_mailer_config => {}, :exists? => false)
|
27
|
+
lambda {
|
28
|
+
CapGun::Mailer.load_mailer_config capistrano
|
29
|
+
}.should raise_error(ArgumentError)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "raises if we don't have at least one recipient" do
|
33
|
+
capistrano = stub_everything(:cap_gun_action_mailer_config => {}, :cap_gun_email_envelope => {})
|
34
|
+
lambda {
|
35
|
+
CapGun::Mailer.load_mailer_config capistrano
|
36
|
+
}.should raise_error(ArgumentError)
|
37
|
+
capistrano = stub_everything(:cap_gun_action_mailer_config => {}, :cap_gun_email_envelope => {:recipients => []})
|
38
|
+
lambda {
|
39
|
+
CapGun::Mailer.load_mailer_config capistrano
|
40
|
+
}.should raise_error(ArgumentError)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe CapGun::Mailer do
|
46
|
+
|
47
|
+
it "calls Net::SMTP to send the mail correctly (we test this because SMTP internals changed between 1.8.6 and newer versions of Ruby)" do
|
48
|
+
ActionMailer::Base.smtp_settings = {
|
49
|
+
:address => "smtp.gmail.com",
|
50
|
+
:port => 587,
|
51
|
+
:domain => "foo.com",
|
52
|
+
:authentication => :plain,
|
53
|
+
:user_name => "username",
|
54
|
+
:password => "password"
|
55
|
+
}
|
56
|
+
|
57
|
+
capistrano = { :current_release => "/data/foo", :previous_release => "/data/foo", :cap_gun_email_envelope => {:recipients => ["joe@example.com"]} }
|
58
|
+
smtp = Net::SMTP.new('gmail.com', 25)
|
59
|
+
Net::SMTP.expects(:new).returns(smtp)
|
60
|
+
smtp.expects(:start)
|
61
|
+
CapGun::Mailer.deliver_deployment_notification capistrano
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require 'net/smtp'
|
3
|
+
require "mocha"
|
4
|
+
require 'micronaut'
|
5
|
+
require File.join(File.dirname(__FILE__), *%w[.. lib cap_gun])
|
6
|
+
|
7
|
+
def silence_warnings
|
8
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
9
|
+
yield
|
10
|
+
ensure
|
11
|
+
$VERBOSE = old_verbose
|
12
|
+
end
|
13
|
+
|
14
|
+
Micronaut.configure do |config|
|
15
|
+
config.mock_with :mocha
|
16
|
+
config.formatter = :documentation
|
17
|
+
config.color_enabled = true
|
18
|
+
config.filter_run :options => { :focused => true }
|
19
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[example_helper])
|
2
|
+
|
3
|
+
describe CapGun::Presenter do
|
4
|
+
|
5
|
+
describe "git details" do
|
6
|
+
|
7
|
+
it "does nothing if git is not the scm" do
|
8
|
+
presenter = CapGun::Presenter.new(stub("capistrano", :scm => :svn))
|
9
|
+
presenter.git_details.should == nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "collects branch and git log details if git is scm" do
|
13
|
+
capistrano = {:scm => :git, :branch => "edge"}
|
14
|
+
presenter = CapGun::Presenter.new(capistrano)
|
15
|
+
presenter.expects(:git_log).returns("xxxxx")
|
16
|
+
|
17
|
+
details = presenter.git_details
|
18
|
+
details.should include("Branch: edge")
|
19
|
+
details.should include("xxxxx")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "git log messages" do
|
24
|
+
|
25
|
+
it "returns N/A if the git log call returns an error" do
|
26
|
+
capistrano = { :previous_revision => "previous-sha", :current_revision => "current-sha" }
|
27
|
+
presenter = CapGun::Presenter.new(capistrano)
|
28
|
+
presenter.stubs(:`).returns("fatal: Not a git repo")
|
29
|
+
presenter.stubs(:exit_code).returns(stub("process status", :success? => false))
|
30
|
+
presenter.git_log_messages.should == "N/A"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "calls git log with previous_rev..current_rev" do
|
34
|
+
capistrano = { :previous_revision => "previous-sha", :current_revision => "current-sha" }
|
35
|
+
presenter = CapGun::Presenter.new(capistrano)
|
36
|
+
presenter.stubs(:exit_code).returns(stub("process status", :success? => true))
|
37
|
+
presenter.expects(:`).with(includes("git log previous-sha..current-sha"))
|
38
|
+
presenter.git_log_messages
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "release time" do
|
43
|
+
|
44
|
+
before do # make DateTime act as if local timezone is CDT
|
45
|
+
@presenter = CapGun::Presenter.new(nil)
|
46
|
+
@presenter.stubs(:local_timezone).returns("CDT")
|
47
|
+
@presenter.stubs(:local_datetime_zone_offset).returns(Rational(-1,6))
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns nil for weird release path" do
|
51
|
+
@presenter.humanize_release_time("/data/foo/my_release").should == nil
|
52
|
+
end
|
53
|
+
|
54
|
+
it "parse datetime from release path" do
|
55
|
+
@presenter.humanize_release_time("/data/foo/releases/20080227120000").should == "February 27th, 2008 8:00 AM CDT"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "converts time from release into localtime" do
|
59
|
+
@presenter.humanize_release_time("/data/foo/releases/20080410040000").should == "April 10th, 2008 12:00 AM CDT"
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "from and to emails" do
|
65
|
+
|
66
|
+
it "gets recipients from email envelope" do
|
67
|
+
capistrano = { :cap_gun_email_envelope => { :recipients => ["foo@here.com", "bar@here.com"] } }
|
68
|
+
presenter = CapGun::Presenter.new(capistrano)
|
69
|
+
presenter.recipients.should == ["foo@here.com", "bar@here.com"]
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should have a default sender" do
|
73
|
+
capistrano = { :cap_gun_email_envelope => { } }
|
74
|
+
presenter = CapGun::Presenter.new(capistrano)
|
75
|
+
presenter.from.should == "\"CapGun\" <cap_gun@example.com>"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should override sender from email envelope" do
|
79
|
+
capistrano = { :cap_gun_email_envelope => { :from => "booyakka!@example.com" } }
|
80
|
+
presenter = CapGun::Presenter.new(capistrano)
|
81
|
+
presenter.from.should == "booyakka!@example.com"
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
data/lib/cap_gun.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'action_mailer'
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), *%w[cap_gun presenter])
|
2
4
|
require File.join(File.dirname(__FILE__), *%w[.. vendor action_mailer_tls lib smtp_tls])
|
3
5
|
|
4
6
|
# Tell everyone about your releases! Send email notification after Capistrano deployments! Rule the world!
|
@@ -26,121 +28,35 @@ require File.join(File.dirname(__FILE__), *%w[.. vendor action_mailer_tls lib sm
|
|
26
28
|
#
|
27
29
|
# See README for full install/config instructions.
|
28
30
|
module CapGun
|
29
|
-
VERSION = '0.0.
|
31
|
+
VERSION = '0.0.11'
|
30
32
|
|
31
|
-
module Helper
|
32
|
-
|
33
|
-
# Loads ActionMailer settings from a Capistrano variable called "cap_gun_action_mailer_config"
|
34
|
-
def load_mailer_config(cap)
|
35
|
-
raise ArgumentError, "You must define ActionMailer settings in 'cap_gun_action_mailer_config'" unless cap.cap_gun_action_mailer_config
|
36
|
-
raise ArgumentError, "Need at least one recipient." if !cap.exists?(:cap_gun_email_envelope) || cap[:cap_gun_email_envelope][:recipients].blank?
|
37
|
-
|
38
|
-
ActionMailer::Base.smtp_settings = cap.cap_gun_action_mailer_config
|
39
|
-
end
|
40
|
-
|
41
|
-
# Current user - unsupported on Windows, patches welcome
|
42
|
-
def current_user
|
43
|
-
platform.include?('mswin') ? nil : `id -un`.strip
|
44
|
-
end
|
45
|
-
|
46
|
-
# stub hook purposes only
|
47
|
-
def platform
|
48
|
-
RUBY_PLATFORM
|
49
|
-
end
|
50
|
-
|
51
|
-
# Gives you a prettier date/time for output from the standard Capistrano timestamped release directory.
|
52
|
-
# This assumes Capistrano uses UTC for its date/timestamped directories, and converts to the local
|
53
|
-
# machine timezone.
|
54
|
-
def humanize_release_time(path)
|
55
|
-
return unless path
|
56
|
-
match = path.match(/(\d+)$/)
|
57
|
-
return unless match
|
58
|
-
local = convert_from_utc(match[1])
|
59
|
-
local.strftime("%B #{local.day.ordinalize}, %Y %l:%M %p #{local_timezone}").gsub(/\s+/, ' ').strip
|
60
|
-
end
|
61
|
-
|
62
|
-
# Use some DateTime magicrey to convert UTC to the current time zone
|
63
|
-
# When the whole world is on Rails 2.1 (and therefore new ActiveSupport) we can use the magic timezone support there.
|
64
|
-
def convert_from_utc(timestamp)
|
65
|
-
# we know Capistrano release timestamps are UTC, but Ruby doesn't, so make it explicit
|
66
|
-
utc_time = timestamp << "UTC"
|
67
|
-
datetime = DateTime.parse(utc_time)
|
68
|
-
datetime.new_offset(local_datetime_zone_offset)
|
69
|
-
end
|
70
|
-
|
71
|
-
def local_datetime_zone_offset
|
72
|
-
@local_datetime_zone_offset ||= DateTime.now.offset
|
73
|
-
end
|
74
|
-
|
75
|
-
def local_timezone
|
76
|
-
@current_timezone ||= Time.now.zone
|
77
|
-
end
|
78
|
-
|
79
|
-
extend self
|
80
|
-
end
|
81
|
-
|
82
33
|
# This mailer is configured with a capistrano variable called "cap_gun_email_envelope"
|
83
34
|
class Mailer < ActionMailer::Base
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
35
|
+
|
36
|
+
def self.load_mailer_config(cap)
|
37
|
+
raise ArgumentError, "You must define ActionMailer settings in 'cap_gun_action_mailer_config'" unless cap.cap_gun_action_mailer_config
|
38
|
+
raise ArgumentError, "Need at least one recipient." if !cap.exists?(:cap_gun_email_envelope) || cap[:cap_gun_email_envelope][:recipients].blank?
|
39
|
+
|
40
|
+
ActionMailer::Base.smtp_settings = cap.cap_gun_action_mailer_config
|
41
|
+
end
|
90
42
|
|
91
|
-
# Grab the options for emailing from cap_gun_email_envelope (should be set in your deploy file)
|
43
|
+
# Grab the options for emailing from capistrano[:cap_gun_email_envelope] (should be set in your deploy file)
|
92
44
|
#
|
93
45
|
# Valid options:
|
94
46
|
# :recipients (required) an array or string of email address(es) that should get notifications
|
95
47
|
# :from the sender of the notification, defaults to cap_gun@example.com
|
96
48
|
# :email_prefix subject prefix, defaults to [DEPLOY]
|
97
|
-
def init(envelope = {})
|
98
|
-
recipients envelope[:recipients]
|
99
|
-
from (envelope[:from] || DEFAULT_SENDER)
|
100
|
-
email_prefix (envelope[:email_prefix] || DEFAULT_EMAIL_PREFIX)
|
101
|
-
end
|
102
|
-
|
103
|
-
# Do the actual email
|
104
49
|
def deployment_notification(capistrano)
|
105
|
-
|
106
|
-
self.summary = create_summary(capistrano)
|
50
|
+
presenter = Presenter.new(capistrano)
|
107
51
|
|
108
52
|
content_type "text/plain"
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
def create_summary(capistrano)
|
114
|
-
%[#{capistrano[:application]} was deployed#{" to " << capistrano[:rails_env] if capistrano[:rails_env]} by #{current_user} at #{humanize_release_time(capistrano[:current_release])}.]
|
115
|
-
end
|
116
|
-
|
117
|
-
def deployed_to(capistrano)
|
118
|
-
returning(deploy_msg = "deployed") { |msg| msg << " to #{capistrano[:rails_env]}" if capistrano[:rails_env] }
|
119
|
-
end
|
120
|
-
|
121
|
-
# Create the body of the message using a bunch of values from Capistrano
|
122
|
-
def create_body(capistrano)
|
123
|
-
<<-EOL
|
124
|
-
#{summary}
|
125
|
-
|
126
|
-
Comment: #{capistrano[:comment] || "[none given]"}
|
127
|
-
|
128
|
-
Nerd details
|
129
|
-
============
|
130
|
-
Release: #{capistrano[:current_release]}
|
131
|
-
Release Time: #{humanize_release_time(capistrano[:current_release])}
|
132
|
-
Release Revision: #{capistrano[:current_revision]}
|
133
|
-
|
134
|
-
Previous Release: #{capistrano[:previous_release]}
|
135
|
-
Previous Release Time: #{humanize_release_time(capistrano[:previous_release])}
|
136
|
-
Previous Release Revision: #{capistrano[:previous_revision]}
|
137
|
-
|
138
|
-
Repository: #{capistrano[:repository]}
|
139
|
-
Deploy path: #{capistrano[:deploy_to]}
|
140
|
-
EOL
|
53
|
+
from presenter.from
|
54
|
+
recipients presenter.recipients
|
55
|
+
subject presenter.subject
|
56
|
+
body presenter.body
|
141
57
|
end
|
142
58
|
end
|
143
|
-
|
59
|
+
|
144
60
|
end
|
145
61
|
|
146
62
|
if Object.const_defined?("Capistrano")
|
@@ -149,8 +65,8 @@ if Object.const_defined?("Capistrano")
|
|
149
65
|
|
150
66
|
namespace :cap_gun do
|
151
67
|
desc "Send notification of the current release and the previous release via email."
|
152
|
-
task :email do
|
153
|
-
CapGun::
|
68
|
+
task :email, :roles => :app do
|
69
|
+
CapGun::Mailer.load_mailer_config(self)
|
154
70
|
CapGun::Mailer.deliver_deployment_notification(self)
|
155
71
|
end
|
156
72
|
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'etc'
|
2
|
+
|
3
|
+
module CapGun
|
4
|
+
class Presenter
|
5
|
+
DEFAULT_SENDER = %("CapGun" <cap_gun@example.com>)
|
6
|
+
DEFAULT_EMAIL_PREFIX = "[DEPLOY]"
|
7
|
+
|
8
|
+
attr_accessor :capistrano
|
9
|
+
|
10
|
+
def initialize(capistrano)
|
11
|
+
self.capistrano = capistrano
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def recipients
|
16
|
+
capistrano[:cap_gun_email_envelope][:recipients]
|
17
|
+
end
|
18
|
+
|
19
|
+
def email_prefix
|
20
|
+
capistrano[:cap_gun_email_envelope][:email_prefix] || DEFAULT_EMAIL_PREFIX
|
21
|
+
end
|
22
|
+
|
23
|
+
def from
|
24
|
+
capistrano[:cap_gun_email_envelope][:from] || DEFAULT_SENDER
|
25
|
+
end
|
26
|
+
|
27
|
+
def current_user
|
28
|
+
Etc.getlogin
|
29
|
+
end
|
30
|
+
|
31
|
+
def summary
|
32
|
+
%[#{capistrano[:application]} was #{deployed_to} by #{current_user} at #{release_time}.]
|
33
|
+
end
|
34
|
+
|
35
|
+
def deployed_to
|
36
|
+
return "deployed to #{capistrano[:rails_env]}" if capistrano[:rails_env]
|
37
|
+
"deployed"
|
38
|
+
end
|
39
|
+
|
40
|
+
def branch
|
41
|
+
"Branch: #{capistrano[:branch]}" unless capistrano[:branch].nil? || capistrano[:branch].empty?
|
42
|
+
end
|
43
|
+
|
44
|
+
def git_details
|
45
|
+
return unless capistrano[:scm].to_sym == :git
|
46
|
+
<<-EOL
|
47
|
+
#{branch}
|
48
|
+
#{git_log}
|
49
|
+
EOL
|
50
|
+
rescue
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
|
54
|
+
def git_log
|
55
|
+
"\nCommits since last release\n====================\n#{git_log_messages}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def git_log_messages
|
59
|
+
messages = `git log #{capistrano[:previous_revision]}..#{capistrano[:current_revision]} --pretty=format:%h:%s`
|
60
|
+
exit_code.success? ? messages : "N/A"
|
61
|
+
end
|
62
|
+
|
63
|
+
def exit_code
|
64
|
+
$?
|
65
|
+
end
|
66
|
+
|
67
|
+
# Gives you a prettier date/time for output from the standard Capistrano timestamped release directory.
|
68
|
+
# This assumes Capistrano uses UTC for its date/timestamped directories, and converts to the local
|
69
|
+
# machine timezone.
|
70
|
+
def humanize_release_time(path)
|
71
|
+
return unless path
|
72
|
+
match = path.match(/(\d+)$/)
|
73
|
+
return unless match
|
74
|
+
local = convert_from_utc(match[1])
|
75
|
+
local.strftime("%B #{local.day.ordinalize}, %Y %l:%M %p #{local_timezone}").gsub(/\s+/, ' ').strip
|
76
|
+
end
|
77
|
+
|
78
|
+
# Use some DateTime magicrey to convert UTC to the current time zone
|
79
|
+
# When the whole world is on Rails 2.1 (and therefore new ActiveSupport) we can use the magic timezone support there.
|
80
|
+
def convert_from_utc(timestamp)
|
81
|
+
# we know Capistrano release timestamps are UTC, but Ruby doesn't, so make it explicit
|
82
|
+
utc_time = timestamp << "UTC"
|
83
|
+
datetime = DateTime.parse(utc_time)
|
84
|
+
datetime.new_offset(local_datetime_zone_offset)
|
85
|
+
end
|
86
|
+
|
87
|
+
def local_datetime_zone_offset
|
88
|
+
@local_datetime_zone_offset ||= DateTime.now.offset
|
89
|
+
end
|
90
|
+
|
91
|
+
def local_timezone
|
92
|
+
@current_timezone ||= Time.now.zone
|
93
|
+
end
|
94
|
+
|
95
|
+
def release_time
|
96
|
+
humanize_release_time(capistrano[:current_release])
|
97
|
+
end
|
98
|
+
|
99
|
+
def previous_release_time
|
100
|
+
humanize_release_time(capistrano[:previous_release])
|
101
|
+
end
|
102
|
+
|
103
|
+
def subject
|
104
|
+
"#{email_prefix} #{capistrano[:application]} #{deployed_to}"
|
105
|
+
end
|
106
|
+
|
107
|
+
def comment
|
108
|
+
"Comment: #{capistrano[:comment]}.\n" if capistrano[:comment]
|
109
|
+
end
|
110
|
+
|
111
|
+
def body
|
112
|
+
<<-EOL
|
113
|
+
#{summary}
|
114
|
+
#{comment}
|
115
|
+
Deployment details
|
116
|
+
==================
|
117
|
+
Release: #{capistrano[:current_release]}
|
118
|
+
Release Time: #{release_time}
|
119
|
+
Release Revision: #{capistrano[:current_revision]}
|
120
|
+
|
121
|
+
Previous Release: #{capistrano[:previous_release]}
|
122
|
+
Previous Release Time: #{previous_release_time}
|
123
|
+
Previous Release Revision: #{capistrano[:previous_revision]}
|
124
|
+
|
125
|
+
Repository: #{capistrano[:repository]}
|
126
|
+
Deploy path: #{capistrano[:deploy_to]}
|
127
|
+
Domain: #{capistrano[:domain]}
|
128
|
+
#{git_details}
|
129
|
+
EOL
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
data/version.yml
ADDED
metadata
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cap_gun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Rob Sanheim
|
7
|
+
- Rob Sanheim
|
8
|
+
- Muness Alrubaie
|
9
|
+
- Relevance
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
13
|
|
12
|
-
date:
|
14
|
+
date: 2009-06-21 00:00:00 -04:00
|
13
15
|
default_executable:
|
14
16
|
dependencies:
|
15
17
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
18
|
+
name: spicycode-micronaut
|
17
19
|
type: :development
|
18
20
|
version_requirement:
|
19
21
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -22,44 +24,55 @@ dependencies:
|
|
22
24
|
- !ruby/object:Gem::Version
|
23
25
|
version: "0"
|
24
26
|
version:
|
25
|
-
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mocha
|
29
|
+
type: :development
|
30
|
+
version_requirement:
|
31
|
+
version_requirements: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
version:
|
37
|
+
description: Super simple capistrano deployment notifications.
|
26
38
|
email: opensource@thinkrelevance.com
|
27
39
|
executables: []
|
28
40
|
|
29
41
|
extensions: []
|
30
42
|
|
31
43
|
extra_rdoc_files:
|
44
|
+
- README.markdown
|
45
|
+
files:
|
46
|
+
- .autotest
|
47
|
+
- .gitignore
|
32
48
|
- CHANGELOG
|
33
|
-
- lib/cap_gun.rb
|
34
49
|
- MIT-LICENSE
|
35
|
-
- README.
|
36
|
-
|
50
|
+
- README.markdown
|
51
|
+
- Rakefile
|
52
|
+
- VERSION
|
37
53
|
- cap_gun.gemspec
|
38
|
-
-
|
54
|
+
- examples/cap_gun_example.rb
|
55
|
+
- examples/example_helper.rb
|
56
|
+
- examples/presenter_example.rb
|
39
57
|
- init.rb
|
40
58
|
- install.rb
|
41
59
|
- lib/cap_gun.rb
|
60
|
+
- lib/cap_gun/presenter.rb
|
42
61
|
- manifest.txt
|
43
|
-
- MIT-LICENSE
|
44
|
-
- Rakefile
|
45
|
-
- README.rdoc
|
46
|
-
- spec/cap_gun_spec.rb
|
47
62
|
- tasks/cap_bot_tasks.rake
|
63
|
+
- vendor/action_mailer_tls/README
|
48
64
|
- vendor/action_mailer_tls/init.rb
|
49
65
|
- vendor/action_mailer_tls/lib/smtp_tls.rb
|
50
|
-
- vendor/action_mailer_tls/README
|
51
66
|
- vendor/action_mailer_tls/sample/mailer.yml.sample
|
52
67
|
- vendor/action_mailer_tls/sample/smtp_gmail.rb
|
68
|
+
- version.yml
|
53
69
|
has_rdoc: true
|
54
|
-
homepage: http://
|
70
|
+
homepage: http://github.com/relevance/cap_gun
|
71
|
+
licenses: []
|
72
|
+
|
55
73
|
post_install_message:
|
56
74
|
rdoc_options:
|
57
|
-
- --
|
58
|
-
- --inline-source
|
59
|
-
- --title
|
60
|
-
- Cap_gun
|
61
|
-
- --main
|
62
|
-
- README.rdoc
|
75
|
+
- --charset=UTF-8
|
63
76
|
require_paths:
|
64
77
|
- lib
|
65
78
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -72,14 +85,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
85
|
requirements:
|
73
86
|
- - ">="
|
74
87
|
- !ruby/object:Gem::Version
|
75
|
-
version: "
|
88
|
+
version: "0"
|
76
89
|
version:
|
77
90
|
requirements: []
|
78
91
|
|
79
92
|
rubyforge_project: thinkrelevance
|
80
|
-
rubygems_version: 1.3.
|
93
|
+
rubygems_version: 1.3.5
|
81
94
|
signing_key:
|
82
|
-
specification_version:
|
83
|
-
summary: Bang! You're deployed
|
95
|
+
specification_version: 3
|
96
|
+
summary: Bang! You're deployed.
|
84
97
|
test_files:
|
85
|
-
-
|
98
|
+
- examples/cap_gun_example.rb
|
99
|
+
- examples/example_helper.rb
|
100
|
+
- examples/presenter_example.rb
|
data/spec/cap_gun_spec.rb
DELETED
@@ -1,154 +0,0 @@
|
|
1
|
-
ENV["RAILS_ENV"] = "test"
|
2
|
-
require 'rubygems'
|
3
|
-
require 'test/unit'
|
4
|
-
require 'test/spec'
|
5
|
-
require 'mocha'
|
6
|
-
require 'net/smtp'
|
7
|
-
require 'redgreen' unless Object.const_defined?("TextMate")
|
8
|
-
require File.join(File.dirname(__FILE__), *%w[.. lib cap_gun])
|
9
|
-
|
10
|
-
describe "CapGun" do
|
11
|
-
it "uses action mailer hack" do
|
12
|
-
Net::SMTP.new('').respond_to?(:starttls, true).should == true
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "CapGun" do
|
17
|
-
|
18
|
-
describe "mail settings" do
|
19
|
-
include CapGun::Helper
|
20
|
-
|
21
|
-
it "raises if we don't have settings" do
|
22
|
-
capistrano = stub_everything
|
23
|
-
lambda { CapGun::Helper.load_mailer_config(capistrano) }.should.raise(ArgumentError).message.should == "You must define ActionMailer settings in 'cap_gun_action_mailer_config'"
|
24
|
-
end
|
25
|
-
|
26
|
-
it "gets action mailer config from capistrano" do
|
27
|
-
capistrano = stub(:cap_gun_action_mailer_config => {:account => "foo@gmail.com", :password => "password"}, :exists? => true)
|
28
|
-
capistrano.stubs(:[]).returns({:recipients => 'foo'})
|
29
|
-
CapGun::Helper.load_mailer_config(capistrano)
|
30
|
-
ActionMailer::Base.smtp_settings.should == {:account => "foo@gmail.com", :password => "password"}
|
31
|
-
end
|
32
|
-
|
33
|
-
it "raises if we have no cap gun email envelope" do
|
34
|
-
capistrano = stub_everything(:cap_gun_action_mailer_config => {}, :exists? => false)
|
35
|
-
lambda { CapGun::Helper.load_mailer_config capistrano }.should.raise(ArgumentError)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "raises if we don't have at least one recipient" do
|
39
|
-
capistrano = stub_everything(:cap_gun_action_mailer_config => {}, :cap_gun_email_envelope => {})
|
40
|
-
lambda { CapGun::Helper.load_mailer_config capistrano }.should.raise(ArgumentError)
|
41
|
-
capistrano = stub_everything(:cap_gun_action_mailer_config => {}, :cap_gun_email_envelope => {:recipients => []})
|
42
|
-
lambda { CapGun::Helper.load_mailer_config capistrano }.should.raise(ArgumentError)
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "misc helpers" do
|
48
|
-
include CapGun::Helper
|
49
|
-
|
50
|
-
it "returns nil for current user if platform is win32" do
|
51
|
-
expects(:platform).returns("mswin")
|
52
|
-
current_user.should.be nil
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should get current user from *nix id command" do
|
56
|
-
expects(:"`").with('id -un').returns("joe")
|
57
|
-
current_user
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "handling release time" do
|
63
|
-
include CapGun::Helper
|
64
|
-
|
65
|
-
before do # make DateTime act as if local timezone is EDT
|
66
|
-
stubs(:local_timezone).returns("EDT")
|
67
|
-
stubs(:local_datetime_zone_offset).returns(Rational(-1,6))
|
68
|
-
end
|
69
|
-
|
70
|
-
it "returns nil for weird release path" do
|
71
|
-
humanize_release_time("/data/foo/my_release").should == nil
|
72
|
-
end
|
73
|
-
|
74
|
-
it "parse datetime from release path" do
|
75
|
-
humanize_release_time("/data/foo/releases/20080227120000").should == "February 27th, 2008 8:00 AM EDT"
|
76
|
-
end
|
77
|
-
|
78
|
-
it "converts time from release into localtime" do
|
79
|
-
humanize_release_time("/data/foo/releases/20080410040000").should == "April 10th, 2008 12:00 AM EDT"
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "Mailer" do
|
85
|
-
|
86
|
-
it "passes capistrano into create body" do
|
87
|
-
capistrano = { :current_release => "/data/foo", :previous_release => "/data/foo", :cap_gun_email_envelope => {:recipients => ["joe@example.com"]} }
|
88
|
-
CapGun::Mailer.any_instance.expects(:create_body).with(capistrano).returns("foo")
|
89
|
-
CapGun::Mailer.create_deployment_notification capistrano
|
90
|
-
end
|
91
|
-
|
92
|
-
it "calls Net::SMTP to send the mail correctly (we test this because SMTP internals changed between 1.8.6 and newer versions of Ruby)" do
|
93
|
-
ActionMailer::Base.smtp_settings = {
|
94
|
-
:address => "smtp.gmail.com",
|
95
|
-
:port => 587,
|
96
|
-
:domain => "foo.com",
|
97
|
-
:authentication => :plain,
|
98
|
-
:user_name => "username",
|
99
|
-
:password => "password"
|
100
|
-
}
|
101
|
-
|
102
|
-
capistrano = { :current_release => "/data/foo", :previous_release => "/data/foo", :cap_gun_email_envelope => {:recipients => ["joe@example.com"]} }
|
103
|
-
Net::SMTP.expects(:start)
|
104
|
-
CapGun::Mailer.deliver_deployment_notification capistrano
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "Mail envelope" do
|
109
|
-
before { CapGun::Mailer.any_instance.stubs(:create_body).returns("email body!") }
|
110
|
-
|
111
|
-
it "gets recipients from email envelope" do
|
112
|
-
capistrano = { :cap_gun_email_envelope => { :recipients => ["foo@here.com", "bar@here.com"] } }
|
113
|
-
mail = CapGun::Mailer.create_deployment_notification capistrano
|
114
|
-
mail.to.should == ["foo@here.com", "bar@here.com"]
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should have a default sender" do
|
118
|
-
capistrano = { :cap_gun_email_envelope => { :recipients => "foo@here.com" } }
|
119
|
-
mail = CapGun::Mailer.create_deployment_notification capistrano
|
120
|
-
mail.from.should == ["cap_gun@example.com"]
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should override sender from email envelope" do
|
124
|
-
capistrano = { :cap_gun_email_envelope => { :from => "booyakka!@example.com", :recipients => ["foo@here.com", "bar@here.com"] } }
|
125
|
-
mail = CapGun::Mailer.create_deployment_notification capistrano
|
126
|
-
mail.from.should == ["booyakka!@example.com"]
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
describe "creating body" do
|
131
|
-
before do # make DateTime act as if local timezone is EDT
|
132
|
-
CapGun::Mailer.any_instance.stubs(:local_timezone).returns("EDT")
|
133
|
-
CapGun::Mailer.any_instance.stubs(:local_datetime_zone_offset).returns(Rational(-1,6))
|
134
|
-
end
|
135
|
-
|
136
|
-
it "has a friendly summary line" do
|
137
|
-
CapGun::Mailer.any_instance.stubs(:current_user).returns("jdoe")
|
138
|
-
capistrano = { :application => "my app", :rails_env => "staging", :current_release => "/data/foo/releases/20080227120000", :cap_gun_email_envelope => {} }
|
139
|
-
mail = CapGun::Mailer.create_deployment_notification capistrano
|
140
|
-
mail.subject.should == "[DEPLOY] my app deployed to staging"
|
141
|
-
mail.body.split("\n").first.should == "my app was deployed to staging by jdoe at February 27th, 2008 8:00 AM EDT."
|
142
|
-
end
|
143
|
-
|
144
|
-
it "does not include rails env if not defined" do
|
145
|
-
CapGun::Mailer.any_instance.stubs(:current_user).returns("jdoe")
|
146
|
-
capistrano = { :application => "my app", :current_release => "/data/foo/releases/20080227120000", :cap_gun_email_envelope => {}}
|
147
|
-
mail = CapGun::Mailer.create_deployment_notification capistrano
|
148
|
-
mail.subject.should == "[DEPLOY] my app deployed"
|
149
|
-
mail.body.split("\n").first.should == "my app was deployed by jdoe at February 27th, 2008 8:00 AM EDT."
|
150
|
-
end
|
151
|
-
|
152
|
-
end
|
153
|
-
|
154
|
-
end
|