lita-stackstorm 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a08d0bd0d5c21c5001b188b581a293ae00d869b9
4
- data.tar.gz: 97387dba3afe6cfe9ec05b2d0ae234ef441efbf6
3
+ metadata.gz: cf8f71a403fa1cf6bf82f1322f7b1f334f03e143
4
+ data.tar.gz: 3d955d16f7b91237373179b4fca42ec4e392656c
5
5
  SHA512:
6
- metadata.gz: 153ef37f561ed55df0aba60c02a357b365fae384e32a201ea8ee7cb3dfcb807efdf624ff873bc5b41fcca693117c01c0542c6116960c31fb7b35404dbe819dba
7
- data.tar.gz: 0879872781301b5c7fc72befc51a44e8aeb87d0058e69d8362a9f84b7253ab11d4dfe7ad998f7e5eda7a3d5f0a77bff0eb3fa9a68db6474af3c4e983da799679
6
+ metadata.gz: 1671be84e6ae51b4676dbb6880b8c7a5e3629527c1003a926e588ed8573c0b48220efcd521b9d07e5391dc4be9a70fbda60ce685dbb7a1f3dd7703dcfb0b3767
7
+ data.tar.gz: 666782d0dd08500f772200706f13d355f4b2c2ff07c66a4f78e037f6b1d3e5e5dc38edbaf73e77978719a4c4afff21a451423d2e66e0cd9b9db07fbcb1557008
@@ -1,5 +1,14 @@
1
1
  require 'json'
2
2
 
3
+ class Array
4
+ def swap!(a,b)
5
+ self[a], self[b] = self[b], self[a]
6
+ self
7
+ end
8
+ end
9
+
10
+
11
+
3
12
  module Lita
4
13
  module Handlers
5
14
  class Stackstorm < Handler
@@ -56,13 +65,20 @@ module Lita
56
65
  authenticate
57
66
  end
58
67
  command_array = msg.matches.flatten.first.split
68
+ command_set = Set.new(command_array)
69
+
59
70
  candidates = redis.scan_each(:match => "#{command_array[0..1].join(' ')}*")
60
- p = candidates.take_while {|i| i.split.length == command_array.length}
61
- l = candidates.take_while {|i| i.split.length > command_array.length}
62
- if p.length == 1
71
+
72
+ candidates_set = Set.new(candidates)
73
+ h = candidates_set.classify do |s|
74
+ st = Set.new(s.split /(?<=})\s|\s(?={)|\b\s\b/)
75
+ (st - command_set).length
76
+ end
77
+
78
+ if h[h.keys.min].length == 1
63
79
  payload = {
64
- name: command_array[0..1].join('_'),
65
- format: "#{command_array[0..1].join(' ')} {{pack}}",
80
+ name: command_array.swap!(command_array.length-2,command_array.length-1).join('_'),
81
+ format: h[h.keys.min].to_a.join(" "),
66
82
  command: msg.matches.flatten.first,
67
83
  user: msg.user.name,
68
84
  source_channel: 'chatops',
@@ -70,10 +86,14 @@ module Lita
70
86
  }
71
87
  s = make_post_request("/aliasexecution", payload)
72
88
  j = JSON.parse(s.body)
73
- msg.reply "Got it! Details available at #{config.url}/#/history/#{j['execution']['id']}/general"
74
- elsif l.length > 0
89
+ if s.success?
90
+ msg.reply "Got it! Details available at #{config.url}/#/history/#{j['execution']['id']}/general"
91
+ else
92
+ msg.reply "Execution failed with message: #{j['faultstring']}"
93
+ end
94
+ elsif h[h.keys.min].length > 1
75
95
  response_text = "possible matches:"
76
- l.each do |match|
96
+ h[h.keys.min].each do |match|
77
97
  response_text+= "\n\t#{match}"
78
98
  end
79
99
  msg.reply response_text
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-stackstorm"
3
- spec.version = "0.5.2"
3
+ spec.version = "0.5.3"
4
4
  spec.authors = ["Jurnell Cockhren"]
5
5
  spec.email = ["jurnell@sophicware.com"]
6
6
  spec.description = "Stackstorm handler for lita 4+"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-stackstorm
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
  - Jurnell Cockhren