lita-stackstorm 0.5.2 → 0.5.3
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/lib/lita/handlers/stackstorm.rb +28 -8
- data/lita-stackstorm.gemspec +1 -1
- 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: cf8f71a403fa1cf6bf82f1322f7b1f334f03e143
|
4
|
+
data.tar.gz: 3d955d16f7b91237373179b4fca42ec4e392656c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
61
|
-
|
62
|
-
|
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
|
65
|
-
format:
|
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
|
-
|
74
|
-
|
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
|
-
|
96
|
+
h[h.keys.min].each do |match|
|
77
97
|
response_text+= "\n\t#{match}"
|
78
98
|
end
|
79
99
|
msg.reply response_text
|
data/lita-stackstorm.gemspec
CHANGED