bender-bot 0.2.3 → 0.2.4

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/bot.rb +61 -1
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0324ee0a7d5aa68cf88b4fd9a69d1c1a0c5ff90
4
- data.tar.gz: 8b2db209b7493e34498cc567d5a061dbb7490ffd
3
+ metadata.gz: 702cbc0ab493486d62b7c9db41dfc1191a5c9868
4
+ data.tar.gz: 3e6535a990ed42e03aa8d6b93c4a24bd83643791
5
5
  SHA512:
6
- metadata.gz: 99bddc520fc9d3e535b21b9f897cddf9233192f0a505f1bc34fcc1fa66211bf3a56ede74430e1d583fda0b74cdaa6a762bd43933885e8bc18a957a52675e4b04
7
- data.tar.gz: c9d936604c20eceffe775d87322eec6e894c458b7fc70c2299be64231f8abc7b1d5b879a19571a1bcbf1446348762fd56972af3c2849181332720eae8509b7ab
6
+ metadata.gz: 10f0310b8a034da123d18f08da7b22698b57acc31520c66a2e9d9306d64c028f161e3f0a77b123fca96b50ff56ece5e9434a924f0481d2bc34859d971b80225e
7
+ data.tar.gz: c8b49ba2fa7bb1f1b715fbbb04dea79ed361657a2483d7fc4f8a8fbe2a61694a28c6992ad0cffd7edc19e0fc81a6e03b09b1abd6ed8dd08300d91826a2cd63b2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
data/lib/bender/bot.rb CHANGED
@@ -32,6 +32,10 @@ class BenderBot
32
32
 
33
33
  JARO = FuzzyStringMatch::JaroWinkler.create :native
34
34
 
35
+ RESOLVED_TRANSITIONS = %w[ 51 ]
36
+
37
+ RESOLVED_STATE = /resolve/i
38
+
35
39
  CLOSED_TRANSITIONS = %w[ 61 71 ]
36
40
 
37
41
  CLOSED_STATE = /close/i
@@ -91,9 +95,13 @@ class BenderBot
91
95
  fmt: 'INCIDENT_NUMBER',
92
96
  desc: 'Display incident details'
93
97
  },
98
+ resolve: {
99
+ fmt: 'INCIDENT_NUMBER',
100
+ desc: 'Resolve an incident',
101
+ },
94
102
  close: {
95
103
  fmt: 'INCIDENT_NUMBER',
96
- desc: 'Display incident details',
104
+ desc: 'Close an incident',
97
105
  },
98
106
  open: {
99
107
  fmt: "SEVERITY=#{SEVERITIES.keys.sort_by(&:to_i).join(',')} SUMMARY_TEXT",
@@ -258,6 +266,15 @@ class BenderBot
258
266
  ]
259
267
  end
260
268
 
269
+ # /inc resolve NUM - Resolve an incident
270
+ when /^\s*\/inc\s+resolve\s+(\d+)\s*$/
271
+ incident = select_incident $1
272
+ if incident
273
+ reply_html *resolve_incident(incident)
274
+ else
275
+ reply_html 'Sorry, no such incident!', :red
276
+ end
277
+
261
278
  # /inc close NUM - Close an incident
262
279
  when /^\s*\/inc\s+close\s+(\d+)\s*$/
263
280
  incident = select_incident $1
@@ -376,6 +393,49 @@ private
376
393
  end
377
394
 
378
395
 
396
+
397
+ def resolve_incident incident
398
+ status = normalize_value incident['fields']['status']
399
+ if status =~ RESOLVED_STATE
400
+ return [
401
+ "#{incident_link(incident)} is already resolved!",
402
+ :green
403
+ ]
404
+ end
405
+
406
+ req_path = '/rest/api/2/issue/%s/transitions?expand=transitions.fields' % [
407
+ incident['key']
408
+ ]
409
+ uri = URI(options.jira_site + req_path)
410
+ http = Net::HTTP.new uri.hostname, uri.port
411
+
412
+ req = Net::HTTP::Post.new uri
413
+ req.basic_auth options.jira_user, options.jira_pass
414
+ req['Content-Type'] = 'application/json'
415
+ req['Accept'] = 'application/json'
416
+
417
+ RESOLVED_TRANSITIONS.each do |tid|
418
+ req.body = {
419
+ transition: { id: tid }
420
+ }.to_json
421
+ http.request req
422
+ end
423
+
424
+ incident = select_incident incident['key'].split('-',2).last
425
+ status = normalize_value incident['fields']['status']
426
+
427
+ if status =~ RESOLVED_STATE
428
+ [ 'Resolved ' + incident_link(incident), :green ]
429
+ else
430
+ [
431
+ "Failed to resolve #{incident_link(incident)} automatically, you might try yourself",
432
+ :red
433
+ ]
434
+ end
435
+ end
436
+
437
+
438
+
379
439
  def close_incident incident
380
440
  status = normalize_value incident['fields']['status']
381
441
  if status =~ CLOSED_STATE
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.2.3
4
+ version: 0.2.4
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-08-25 00:00:00.000000000 Z
11
+ date: 2015-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  version: '0'
207
207
  requirements: []
208
208
  rubyforge_project:
209
- rubygems_version: 2.4.5
209
+ rubygems_version: 2.4.5.1
210
210
  signing_key:
211
211
  specification_version: 4
212
212
  summary: Yet another HipChat bot