lita-heroku 0.1.2 → 0.1.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: 1ef0b49e0d8ccdd532240cf3dbe0464e757b5323
4
- data.tar.gz: 009a8150386caa5324e9f391dc9a24f4a0462cf9
3
+ metadata.gz: 7ea1479c89addbafb3f848555eecd0ccae6f164d
4
+ data.tar.gz: b5211f61d5bbae6b64a9b3a38560726b6f9154ca
5
5
  SHA512:
6
- metadata.gz: 1c99a77aa674c4f7a8fb643c8a73c7ab810589264d938c4778b430040a13d69a0c2e1db6ab20af9f42d90ec61efd25580c03841e1ef845a839d921682ee0d0d5
7
- data.tar.gz: 3294b29606614d408918da09cc0cd3dd4bffafd3e3ad33d687f1e7c18a314386f027764db685f6bd6a31f0ff25c9fbd0c0c4ca4f0e5692f02318d8b13a9fafd5
6
+ metadata.gz: 3a145aac191080e00fc5fbd605c8999fd70143564140bb45305971fde186b2c71625a79153189eb187847d0fcf5c1cdab34686996d168a4809381ea477778914
7
+ data.tar.gz: 73a357c27064d3cf5e72fc9fc1e18f3a5639858ef0e592af4f907552418d8e8d6a733d7ac182497dd98ca8283f2474417391ac936e3d40e8cb341bee8ff39cce
data/README.md CHANGED
@@ -10,6 +10,20 @@ Add lita-heroku to your Lita instance's Gemfile:
10
10
  gem "lita-heroku"
11
11
  ```
12
12
 
13
+ Create an oauth token and set it in config:
14
+
15
+ ``` bash
16
+ heroku plugins:install https://github.com/heroku/heroku-oauth
17
+ heroku authorizations:create -d "Lita Bot"
18
+ echo "HEROKU_OAUTH_TOKEN=YOUR_TOKEN" >> .env
19
+ ```
20
+
21
+ In your lita config:
22
+
23
+ ``` ruby
24
+ config.handlers.heroku.oauth_token = ENV.fetch("HEROKU_OAUTH_TOKEN")
25
+ ```
26
+
13
27
  ## Configuration
14
28
 
15
29
  TODO: Describe any configuration attributes the plugin exposes.
@@ -2,8 +2,8 @@ require "json"
2
2
  module Lita
3
3
  module Handlers
4
4
  class Heroku < Handler
5
- config :bearer, required: true
6
- config :application_id, required: true
5
+ config :oauth_token, required: true
6
+ config :app_prefix
7
7
 
8
8
  route(/^hk\s+([^ ]+)\s+(.+)/, :heroku_cmd, command: true, help: {
9
9
  "hk [app name] [command]" => "example: 'lita hk production ps'"
@@ -15,7 +15,7 @@ module Lita
15
15
  if command == "deploy"
16
16
  heroku_deploy response
17
17
  else
18
- response.reply `#{heroku_bin} #{command} -a hats-#{environment}`
18
+ response.reply `#{heroku_bin} #{command} -a #{config.app_prefix}#{environment}`
19
19
  end
20
20
  end
21
21
 
@@ -32,25 +32,35 @@ module Lita
32
32
  end
33
33
 
34
34
  route(/^hk deploy\s+(.+)/, :heroku_deploy, command: true, help: {
35
- "hk deploy [environment]" => "example: 'lita hk production deploy'"
35
+ "hk [environment] deploy" => "example: 'lita hk production deploy'"
36
36
  })
37
37
 
38
38
  def heroku_deploy(response)
39
- app_id = config.application_id
40
- bearer = config.bearer
41
- branch = "master"
39
+ bearer = config.oauth_token
40
+ app_name = "#{config.app_prefix}#{response.matches[0][0]}"
41
+ branch = response.matches[0][1] || "master"
42
+
43
+ apps = JSON.parse `curl -s "https://api.heroku.com/apps" -H "Authorization: Bearer #{bearer}" -H 'Accept: application/vnd.heroku+json; version=3'`
44
+ app = apps.select{|app| app["name"] == app_name }.first
45
+ app_id = app["id"]
42
46
 
43
47
  build_response = `curl -s "https://kolkrabbi.herokuapp.com/apps/#{app_id}/github/push" -H "Authorization: Bearer #{bearer}" -d '{"branch":"#{branch}"}'`
44
48
  build_response = JSON.parse build_response
45
49
 
46
50
  if build_response.key?("build") && build_response["build"]["status"] == "pending"
47
- response.reply("Started deploy.")
51
+ response.reply("Deploying #{branch} to #{app_name}.")
48
52
  else
49
53
  $stdout.puts build_response
50
- response.reply("Deploy could not be started. Check my logs for more information.")
54
+ response.reply("Deploy could not be started. Response: #{build_response}")
51
55
  end
52
56
  end
53
57
 
58
+ def api(bearer, uri, data=nil)
59
+ cmd = %Q{curl -s "https://kolkrabbi.herokuapp.com#{uri}" -H "Authorization: Bearer #{bearer}" -H 'range: name ..; order=asc, max=1000'}
60
+ cmd += %Q{-d '#{data}'} if data
61
+ JSON.parse `#{cmd}`
62
+ end
63
+
54
64
  Lita.register_handler(self)
55
65
  end
56
66
  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.2"
3
+ spec.version = "0.1.3"
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.2
4
+ version: 0.1.3
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-04 00:00:00.000000000 Z
11
+ date: 2016-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita