bender-bot 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/bender/main.rb +39 -23
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9ea8e6ba9c6e95cc880b44560383e48bb087794
4
- data.tar.gz: cf43d17d8d76d4b17600a7dae9dcacaf36d153dc
3
+ metadata.gz: d2171e9575b5e902190f80671fc54d50d3a29807
4
+ data.tar.gz: fe7a496b89279728545e4fe032f2c964c9e5b45c
5
5
  SHA512:
6
- metadata.gz: 09448e7da47703411a5788e41afcbe912d33d19a488cfeec35da590bcc7f77f848fd2ca83a0db77b6cbad300ed54a30dc0cdfd845d4a9999e0d19fb2462e0544
7
- data.tar.gz: b4dcdb8c73e62faad053ea18ba272d29088a9f1e8b705e378b97b7abe9f9524e430656416e185f8c5327b8aaf311f1b031e422e032001d3f0839fb3d54da2a32
6
+ metadata.gz: 601fed44461ff0050a959c50d246a8acbcde081d3b2d0d8040df01d8a359785f13e5d15a337288280aa40614d87bcfd5a70d026575469aa8d988565e0e8957ea
7
+ data.tar.gz: 41985123cd22f41401a556c3ce56bcaabc21b6252c22ff9f624c1699668ef2499b7c0930d2860834f0066b6866da9eb7c382f65f7ee90072ebdb3e6b02be882e
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.5.3
@@ -1,5 +1,6 @@
1
1
  require 'logger'
2
2
  require 'net/http'
3
+ require 'json'
3
4
 
4
5
  require 'tilt/erb'
5
6
  require 'queryparams'
@@ -141,13 +142,20 @@ module Bender
141
142
  aliases: %w[ -O ],
142
143
  desc: 'Reverse order of HipChat API loading (hack)',
143
144
  default: false
145
+ option :room_base_name, \
146
+ type: :string,
147
+ aliases: %w[ -N ],
148
+ desc: 'Base name for the primary room',
149
+ default: 'Production Indicent'
144
150
  include_common_options
145
151
  def start
146
152
  bot = start_bot
147
- periodically_refresh_group bot
148
- periodically_refresh_users bot
149
- periodically_refresh_incidents bot
150
- serve_web bot
153
+ ts = []
154
+ ts << periodically_refresh_group(bot)
155
+ ts << periodically_refresh_users(bot)
156
+ ts << periodically_refresh_incidents(bot)
157
+ # serve_web bot
158
+ ts.map(&:join)
151
159
  end
152
160
 
153
161
 
@@ -200,13 +208,9 @@ module Bender
200
208
 
201
209
  if open_incidents.empty?
202
210
  if @open.nil? || @open > 0
203
- new_room['name'] = '[NONE] Production Incident'
211
+ new_room['name'] = '[NONE] %s' % options.room_base_name
204
212
  new_room['topic'] = 'Good news everyone! No high-severity incidents at the moment'
205
- begin
206
- room.update_room(new_room)
207
- rescue NoMethodError
208
- log.warn 'NoMethodError in set_room_name_and_topic'
209
- end
213
+ apply_room_name_and_topic new_room
210
214
  end
211
215
 
212
216
  @open = 0
@@ -218,14 +222,10 @@ module Bender
218
222
  end
219
223
 
220
224
  unless @open == open_incidents.size
221
- new_room['name'] = '[IN PROGRESS] Production Incident'
225
+ new_room['name'] = '[IN PROGRESS] %s' % options.room_base_name
222
226
  tha_news = open_incidents.size == 1 ? "There's a high-severity incident" : "There are #{open_incidents.size} high-severity incidents"
223
227
  new_room['topic'] = "Terrible news everyone! #{tha_news}"
224
- begin
225
- room.update_room(new_room)
226
- rescue NoMethodError
227
- log.warn 'NoMethodError in set_room_name_and_topic'
228
- end
228
+ apply_room_name_and_topic new_room
229
229
  end
230
230
 
231
231
  @open = open_incidents.size
@@ -236,6 +236,27 @@ module Bender
236
236
  end
237
237
 
238
238
 
239
+ def apply_room_name_and_topic room
240
+ uri = URI room['links']['self']
241
+
242
+ resp = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
243
+ req = Net::HTTP::Put.new uri
244
+ req['Content-Type'] = 'application/json'
245
+ req['Authorization'] = 'Bearer %s' % options.hipchat_v2_token
246
+ req.body = {
247
+ name: room['name'],
248
+ topic: room['topic'],
249
+ privacy: room['privacy'],
250
+ is_archived: room['is_archived'],
251
+ is_guest_accessible: room['is_guest_accessible'],
252
+ owner: { id: room['owner']['id'] }
253
+ }.to_json
254
+
255
+ http.request req
256
+ end
257
+ end
258
+
259
+
239
260
  def periodically_refresh_incidents bot
240
261
  Thread.new do
241
262
  if options.order
@@ -254,13 +275,8 @@ module Bender
254
275
 
255
276
  loop do
256
277
  is = refresh_incidents bot
257
- begin
258
- set_room_name_and_topic room_id, is, hipchat_v2, bot
259
- sleep options.issue_refresh
260
- rescue HipChat::UnknownResponseCode
261
- log.warn 'HipChat::UnknownResponseCode in set_room_name_and_topic'
262
- sleep 2
263
- end
278
+ set_room_name_and_topic room_id, is, hipchat_v2, bot
279
+ sleep options.issue_refresh
264
280
  end
265
281
  end
266
282
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bender-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Clemmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-12 00:00:00.000000000 Z
11
+ date: 2015-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor