ruboty-replica 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1585ba5dfaa5b4e9773af0a1cf29d3a5a14d4f42
4
+ data.tar.gz: ab758f236f975ac94f7b4ccfe88c13def47df0ef
5
+ SHA512:
6
+ metadata.gz: 40d76c41628c146cf714c1fda9b8b03c13c322934dd975a5035e9c7fc9a0e6e4a3dc573c560d23332d9d08604d9e88a74ffbd014f78bc0208161102364299f2a
7
+ data.tar.gz: 81d5e20adfa6014ff9d9ff234982e1680bb76d5af87084ea33eb1a8a479046138de2861d8e9a06889ebd9afe1c9d284c42ca1b7f327a4599953459c977ac0b94
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-replica.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 block_given?
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # Ruboty::Replica
2
+
3
+ ruboty plugin for replicate itself.
4
+
5
+ ## Support
6
+ heroku
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'ruboty-replica'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install ruboty-replica
23
+
24
+ ## Usage
25
+
26
+ @ruboty replica
27
+
28
+ or
29
+
30
+ @ruboty
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it ( https://github.com/blockgiven/ruboty-replica/fork )
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,14 @@
1
+ module Ruboty
2
+ module Handlers
3
+ class Replica < Base
4
+ env :HEROKU_API_KEY, 'heroku api key'
5
+ env :HEROKU_APP_NAME, 'heroku app name'
6
+
7
+ on /replica(?: to(?<new_owner>.*@.*))?/, name: 'replica', description: 'replicate itself'
8
+
9
+ def replica(message)
10
+ Ruboty::Replica::Actions::Replica.new(message).call
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ require "ruboty/replica/version"
2
+ require "ruboty/handlers/replica"
3
+ require "ruboty/replica/actions/replica"
4
+
5
+ module Ruboty
6
+ module Replica
7
+ # Your code goes here...
8
+ end
9
+ end
@@ -0,0 +1,108 @@
1
+ module Ruboty
2
+ module Replica
3
+ module Actions
4
+ class Replica < Ruboty::Actions::Base
5
+ def call
6
+ replica = replicate!
7
+ message.reply("replica: replicated #{message.robot.name} to #{replica['name']}")
8
+ message.reply("replica: #{replica['git_url']}")
9
+
10
+ if message[:new_owner]
11
+ transfer!(replica, to: message[:new_owner])
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def transfer!(replica, recipient)
18
+ heroku.collaborator.create(replica['name'], user: recipient)
19
+ message.reply("replica: collaborator #{recipient} added")
20
+
21
+ heroku.app_transfer.create(app: replica['name'], recipient: recipient)
22
+ message.reply("replica: #{recipient} is now owner of #{replica['name']}")
23
+ end
24
+
25
+ def replicate!
26
+ replica = heroku.app.create({})
27
+
28
+ message.reply("replica: my name is #{replica['name']}")
29
+
30
+ heroku.config_var.update(
31
+ replica['name'],
32
+ replicable_config_vars.merge({
33
+ 'HEROKU_APP_NAME' => replica['name'],
34
+ 'ROBOT_NAME' => replica['name']
35
+ })
36
+ )
37
+
38
+ message.reply("replica: replicated env #{replicable_config_vars.keys.join(', ')}")
39
+
40
+ addons.each do |addon|
41
+ heroku.addon.create(replica['name'], {plan: addon['plan']['name']})
42
+ message.reply("replica: addon created #{addon['plan']['name']}")
43
+ end
44
+
45
+ heroku.release.create(replica['name'], slug: latest_release['slug']['id'])
46
+ message.reply("replica: slug copied")
47
+
48
+ heroku.formation.batch_update(replica['name'], {"updates" => replica_formations})
49
+ formation_text = replica_formations.map {|f|
50
+ "#{f[:process]} (#{f[:size]}): #{f[:quantity]}"
51
+ }.join(', ')
52
+ message.reply("replica: #{formation_text}")
53
+
54
+ replica
55
+ end
56
+
57
+ def app
58
+ @app ||= heroku.app.info(heroku_app_name)
59
+ end
60
+
61
+ def app_config_vars
62
+ @app_config_vars ||= heroku.config_var.info(heroku_app_name)
63
+ end
64
+
65
+ def app_formations
66
+ heroku.formation.list(app['name'])
67
+ end
68
+
69
+ def replica_formations
70
+ app_formations.map {|f| {process: f['type'], quantity: f['quantity'], size: f['size']} }
71
+ end
72
+
73
+ def replicable_config_vars
74
+ app_config_vars.except(*addon_config_var_keys, 'ROBOT_NAME', 'HEROKU_APP_NAME')
75
+ end
76
+
77
+ def addons
78
+ @addons ||= heroku.addon.list(heroku_app_name)
79
+ end
80
+
81
+ def addon_config_var_keys
82
+ addons.map {|addon| addon['config_vars'] }.flatten
83
+ end
84
+
85
+ def latest_release
86
+ releases.sort_by {|r| r['version'] }.last
87
+ end
88
+
89
+ def releases
90
+ @releases ||= heroku.release.list(heroku_app_name)
91
+ end
92
+
93
+ def heroku
94
+ require 'platform-api'
95
+ @heroku ||= PlatformAPI.connect(heroku_api_key)
96
+ end
97
+
98
+ def heroku_app_name
99
+ ENV['HEROKU_APP_NAME']
100
+ end
101
+
102
+ def heroku_api_key
103
+ ENV['HEROKU_API_KEY']
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Replica
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/replica/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-replica"
8
+ spec.version = Ruboty::Replica::VERSION
9
+ spec.authors = ["block_given?"]
10
+ spec.email = ["block_given@outlook.com"]
11
+ spec.summary = %q{ruboty plugin for replicate itself.}
12
+ spec.homepage = "https://github.com/blockgiven/ruboty-replica"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "ruboty"
21
+ spec.add_runtime_dependency "platform-api"
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-replica
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - block_given?
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: platform-api
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description:
70
+ email:
71
+ - block_given@outlook.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/ruboty/handlers/replica.rb
82
+ - lib/ruboty/replica.rb
83
+ - lib/ruboty/replica/actions/replica.rb
84
+ - lib/ruboty/replica/version.rb
85
+ - ruboty-replica.gemspec
86
+ homepage: https://github.com/blockgiven/ruboty-replica
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: ruboty plugin for replicate itself.
110
+ test_files: []
111
+ has_rdoc: