lita-stackstorm 0.5.3 → 0.6.0

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: cf8f71a403fa1cf6bf82f1322f7b1f334f03e143
4
- data.tar.gz: 3d955d16f7b91237373179b4fca42ec4e392656c
3
+ metadata.gz: 5c6ce0e485828fef1c97a9231ebff3b9421cacdc
4
+ data.tar.gz: 89b55ca36a0a3948d319cf3c403ed5460da1179c
5
5
  SHA512:
6
- metadata.gz: 1671be84e6ae51b4676dbb6880b8c7a5e3629527c1003a926e588ed8573c0b48220efcd521b9d07e5391dc4be9a70fbda60ce685dbb7a1f3dd7703dcfb0b3767
7
- data.tar.gz: 666782d0dd08500f772200706f13d355f4b2c2ff07c66a4f78e037f6b1d3e5e5dc38edbaf73e77978719a4c4afff21a451423d2e66e0cd9b9db07fbcb1557008
6
+ metadata.gz: efd097d6aaf2860a6f758c87576ae05be5597c63851b317e6b135c894d29647064e10121fa2e4543155b4a2ecd8978e84768a9fd7e2b92f6e646aaa6800484c0
7
+ data.tar.gz: bf18120bcdbe8f01c6445a17a2e00af550bad372eade6055ca4c7755a4bafb0217130429197fe616fd79a710fbc8953d62d92c203f4f76ad37e5b9200e1b3def
@@ -30,12 +30,12 @@ module Lita
30
30
  end
31
31
 
32
32
  route /^st2 login$/, :login, command: false, help: { "st2 login" => "login with st2-api" }
33
- route /^st2 list$/, :list, command: false, help: { "st2 list" => "list available st2 chatops commands" }
33
+ route /^st2 (ls|aliases|list)$/, :list, command: false, help: { "st2 list" => "list available st2 chatops commands" }
34
34
 
35
35
  route /^!(.*)$/, :call_alias, command: false, help: {}
36
36
 
37
37
  def auth_builder
38
- if config.auth_port == '443' and config.url.start_with?('https')
38
+ if Integer(config.auth_port) == 443 and config.url.start_with?('https')
39
39
  "#{config.url}/auth"
40
40
  else
41
41
  "#{config.url}:#{config.auth_port}/v1"
@@ -43,7 +43,7 @@ module Lita
43
43
  end
44
44
 
45
45
  def url_builder
46
- if config.execution_port == '443' and config.url.start_with?('https')
46
+ if Integer(config.execution_port) == 443 and config.url.start_with?('https')
47
47
  "#{config.url}/api"
48
48
  else
49
49
  "#{config.url}:#{config.execution_port}/v1"
@@ -64,41 +64,31 @@ module Lita
64
64
  if expired
65
65
  authenticate
66
66
  end
67
- command_array = msg.matches.flatten.first.split
68
- command_set = Set.new(command_array)
69
-
70
- candidates = redis.scan_each(:match => "#{command_array[0..1].join(' ')}*")
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
67
+ command = msg.matches.flatten.first
68
+ found = ""
69
+ redis.scan_each do |a|
70
+ possible = /#{a}/.match(command)
71
+ if not possible.nil?
72
+ found = a
73
+ break
74
+ end
76
75
  end
77
76
 
78
- if h[h.keys.min].length == 1
79
- payload = {
80
- name: command_array.swap!(command_array.length-2,command_array.length-1).join('_'),
81
- format: h[h.keys.min].to_a.join(" "),
82
- command: msg.matches.flatten.first,
83
- user: msg.user.name,
84
- source_channel: 'chatops',
85
- notification_channel: 'lita'
86
- }
87
- s = make_post_request("/aliasexecution", payload)
88
- j = JSON.parse(s.body)
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
95
- response_text = "possible matches:"
96
- h[h.keys.min].each do |match|
97
- response_text+= "\n\t#{match}"
98
- end
99
- msg.reply response_text
77
+ jobject = JSON.parse(redis.get(found))
78
+ payload = {
79
+ name: jobject['object']['name'],
80
+ format: jobject['format'],
81
+ command: command,
82
+ user: msg.user.name,
83
+ source_channel: 'chatops',
84
+ notification_channel: 'lita'
85
+ }
86
+ s = make_post_request("/aliasexecution", payload)
87
+ j = JSON.parse(s.body)
88
+ if s.success?
89
+ msg.reply "Got it! Details available at #{config.url}/#/history/#{j['execution']['id']}/general"
100
90
  else
101
- msg.reply "Failed! No Aliases Found..."
91
+ msg.reply "Execution failed with message: #{j['faultstring']}"
102
92
  end
103
93
  end
104
94
 
@@ -106,16 +96,21 @@ module Lita
106
96
  if expired
107
97
  authenticate
108
98
  end
99
+ redis.keys.each {|k| redis.del k }
109
100
  s = make_request("/actionalias", "")
110
101
  if JSON.parse(s.body).empty?
111
102
  msg.reply "No Action Aliases Registered"
112
103
  else
113
104
  j = JSON.parse(s.body)
114
105
  a = ""
106
+ extra_params = '(\\s+(\\S+)\\s*=("([\\s\\S]*?)"|\'([\\s\\S]*?)\'|({[\\s\\S]*?})|(\\S+))\\s*)*'
115
107
  j.take_while{|i| i['enabled'] }.each do |command|
116
108
  command['formats'].each do |format|
117
- redis.set(format, command['action_ref'])
118
- a+= "#{format} -> #{command['action_ref']}\n"
109
+ f = format.gsub(/(\s*){{\s*\S+\s*=\s*(?:({.+?}|.+?))\s*}}(\s*)/, '\\s*([\\s\\S]+?)?\\s*')
110
+ f = f.gsub(/\s*{{.+?}}\s*/, '\\s*([\\s\\S]+?)\\s*')
111
+ f = "^\\s*#{f}#{extra_params}\\s*$"
112
+ redis.set(f, {format: format, object: command}.to_json)
113
+ a+= "#{format} -> #{command['description']}\n"
119
114
  end
120
115
  end
121
116
  msg.reply a
@@ -139,9 +134,8 @@ module Lita
139
134
 
140
135
  def make_request(path, body)
141
136
  resp = http.get("#{url_builder()}#{path}") do |req|
142
- req.body = {}
143
137
  req.headers = headers
144
- req.body = body.to_json
138
+ req.body = body.to_json if not body.empty?
145
139
  end
146
140
  resp
147
141
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-stackstorm"
3
- spec.version = "0.5.3"
3
+ spec.version = "0.6.0"
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-stackstorm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.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-05 00:00:00.000000000 Z
11
+ date: 2016-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -176,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  version: '0'
177
177
  requirements: []
178
178
  rubyforge_project:
179
- rubygems_version: 2.4.5.1
179
+ rubygems_version: 2.4.5
180
180
  signing_key:
181
181
  specification_version: 4
182
182
  summary: Stackstorm handler for lita 4+