middleman-deploy-with-notifications 0.0.31 → 0.0.32

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3e1ecf7ec07a01399eb4563426e637ec7afe669
4
- data.tar.gz: 9638f7e4e69a433fe250208397a83c352b03406e
3
+ metadata.gz: 2a67629673a43d9cf77a074ddb1e97178d46f6ce
4
+ data.tar.gz: 78446ebb30f62a65a39e069c1ef73e4b550f421a
5
5
  SHA512:
6
- metadata.gz: 4b624214ae6beddfe061439704454af0f4dfb628e100712954906cbb74455961f9c82789b9941009025668e31812f1a11daafc0812690e8abeec1c52f3e4af49
7
- data.tar.gz: 239a6bcffa54ded3ecb78db45ac517d7007faf3b160af3b27829f79b46688d3f91eca5aeb84022dbf15dd4f8c76d09e2e2a36bd259e27961261aad59b75c46ae
6
+ metadata.gz: def2690f227fb81d4661ac0f2b23641d4bfed892d386ae570934d584822773b55174afb56f51361c5a5dedf22c4d02254541447883e2e0d3d395a94b64bccf4b
7
+ data.tar.gz: 4ebe364acf2017b7dabdaba68ded7f941a0e11ece0d814f5ba5dc64afac08762af520e517660a749d93ca801d992fb0d98c95113ae066fe5129c6ea090cab903
@@ -2,10 +2,7 @@ require "middleman-core/cli"
2
2
 
3
3
  require "middleman-deploy-with-notifications/extension"
4
4
  require "middleman-deploy-with-notifications/pkg-info"
5
-
6
- # for hipchat notifications
7
- require "net/http"
8
- require "uri"
5
+ require "middleman-deploy-with-notifications/notifications"
9
6
 
10
7
  PACKAGE = "#{Middleman::DeployWithNotifications::PACKAGE}"
11
8
  VERSION = "#{Middleman::DeployWithNotifications::VERSION}"
@@ -107,65 +104,14 @@ EOF
107
104
  options
108
105
  end
109
106
 
110
- def notify_airbrake(short_rev, rev, who)
111
- puts "Recording a timestamped deploy in Airbrake: #{short_rev}".green
112
- url = "api_key=#{self.deploy_options.airbrake_api_key}" +
113
- "&deploy[rails_env]=production" +
114
- "&deploy[local_username]=#{who}" +
115
- "&deploy[scm_repository]=git@github.com:140proof/280.140proof.com.git" +
116
- "&deploy[scm_revision]=#{short_rev}"
117
- `curl -d "#{url}" http://airbrake.io/deploys &> /dev/null`
118
- end
119
-
120
- def send_hc_mesg(mesg, fmt = "text")
121
- uri = uri || URI.parse( "http://api.hipchat.com/v1/rooms/message" )
122
- self.deploy_options.hipchat_rooms.each do |room|
123
- Net::HTTP.post_form( uri, {
124
- "format" => "json",
125
- "color" => "random",
126
- "auth_token" => self.deploy_options.hipchat_token,
127
- "room_id" => room,
128
- "from" => "280 Deploy",
129
- "message" => mesg,
130
- "message_format" => fmt || "text"}
131
- )
132
- end
133
- end
134
-
135
- def hipchat_start(who, github_project)
136
- send_hc_mesg( "Yo yo! @#{who} is deploying #{github_project}:" )
137
- end
138
-
139
- def hipchat_complete(who, github_project, github_user, rev, comment)
140
- puts "Notifying hipchat room(s)".yellow
141
-
142
- message = "<a href='http://github.com/#{github_user}/#{github_project}/commit/#{rev}'>#{rev}</a> (#{comment}) is now live on <b><a href='http://#{github_project}'>production</a></b>."
143
- send_hc_mesg(message, "html")
144
- end
145
-
146
- remove_task :send_hc_mesg, :hipchat_start, :hipchat_complete
147
-
148
107
  def deploy_rsync
149
108
  host = self.deploy_options.host
150
109
  port = self.deploy_options.port
151
110
  user = self.deploy_options.user
152
111
  path = self.deploy_options.path
153
112
 
154
- airbrake_api_key = self.deploy_options.airbrake_api_key
155
- hipchat_rooms = self.deploy_options.hipchat_rooms
156
- hipchat_token = self.deploy_options.hipchat_token
157
-
158
- github_user, github_project = `git remote -v | grep "/" | head -n1`.gsub( /.*:([\w_-]+)\/([\w_\.-]+).git.*/, '\1/\2' ).split( "/" )
159
- github_project.chomp!
160
-
161
- rev = `git rev-parse HEAD`.gsub( /\s*$/, '' ).chomp
162
- short_rev = `git rev-parse --short HEAD`.gsub( /\s*$/, '' ).chomp
163
- branch = `git rev-parse --abbrev-ref HEAD`.gsub( /\s*/, '' ).chomp
164
- comment = `git log -1 --pretty=%B`.gsub( /\s*$/, '' ).chomp
165
- who = `git config --get github.user`.chomp
166
-
167
- notify_airbrake(short_rev, rev, who) if self.deploy_options.airbrake_api_key
168
- hipchat_start(who, github_project) if self.deploy_options.hipchat_token
113
+ notify_airbrake if self.deploy_options.airbrake_api_key
114
+ notify_hipchat_start if self.deploy_options.hipchat_token
169
115
 
170
116
  puts "Deploying via rsync to #{user}@#{host}".red
171
117
 
@@ -183,8 +129,7 @@ EOF
183
129
 
184
130
  run command
185
131
 
186
- hipchat_complete(who, github_project, github_user, rev, comment)
187
-
132
+ notify_hipchat_complete if self.deploy_options.hipchat_token
188
133
  end
189
134
 
190
135
  def deploy_git
@@ -193,6 +138,9 @@ EOF
193
138
 
194
139
  puts "## Deploying via git to remote=\"#{remote}\" and branch=\"#{branch}\""
195
140
 
141
+ notify_airbrake if self.deploy_options.airbrake_api_key
142
+ notify_hipchat_start if self.deploy_options.hipchat_token
143
+
196
144
  #check if remote is not a git url
197
145
  unless remote =~ /\.git$/
198
146
  remote = `git config --get remote.#{remote}.url`.chop
@@ -227,6 +175,7 @@ EOF
227
175
  `git commit --allow-empty -am 'Automated commit at #{Time.now.utc} by #{PACKAGE} #{VERSION}'`
228
176
  `git push -f origin #{branch}`
229
177
  end
178
+ notify_hipchat_complete if self.deploy_options.hipchat_token
230
179
  end
231
180
 
232
181
  def deploy_ftp
@@ -240,6 +189,9 @@ EOF
240
189
 
241
190
  puts "## Deploying via ftp to #{user}@#{host}:#{path}"
242
191
 
192
+ notify_airbrake if self.deploy_options.airbrake_api_key
193
+ notify_hipchat_start if self.deploy_options.hipchat_token
194
+
243
195
  ftp = Net::FTP.new(host)
244
196
  ftp.login(user, pass)
245
197
  ftp.chdir(path)
@@ -277,6 +229,7 @@ EOF
277
229
  end
278
230
  end
279
231
  ftp.close
232
+ notify_hipchat_complete if self.deploy_options.hipchat_token
280
233
  end
281
234
 
282
235
  end
@@ -5,7 +5,7 @@ require "middleman-core"
5
5
  module Middleman
6
6
  module DeployWithNotifications
7
7
 
8
- class Options < Struct.new(:whatisthis, :method, :host, :port, :user, :password, :path, :clean, :remote, :branch, :after_build, :airbrake_api_key, :hipchat_rooms, :hipchat_token); end
8
+ class Options < Struct.new(:whatisthis, :method, :host, :port, :user, :password, :path, :clean, :remote, :branch, :after_build, :airbrake_api_key, :hipchat_rooms, :hipchat_token, :revision, :revision_short, :deploy_user, :github_project, :github_user, :git_branch, :git_comment); end
9
9
 
10
10
  class << self
11
11
 
@@ -24,6 +24,15 @@ module Middleman
24
24
 
25
25
  options.after_build ||= false
26
26
 
27
+ options.revision = `git rev-parse HEAD`.gsub( /\s*$/, '' ).chomp
28
+ options.revision_short = `git rev-parse --short HEAD`.gsub( /\s*$/, '' ).chomp
29
+ options.deploy_user = `git config --get github.user`.chomp
30
+ options.github_user, options.github_project = `git remote -v | grep "/" | head -n1`.gsub( /.*:([\w_-]+)\/([\w_\.-]+).git.*/, '\1/\2' ).split( "/" )
31
+ options.github_project.chomp!
32
+
33
+ options.git_branch = `git rev-parse --abbrev-ref HEAD`.gsub( /\s*/, '' ).chomp
34
+ options.git_comment = `git log -1 --pretty=%B`.gsub( /\s*$/, '' ).chomp
35
+
27
36
  app.after_build do |builder|
28
37
  ::Middleman::Cli::DeployWithNotifications.new.deploy if options.after_build
29
38
  end
@@ -0,0 +1,69 @@
1
+ module Middleman
2
+ module Cli
3
+
4
+ class DeployWithNotifications < Thor
5
+
6
+ namespace :deploy
7
+
8
+ protected
9
+
10
+ desc "notify_airbrake", ""
11
+ def notify_airbrake
12
+ puts "Recording a timestamped deploy in Airbrake: #{self.deploy_options.revision_short}".green
13
+ url = "api_key=#{self.deploy_options.airbrake_api_key}" +
14
+ "&deploy[rails_env]=production" +
15
+ "&deploy[local_username]=#{self.deploy_options.deploy_user}" +
16
+ "&deploy[scm_repository]=git@github.com:140proof/280.140proof.com.git" +
17
+ "&deploy[scm_revision]=#{self.deploy_options.revision_short}"
18
+ `curl -d "#{url}" http://airbrake.io/deploys &> /dev/null`
19
+ end
20
+
21
+ desc "hipchat_start", ""
22
+ def notify_hipchat_start
23
+ send_hc_mesg( "#{exclaim} @#{self.deploy_options.deploy_user} is deploying #{self.deploy_options.github_project}:" )
24
+ end
25
+ remove_task :notify_hipchat_start
26
+
27
+ desc "hipchat_complete", ""
28
+ def notify_hipchat_complete
29
+ puts "Notifying hipchat room(s)".yellow
30
+
31
+ message = "<a href='http://github.com/#{self.deploy_options.github_user}/#{self.deploy_options.github_project}/commit/#{self.deploy_options.revision}'>#{self.deploy_options.revision}</a> " +
32
+ "(#{self.deploy_options.git_comment}) is now live on <b><a href='http://#{self.deploy_options.github_project}'>production</a></b>."
33
+ send_hc_mesg(message, "html")
34
+ end
35
+ remove_task :notify_hipchat_complete
36
+
37
+ def exclaim
38
+ phrases = [
39
+ "Holy cannoli",
40
+ "Holy guacamole",
41
+ "Holy hot chocolate",
42
+ "Holy ravioli",
43
+ "Hot buttery biscuits",
44
+ ]
45
+ return phrases[rand(phrases.size)] + "!"
46
+ end
47
+ remove_task :exclaim
48
+
49
+ def send_hc_mesg(mesg, fmt = "text")
50
+ uri = uri || URI.parse( "http://api.hipchat.com/v1/rooms/message" )
51
+ puts mesg
52
+ self.deploy_options.hipchat_rooms.each do |room|
53
+ Net::HTTP.post_form( uri, {
54
+ "auth_token" => self.deploy_options.hipchat_token,
55
+ "color" => "random",
56
+ "format" => "json",
57
+ "from" => "280 Deploy",
58
+ "message" => mesg,
59
+ "message_format" => fmt || "text",
60
+ "room_id" => room,
61
+ })
62
+ end
63
+ end
64
+ remove_task :send_hc_mesg
65
+
66
+ end
67
+
68
+ end
69
+ end
@@ -1,6 +1,6 @@
1
1
  module Middleman
2
2
  module DeployWithNotifications
3
3
  PACKAGE = "middleman-deploy-with-notifications"
4
- VERSION = "0.0.31"
4
+ VERSION = "0.0.32"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-deploy-with-notifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.31
4
+ version: 0.0.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Vaughan
@@ -100,6 +100,7 @@ files:
100
100
  - lib/middleman-deploy-with-notifications.rb
101
101
  - lib/middleman-deploy-with-notifications/commands.rb
102
102
  - lib/middleman-deploy-with-notifications/extension.rb
103
+ - lib/middleman-deploy-with-notifications/notifications.rb
103
104
  - lib/middleman-deploy-with-notifications/pkg-info.rb
104
105
  - lib/middleman_extension.rb
105
106
  - middleman-deploy-with-notifications.gemspec