lita-heroku 0.1.7 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 073e7ba90eaebb8c3031c8b9df00133ade6d605d
4
- data.tar.gz: 2d8b509bcce5eb696b2b54109a90bcbbca93cb77
3
+ metadata.gz: d69b82f19f129ff76107502cb2de9966a49c11bd
4
+ data.tar.gz: b25de92fe6c4cbb20d1324cf9ae2b439a3aad41d
5
5
  SHA512:
6
- metadata.gz: 6cabebea9a2a7f97701702c599b27357d32af7444edede9720c8f4297f70d5823a96d274e180af5c47aaabd4d1d0f7881dcf6bafb08b5fe4a8979552867b539f
7
- data.tar.gz: 895648e6de44a6d5f88a5c1b9c7224ef004261e8e63cbf4bb058cf2fc563a6697b27f8f725bb9369b7cfedb78a819a1ef6b03773cf338f9be454d41ea1c202c7
6
+ metadata.gz: b2c5dcd64e72a8085923b6e69a60fcb2746bd73315f27f40eea6fd595faaaf4906739021c9e53000b8e18a1f5b1b4990dcbfa7a29d3fcf57701ac15e92ef67be
7
+ data.tar.gz: fba3ca5fd26a6b1ca5eeae0387213fa471bbc51ef782e37c1c4437e904a3f974ed30cd20329440187bb12adca135bd4b43c10ad402483125449225a051105af5
@@ -18,13 +18,7 @@ module Lita
18
18
  if command.start_with? "deploy"
19
19
  heroku_deploy response
20
20
  else
21
- stdout, stderr, status = Open3.capture3 "#{heroku_bin} #{command} -a #{config.app_prefix}#{environment}"
22
- response_text = "```\n"
23
- response_text += stdout
24
- response_text += stderr
25
- response_text += "Exited with status #{status.exitstatus}" unless status.exitstatus.zero?
26
- response_text += "```"
27
- response.reply response_text
21
+ stream_command response, "#{heroku_bin} #{command} -a #{config.app_prefix}#{environment}"
28
22
  end
29
23
  end
30
24
 
@@ -54,6 +48,7 @@ module Lita
54
48
  build_response = JSON.parse build_response
55
49
 
56
50
  $stdout.puts build_response
51
+
57
52
  if build_response.key?("build") && build_response["build"]["status"] == "pending"
58
53
  response_text = "Deploying #{branch} to #{app_name}. "
59
54
  if config.bitly_access_token
@@ -72,6 +67,45 @@ module Lita
72
67
  JSON.parse `#{cmd}`
73
68
  end
74
69
 
70
+ private
71
+
72
+ def stream_command response, command
73
+ channel = response.message.source.room
74
+
75
+ Open3.popen2e(command) do |stdin, stdout_and_stderr, thread|
76
+ response.reply "```\nStarting `#{command.gsub "\n", '\\n'}`:\n```"
77
+ timestamp, text = get_last_message channel
78
+
79
+ last_update = Time.now.to_i - 2
80
+ text_response = String.new
81
+
82
+ while line = stdout_and_stderr.gets
83
+ text.gsub!("```", "")
84
+ text += line
85
+ text_response = "```#{text}```"
86
+ if Time.now.to_i - last_update > 2
87
+ last_update = Time.now.to_i
88
+ update_response channel, timestamp, text_response
89
+ end
90
+ end
91
+ update_response channel, timestamp, text_response
92
+ end
93
+ end
94
+
95
+ def update_response channel, timestamp, text
96
+ robot.chat_service.api.send(
97
+ :call_api, "chat.update", { channel: channel, ts: timestamp, as_user: true, text: text }
98
+ )
99
+ end
100
+
101
+ def get_last_message channel
102
+ # Would be nice if we could get this from the `response.reply`
103
+ msg = robot.chat_service.api.send(
104
+ :call_api, "im.history", { channel: channel, count: 1 } # Probably need to filter
105
+ )
106
+ [msg["messages"][0]["ts"], msg["messages"][0]["text"]]
107
+ end
108
+
75
109
  Lita.register_handler(self)
76
110
  end
77
111
  end
data/lita-heroku.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-heroku"
3
- spec.version = "0.1.7"
3
+ spec.version = "0.1.8"
4
4
  spec.authors = ["Eric Boehs"]
5
5
  spec.email = ["ericboehs@gmail.com"]
6
6
  spec.description = "Lita handler for interacting with Heroku Apps"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-heroku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Boehs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-11 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita