bender-bot 0.3.0 → 0.4.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 +4 -4
- data/VERSION +1 -1
- data/lib/bender/bot.rb +38 -20
- data/lib/bender/main.rb +69 -16
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39a23282811b3e535eed1c40660ab4d3038c2759
|
4
|
+
data.tar.gz: 1c4d67b9740cfde6671ea41697cc17e745ca50c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d9e6af21a110702f2f33ab2c872562657569e152042e5bc4d9fc88b0d5eda00bead8ddc636f0af6be23f3001909ab593b4437eb4e069800b7a3fd1acece899e
|
7
|
+
data.tar.gz: 733651b2f64a53e739ae94bb9a4623dbc420ded8f92350b8564a118c27bb8e12f6dc32bfc6bafb71ad6f3fe1617c0b42b1462b41833e06baac385443a0c1645f
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/bender/bot.rb
CHANGED
@@ -221,38 +221,50 @@ class BenderBot
|
|
221
221
|
|
222
222
|
# /inc resolve NUM - Resolve an incident
|
223
223
|
when /^\s*\/inc\s+resolve\s+(\d+)\s*$/
|
224
|
-
|
225
|
-
|
226
|
-
reply_html *resolve_incident(incident)
|
224
|
+
unless allowed?
|
225
|
+
reply_html "You're not allowed to do that!", :red
|
227
226
|
else
|
228
|
-
|
227
|
+
incident = select_incident $1
|
228
|
+
if incident
|
229
|
+
reply_html *resolve_incident(incident)
|
230
|
+
else
|
231
|
+
reply_html 'Sorry, no such incident!', :red
|
232
|
+
end
|
229
233
|
end
|
230
234
|
|
231
235
|
# /inc close NUM - Close an incident
|
232
236
|
when /^\s*\/inc\s+close\s+(\d+)\s*$/
|
233
|
-
|
234
|
-
|
235
|
-
reply_html *close_incident(incident)
|
237
|
+
unless allowed?
|
238
|
+
reply_html "You're not allowed to do that!", :red
|
236
239
|
else
|
237
|
-
|
240
|
+
incident = select_incident $1
|
241
|
+
if incident
|
242
|
+
reply_html *close_incident(incident)
|
243
|
+
else
|
244
|
+
reply_html 'Sorry, no such incident!', :red
|
245
|
+
end
|
238
246
|
end
|
239
247
|
|
240
248
|
# /inc open SEVERITY SUMMARY - File a new incident
|
241
249
|
when /^\s*\/inc\s+open\s+(severity|sev|s|p)?(\d+)\s+(.*?)\s*$/i
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
250
|
+
unless allowed?
|
251
|
+
reply_html "You're not allowed to do that!", :red
|
252
|
+
else
|
253
|
+
user = user_where name: sender
|
254
|
+
data = {
|
255
|
+
fields: {
|
256
|
+
project: { key: options.jira_project },
|
257
|
+
issuetype: { name: options.jira_type },
|
258
|
+
reporter: { name: user[:nick] },
|
259
|
+
summary: $3,
|
260
|
+
SHOW_FIELDS.key('Severity') => {
|
261
|
+
id: SEVERITIES[$2.to_i]
|
262
|
+
}
|
251
263
|
}
|
252
264
|
}
|
253
|
-
}
|
254
265
|
|
255
|
-
|
266
|
+
reply_html *file_incident(data)
|
267
|
+
end
|
256
268
|
|
257
269
|
|
258
270
|
# /inc comment [INCIDENT_NUMBER] [COMMENT_TEXT]
|
@@ -432,4 +444,10 @@ private
|
|
432
444
|
end
|
433
445
|
end
|
434
446
|
|
435
|
-
|
447
|
+
|
448
|
+
def allowed?
|
449
|
+
user = user_where name: @sender
|
450
|
+
store['group'].include? user[:name]
|
451
|
+
end
|
452
|
+
|
453
|
+
end
|
data/lib/bender/main.rb
CHANGED
@@ -111,6 +111,11 @@ module Bender
|
|
111
111
|
aliases: %w[ -J ],
|
112
112
|
desc: 'Set JIRA project',
|
113
113
|
required: true
|
114
|
+
option :jira_group, \
|
115
|
+
type: :string,
|
116
|
+
aliases: %w[ -G ],
|
117
|
+
desc: 'Set JIRA group for write mode',
|
118
|
+
required: true
|
114
119
|
option :jira_type, \
|
115
120
|
type: :string,
|
116
121
|
aliases: %w[ -T ],
|
@@ -126,9 +131,20 @@ module Bender
|
|
126
131
|
aliases: %w[ -S ],
|
127
132
|
desc: 'Set JIRA issue refresh rate',
|
128
133
|
default: 5
|
134
|
+
option :group_refresh, \
|
135
|
+
type: :numeric,
|
136
|
+
aliases: %w[ -T ],
|
137
|
+
desc: 'Set JIRA group refresh rate',
|
138
|
+
default: 60
|
139
|
+
option :order, \
|
140
|
+
type: :boolean,
|
141
|
+
aliases: %w[ -O ],
|
142
|
+
desc: 'Reverse order of HipChat API loading (hack)',
|
143
|
+
default: false
|
129
144
|
include_common_options
|
130
145
|
def start
|
131
146
|
bot = start_bot
|
147
|
+
periodically_refresh_group bot
|
132
148
|
periodically_refresh_users bot
|
133
149
|
periodically_refresh_incidents bot
|
134
150
|
serve_web bot
|
@@ -168,7 +184,7 @@ module Bender
|
|
168
184
|
@room_name ||= bot.store['primary_room_name'] || new_room['name']
|
169
185
|
@room_topic ||= bot.store['primary_room_topic'] || new_room['topic']
|
170
186
|
|
171
|
-
@open =
|
187
|
+
@open = 0 unless defined? @open
|
172
188
|
|
173
189
|
log.info \
|
174
190
|
primary_room_name: bot.store['primary_room_name'],
|
@@ -186,42 +202,52 @@ module Bender
|
|
186
202
|
room.update_room(new_room)
|
187
203
|
end
|
188
204
|
|
189
|
-
@open =
|
205
|
+
@open = 0
|
190
206
|
|
191
207
|
else
|
192
|
-
|
208
|
+
if @open.zero?
|
193
209
|
@room_name = new_room['name']
|
194
210
|
@room_topic = new_room['topic']
|
195
|
-
|
196
|
-
|
211
|
+
end
|
212
|
+
|
213
|
+
unless @open == open_incidents.size
|
197
214
|
new_room['name'] = 'DANGER WILL ROBINSON'
|
198
215
|
new_room['topic'] = '%d open incicents!' % open_incidents.size
|
199
216
|
room.update_room(new_room)
|
200
217
|
end
|
201
218
|
|
202
|
-
@open =
|
219
|
+
@open = open_incidents.size
|
203
220
|
end
|
221
|
+
|
222
|
+
bot.store['primary_room_name'] = @room_name
|
223
|
+
bot.store['primary_room_topic'] = @room_topic
|
204
224
|
end
|
205
225
|
|
206
226
|
|
207
227
|
def periodically_refresh_incidents bot
|
208
228
|
Thread.new do
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
229
|
+
if options.order
|
230
|
+
hipchat_v1 = HipChat::Client.new \
|
231
|
+
options.hipchat_token, api_version: 'v1'
|
232
|
+
hipchat_v2 = HipChat::Client.new \
|
233
|
+
options.hipchat_v2_token, api_version: 'v2'
|
234
|
+
else
|
235
|
+
hipchat_v2 = HipChat::Client.new \
|
236
|
+
options.hipchat_v2_token, api_version: 'v2'
|
237
|
+
hipchat_v1 = HipChat::Client.new \
|
238
|
+
options.hipchat_token, api_version: 'v1'
|
239
|
+
end
|
214
240
|
|
215
241
|
room_id = options.primary_room_id
|
216
242
|
|
217
243
|
loop do
|
218
244
|
is = refresh_incidents bot
|
219
|
-
begin
|
245
|
+
# begin
|
220
246
|
set_room_name_and_topic room_id, is, hipchat_v2, bot
|
221
247
|
sleep options.issue_refresh
|
222
|
-
rescue NoMethodError
|
223
|
-
|
224
|
-
end
|
248
|
+
# rescue NoMethodError
|
249
|
+
# sleep 1
|
250
|
+
# end
|
225
251
|
end
|
226
252
|
end
|
227
253
|
end
|
@@ -245,7 +271,8 @@ module Bender
|
|
245
271
|
Thread.new do
|
246
272
|
loop do
|
247
273
|
resp = http.request req
|
248
|
-
|
274
|
+
data = JSON.parse(resp.body)
|
275
|
+
users = data.inject({}) do |h, user|
|
249
276
|
h[user['key']] = {
|
250
277
|
nick: user['key'],
|
251
278
|
name: user['displayName'],
|
@@ -261,6 +288,32 @@ module Bender
|
|
261
288
|
end
|
262
289
|
|
263
290
|
|
291
|
+
def periodically_refresh_group bot
|
292
|
+
req_path = '/rest/api/2/group'
|
293
|
+
req_params = QueryParams.encode \
|
294
|
+
groupname: options.jira_group,
|
295
|
+
expand: 'users'
|
296
|
+
|
297
|
+
uri = URI(options.jira_site + req_path + '?' + req_params)
|
298
|
+
http = Net::HTTP.new uri.hostname, uri.port
|
299
|
+
|
300
|
+
req = Net::HTTP::Get.new uri
|
301
|
+
req.basic_auth options.jira_user, options.jira_pass
|
302
|
+
req['Content-Type'] = 'application/json'
|
303
|
+
req['Accept'] = 'application/json'
|
304
|
+
|
305
|
+
Thread.new do
|
306
|
+
loop do
|
307
|
+
resp = http.request req
|
308
|
+
data = JSON.parse(resp.body)
|
309
|
+
user_names = data['users']['items'].map { |u| u['displayName'] }
|
310
|
+
bot.store['group'] = user_names
|
311
|
+
sleep options.group_refresh
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
|
264
317
|
def serve_web bot
|
265
318
|
Web.set :environment, options.environment
|
266
319
|
Web.set :port, options.port
|