public
Rubygem
Description: Bang! You've deployed!
Homepage: http://opensource.thinkrelevance.com/
Clone URL: git://github.com/relevance/cap_gun.git
don't try to display rails env if its not set
rsanheim (author)
Tue May 27 04:41:59 -0700 2008
commit  aebcb4fb709d414ce1aee409507fb97a398967cb
tree    4bebcc8da2d576f888a7976ed6fdb40be2f293aa
parent  06a864c649542640e762d189defc3b6850b78315
...
53
54
55
 
56
57
58
...
86
87
88
 
89
90
 
91
92
93
...
102
103
104
 
105
106
107
108
109
110
 
 
 
 
111
112
113
114
 
115
116
117
...
53
54
55
56
57
58
59
...
87
88
89
90
91
 
92
93
94
95
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
 
121
122
123
124
0
@@ -53,6 +53,7 @@ module CapGun
0
     # This assumes Capistrano uses UTC for its date/timestamped directories, and converts to the local
0
     # machine timezone.
0
     def humanize_release_time(path)
0
+      return unless path
0
       match = path.match(/(\d+)$/)
0
       return unless match
0
       local = convert_from_utc(match[1])
0
@@ -86,8 +87,9 @@ module CapGun
0
       DEFAULT_EMAIL_PREFIX = "[DEPLOY] "
0
       
0
       adv_attr_accessor :email_prefix
0
+      attr_accessor :summary
0
       
0
-      # Grab the options for emaililng from cap_gun_email_envelope (should be set in your deploy file)
0
+      # Grab the options for emailing from cap_gun_email_envelope (should be set in your deploy file)
0
       #
0
       # Valid options:
0
       #     :recipients     (required) an array or string of email address(es) that should get notifications
0
@@ -102,16 +104,21 @@ module CapGun
0
       # Do the actual email
0
       def deployment_notification(capistrano)
0
         init(capistrano[:cap_gun_email_envelope])
0
+        self.summary = create_summary(capistrano)
0
         
0
         content_type "text/plain"
0
         subject "#{email_prefix} #{capistrano[:application]} deployed to #{capistrano[:rails_env]}"
0
         body    create_body(capistrano)
0
       end
0
       
0
+      def create_summary(capistrano)
0
+        %[#{capistrano[:application]} was deployed#{" to " << capistrano[:rails_env] if capistrano[:rails_env]} by #{current_user} at #{humanize_release_time(capistrano[:current_release])}.]
0
+      end
0
+      
0
       # Create the body of the message using a bunch of values from Capistrano
0
       def create_body(capistrano)
0
 <<-EOL
0
-#{capistrano[:application]} was deployed to #{capistrano[:rails_env]} by #{current_user} at #{humanize_release_time(capistrano[:current_release])}.
0
+#{summary}
0
 
0
 Comment: #{capistrano[:comment] || "[none given]"}
0
 
...
110
111
112
113
114
 
 
 
 
 
 
 
 
115
116
 
 
 
 
 
117
118
119
...
110
111
112
 
 
113
114
115
116
117
118
119
120
121
 
122
123
124
125
126
127
128
129
0
@@ -110,10 +110,20 @@ describe "CapGun" do
0
       mail = CapGun::Mailer.create_deployment_notification capistrano
0
       mail.from.should == ["booyakka!@example.com"]
0
     end
0
-    
0
-    xit "has a friendly summary line"
0
+  end
0
+  
0
+  describe "creating body" do
0
+    it "has a friendly summary line" do
0
+      capistrano = { :application => "my app", :rails_env => "staging", :current_release => "/data/foo/releases/20080227120000", :cap_gun_email_envelope => { :from => "booyakka!@example.com", :recipients => ["foo@here.com", "bar@here.com"] } }
0
+      mail = CapGun::Mailer.create_deployment_notification capistrano
0
+      mail.body.split("\n").first.should == "my app was deployed to staging by rsanheim at February 27th, 2008 8:00 AM EDT."
0
+    end
0
 
0
-    xit "does not include rails env in summary if not defined"
0
+    it "does not include rails env in summary if not defined" do
0
+      capistrano = { :application => "my app", :current_release => "/data/foo/releases/20080227120000", :cap_gun_email_envelope => { :from => "booyakka!@example.com", :recipients => ["foo@here.com", "bar@here.com"] } }
0
+      mail = CapGun::Mailer.create_deployment_notification capistrano
0
+      mail.body.split("\n").first.should == "my app was deployed by rsanheim at February 27th, 2008 8:00 AM EDT."
0
+    end
0
     
0
   end
0
   

Comments