lita-stackstorm 0.6.1 → 1.0.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/README.md +2 -1
- data/lib/lita/handlers/stackstorm.rb +54 -1
- data/lita-stackstorm.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cca8b595c894056c55c31311dd70fcade96d74a2
|
4
|
+
data.tar.gz: 0fc7ae2ecb90d9a426bc8e7ee172e58e0e50dd50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4860b50d9e6e49e5f289435d617e785b4b4177daa0aecee802ffdc590ac34c23e46cee990e9be796c8da0ee4285237aa553a4c58aa209c02e9df3b33fb3c28df
|
7
|
+
data.tar.gz: b38f7810111173a9d966c9783891836809eaa8434da4a3723a74e7ba9036b1c4594baa8c82ec140d110dd5d7d518f7a40469c369e4e9a5704f47220d8a8675bd
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# lita-stackstorm [](http://badge.fury.io/rb/lita-stackstorm)
|
1
|
+
# lita-stackstorm [](http://badge.fury.io/rb/lita-stackstorm)
|
2
2
|
|
3
3
|
**lita-stackstorm** is an handler for [Lita](https://www.lita.io) that allows your bot to interact with your stackstorm installation via st2api.
|
4
4
|
|
@@ -22,6 +22,7 @@ gem "lita-stackstorm"
|
|
22
22
|
|
23
23
|
* `auth_port` (Integer) – Port used for Authentication. Defaults to `9101`.
|
24
24
|
* `execution_port` (Integer) – Port for executions. Defaults to `9100`.
|
25
|
+
* `emoji_icon` (Integer) – Emoji used when bot injests event stream. Defaults to `:panda:`.
|
25
26
|
|
26
27
|
### Example
|
27
28
|
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'yaml'
|
2
4
|
|
3
5
|
class Array
|
4
6
|
def swap!(a,b)
|
@@ -19,6 +21,9 @@ module Lita
|
|
19
21
|
config :password, required: true
|
20
22
|
config :auth_port, required: false, default: 9100
|
21
23
|
config :execution_port, required: false, default: 9101
|
24
|
+
config :emoji_icon, required: false, default: ":panda:"
|
25
|
+
|
26
|
+
on :connected, :stream_listen
|
22
27
|
|
23
28
|
class << self
|
24
29
|
attr_accessor :token, :expires
|
@@ -34,6 +39,55 @@ module Lita
|
|
34
39
|
|
35
40
|
route /^!(.*)$/, :call_alias, command: false, help: {}
|
36
41
|
|
42
|
+
def direct_post(channel, message, user)
|
43
|
+
case robot.config.robot.adapter
|
44
|
+
when :slack
|
45
|
+
payload = {
|
46
|
+
action: "slack.chat.postMessage",
|
47
|
+
parameters: {
|
48
|
+
username: user,
|
49
|
+
text: message,
|
50
|
+
icon_emoji: config.emoji_icon,
|
51
|
+
channel: channel
|
52
|
+
}
|
53
|
+
}
|
54
|
+
make_post_request("/executions", payload)
|
55
|
+
else
|
56
|
+
target = Lita::Source.new(user: user, room: Lita::Room.fuzzy_find(channel))
|
57
|
+
robot.send_message(target, message)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def stream_listen(payload)
|
62
|
+
if expired
|
63
|
+
authenticate
|
64
|
+
end
|
65
|
+
uri = URI("#{url_builder()}/stream")
|
66
|
+
Thread.new {
|
67
|
+
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
|
68
|
+
request = Net::HTTP::Get.new uri
|
69
|
+
request['X-Auth-Token'] = headers()['X-Auth-Token']
|
70
|
+
request['Content-Type'] = 'application/x-yaml'
|
71
|
+
http.request request do |response|
|
72
|
+
io = StringIO.new
|
73
|
+
response.read_body do |chunk|
|
74
|
+
c = chunk.strip
|
75
|
+
if c.length > 0
|
76
|
+
io.write chunk
|
77
|
+
event = YAML.load(io.string)
|
78
|
+
if event['event'] =~ /st2\.announcement/
|
79
|
+
direct_post(event['data']['payload']['channel'],
|
80
|
+
event['data']['payload']['message'],
|
81
|
+
event['data']['payload']['user'])
|
82
|
+
end
|
83
|
+
io.reopen("")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
37
91
|
def auth_builder
|
38
92
|
if Integer(config.auth_port) == 443 and config.url.start_with?('https')
|
39
93
|
"#{config.url}/auth"
|
@@ -108,7 +162,6 @@ module Lita
|
|
108
162
|
command['formats'].each do |format|
|
109
163
|
f = format.gsub(/(\s*){{\s*\S+\s*=\s*(?:({.+?}|.+?))\s*}}(\s*)/, '\\s*([\\S]+)?\\s*')
|
110
164
|
f = f.gsub(/\s*{{.+?}}\s*/, '\\s*([\\S]+?)\\s*')
|
111
|
-
puts f
|
112
165
|
f = "^\\s*#{f}#{extra_params}\\s*$"
|
113
166
|
redis.set(f, {format: format, object: command}.to_json)
|
114
167
|
a+= "#{format} -> #{command['description']}\n"
|
data/lita-stackstorm.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-stackstorm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jurnell Cockhren
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|