autobot 0.0.1

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: 361d598f2f827da377c5d94120279f16f76e213a
4
+ data.tar.gz: 9aaae677c7ed5f6d6d507e361b09f9bb5e252e60
5
+ SHA512:
6
+ metadata.gz: d562d95e4151d90aca3169926501a0dfa5a00097176ef5dbd696b2daa8b263ad99f9c4f3f9454bf451d1111169e72f09ca5fe01e109585195e126b9165e167af
7
+ data.tar.gz: dc245110e604933b1c4e5dc72ebddc85e8f9efc8e9731d56b32fb9d999fde8307874cfbfac643a15618ba44ee7671cf2a2beace78b6a736a0df72af0388fbd30
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in autobot_gem.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Antonio Scandurra
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,29 @@
1
+ # AutobotGem
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'autobot_gem'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install autobot_gem
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'autobot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "autobot"
8
+ spec.version = Autobot::VERSION
9
+ spec.authors = ["Antonio Scandurra"]
10
+ spec.email = ["as-cii@outlook.com"]
11
+ spec.description = %q{Create hubot from scratch in seconds!}
12
+ spec.summary = %q{Hubot deploy automation}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ # Development dependencies
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+
26
+ # Runtime dependencies
27
+ spec.add_runtime_dependency "heroku-api"
28
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'autobot'
4
+
5
+ Autobot::Runner.create_hubot(ARGV.first)
@@ -0,0 +1,3 @@
1
+ require 'autobot/version'
2
+ require 'autobot/utils'
3
+ require 'autobot/runner'
@@ -0,0 +1,143 @@
1
+ require 'heroku-api'
2
+ require 'io/console'
3
+ require 'fileutils'
4
+ require 'tmpdir'
5
+
6
+ # Avoid to flush at every `print` (Ref.: http://stackoverflow.com/a/5080779)
7
+ $stdout.sync = true
8
+
9
+ module Autobot
10
+ class Runner
11
+ # Public: Creates an hubot instance starting with an application name.
12
+ #
13
+ # app_name -
14
+ #
15
+ # Returns nothing.
16
+ def self.create_hubot(app_name)
17
+ check_binaries
18
+
19
+ print 'Insert your heroku api token: '
20
+ api_token = $stdin.gets
21
+ heroku = heroku_login(api_token)
22
+
23
+ heroku_app, is_new = get_or_create_heroku_app(heroku, app_name)
24
+ git_remote = heroku_app.data[:body]['git_url']
25
+ app_path = "#{Dir.pwd}/#{app_name}"
26
+
27
+ if Dir.exists?(app_path)
28
+ push_hubot_app(app_name, app_path, heroku, git_remote)
29
+ else
30
+ if is_new
31
+ create_empty_hubot(app_path)
32
+ else
33
+ system("git clone #{repository_url} #{app_path}")
34
+ end
35
+
36
+ puts "I've just cloned the repository: make every change you want and commit. I'll do the rest."
37
+ end
38
+
39
+ puts 'Autobot shutting down...'
40
+ end
41
+
42
+
43
+ # Public: Check if needed binaries are found: if any of these doesn't exist the program exits.
44
+ #
45
+ # Returns nothing.
46
+ def self.check_binaries
47
+ puts 'Checking binaries...'
48
+
49
+ abort('Missing npm, exiting...') unless which('npm')
50
+ abort('Missing heroku toolbelt, exiting...') unless which('heroku')
51
+ end
52
+
53
+ # Public: Pushes local repository to heroku adding a remote if it doesn't exist.
54
+ #
55
+ # app_name -
56
+ # app_path -
57
+ # heroku -
58
+ # git_remote -
59
+ #
60
+ # Returns nothing.
61
+ def self.push_hubot_app(app_name, app_path, heroku, git_remote)
62
+ Dir.chdir(app_path)
63
+
64
+ # Add heroku application as a remote
65
+ system("git remote add herokuapp #{git_remote}")
66
+
67
+ # Make sure we are at the latest version
68
+ system("git pull herokuapp master")
69
+
70
+ # Push our commits to heroku remote
71
+ system("git push herokuapp master")
72
+
73
+ return unless acceptor('Would you like to insert campfire environment variables?')
74
+
75
+ # Ask and add as config campfire data
76
+ puts 'Insert hubot campfire token'
77
+ hubot_token = $stdin.gets
78
+
79
+ puts 'Insert hubot campfire rooms'
80
+ hubot_rooms = $stdin.gets
81
+
82
+ puts 'Insert hubot campfire domain (e.g. the third level domain in your campfire account)'
83
+ hubot_domain = $stdin.gets
84
+
85
+ heroku.put_config_vars(app_name, 'HUBOT_CAMPFIRE_TOKEN' => hubot_token,
86
+ 'HUBOT_CAMPFIRE_ROOMS' => hubot_rooms,
87
+ 'HUBOT_CAMPFIRE_ACCOUNT' => hubot_domain)
88
+ end
89
+
90
+ # Public: Clones a virgin hubot from GitHub repository in a local repository.
91
+ #
92
+ # app_path -
93
+ #
94
+ # Returns nothing.
95
+ def self.create_empty_hubot(app_path)
96
+ temp_dir = Dir.mktmpdir
97
+ system("git clone https://github.com/github/hubot.git #{temp_dir}")
98
+
99
+ Dir.chdir(temp_dir)
100
+
101
+ # Install needed node.js packages and create an instance of hubot locally
102
+ system('npm install && make package')
103
+
104
+ # Copy hubot and clean tmpdir
105
+ FileUtils.cp_r("./hubot", app_path)
106
+ FileUtils.rm_rf(temp_dir)
107
+ end
108
+
109
+ # Public: Checks if an app exists: if no it creates one.
110
+ #
111
+ # heroku - An heroku client instance.
112
+ # app_name -
113
+ #
114
+ # Returns the duplicated String.
115
+ def self.get_or_create_heroku_app(heroku, app_name)
116
+ begin
117
+ [ heroku.get_app(app_name), false ]
118
+ rescue Heroku::API::Errors::Forbidden
119
+ nil
120
+ rescue Heroku::API::Errors::NotFound
121
+ puts "I didn't find #{app_name} on Heroku. I will create it for you!"
122
+ heroku.post_app('name' => app_name)
123
+ [ heroku.get_app(app_name), true ]
124
+ end
125
+ end
126
+
127
+ # Public: Makes login to heroku.
128
+ #
129
+ # api_token -
130
+ #
131
+ # Returns an heroku client instance.
132
+ def self.heroku_login(api_token)
133
+ heroku = Heroku::API.new(api_key: api_token)
134
+ begin
135
+ heroku.get_user
136
+ puts 'Authentication successful'
137
+ heroku
138
+ rescue Heroku::API::Errors::Unauthorized
139
+ abort('Your api token is not valid. Please verify it and retry to launch autobot!')
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,29 @@
1
+ # Public: Retrieve the location of an executable (mimics `which` behaviour)
2
+ # Ref.: http://stackoverflow.com/a/5471032
3
+ #
4
+ # cmd - The command name to check
5
+ #
6
+ # Returns the path of an executable if it is found, nil otherwise.
7
+ def which(cmd)
8
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
9
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
10
+ exts.each { |ext|
11
+ exe = File.join(path, "#{cmd}#{ext}")
12
+ return exe if File.executable? exe
13
+ }
14
+ end
15
+ return nil
16
+ end
17
+
18
+
19
+ # Public: Prints a question and waits for a yes-no answer.
20
+ #
21
+ # question -
22
+ #
23
+ # Returns true if the user answered yes, false otherwise.
24
+ def acceptor(question)
25
+ print "#{question} [YyNn]"
26
+ answer = $stdin.gets.downcase.strip
27
+
28
+ answer == "y"
29
+ end
@@ -0,0 +1,3 @@
1
+ module Autobot
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: autobot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Antonio Scandurra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: heroku-api
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Create hubot from scratch in seconds!
70
+ email:
71
+ - as-cii@outlook.com
72
+ executables:
73
+ - autobot
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - autobot.gemspec
83
+ - bin/autobot
84
+ - lib/autobot.rb
85
+ - lib/autobot/runner.rb
86
+ - lib/autobot/utils.rb
87
+ - lib/autobot/version.rb
88
+ homepage: ''
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.0.0
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Hubot deploy automation
112
+ test_files: []