push2heroku 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/push2heroku/base.rb +61 -0
- data/lib/push2heroku/config_loader.rb +21 -0
- data/lib/push2heroku/git.rb +16 -0
- data/lib/push2heroku/railtie.rb +13 -0
- data/lib/push2heroku/version.rb +1 -1
- metadata +9 -5
@@ -0,0 +1,61 @@
|
|
1
|
+
module Push2heroku
|
2
|
+
class Base
|
3
|
+
|
4
|
+
attr_accessor :branch_name, :commands, :current_user, :subdomain, :settings
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
git = Git.new
|
8
|
+
@branch_name = git.current_branch
|
9
|
+
@current_user = git.current_user
|
10
|
+
@settings = ConfigLoader.new('push2heroku.yml').load(branch_name)
|
11
|
+
@commands = []
|
12
|
+
@subdomain = "#{url_prefix}-#{url_suffix}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.process
|
16
|
+
new.push
|
17
|
+
end
|
18
|
+
|
19
|
+
def push
|
20
|
+
build_commands
|
21
|
+
commands.each { |cmd| puts ">"*20 + cmd }
|
22
|
+
commands.each do |cmd|
|
23
|
+
begin
|
24
|
+
sh cmd
|
25
|
+
rescue Exception => e
|
26
|
+
puts e
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def url_suffix
|
34
|
+
return branch_name if %w(staging production).include?(branch_name)
|
35
|
+
|
36
|
+
[branch_name[0..10], current_user[0..5]].join('-').gsub(/[^0-9a-zA-Z]+/,'-').downcase
|
37
|
+
end
|
38
|
+
|
39
|
+
def url_prefix
|
40
|
+
settings.app_name.gsub(/[^0-9a-zA-Z]+/,'-').downcase
|
41
|
+
end
|
42
|
+
|
43
|
+
def build_commands
|
44
|
+
commands << "heroku create #{subdomain} --stack cedar --remote h#{branch_name}"
|
45
|
+
commands << "git push h#{branch_name} #{branch_name}:master -f "
|
46
|
+
|
47
|
+
build_config_commands
|
48
|
+
|
49
|
+
commands << "heroku run rake db:migrate --app #{subdomain} --trace"
|
50
|
+
commands << "heroku run rake setup --app #{subdomain} --trace"
|
51
|
+
commands << "heroku open --app #{subdomain}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def build_config_commands
|
55
|
+
settings.config.each do |key, value|
|
56
|
+
commands << "heroku config:add #{key.upcase}=#{value} --app #{subdomain}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Push2heroku
|
2
|
+
class ConfigLoader
|
3
|
+
|
4
|
+
attr_reader :filename
|
5
|
+
|
6
|
+
def initialize(filename)
|
7
|
+
@filename = filename
|
8
|
+
end
|
9
|
+
|
10
|
+
def load(key)
|
11
|
+
file = Rails.root.join('config', filename)
|
12
|
+
hash = YAML.load(ERB.new(File.read(file)).result)
|
13
|
+
|
14
|
+
common_hash = hash['common'] || {}
|
15
|
+
env_hash = hash[key.to_s] || {}
|
16
|
+
|
17
|
+
final_hash = common_hash.deep_merge(env_hash)
|
18
|
+
Hashr.new(final_hash)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Push2heroku
|
2
|
+
class Git
|
3
|
+
def current_branch
|
4
|
+
result = %x{git branch}.split("\n")
|
5
|
+
if result.empty?
|
6
|
+
raise "It seems your app is not a git repo"
|
7
|
+
else
|
8
|
+
result.select { |b| b =~ /^\*/ }.first.split(" ").last.strip.downcase
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def current_user
|
13
|
+
`git config user.name`.chop!.downcase
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/push2heroku/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: push2heroku
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-03-25 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hashr
|
16
|
-
requirement: &
|
16
|
+
requirement: &70184765576220 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - =
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.0.19
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70184765576220
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: heroku
|
27
|
-
requirement: &
|
27
|
+
requirement: &70184765575800 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70184765575800
|
36
36
|
description: push2heroku
|
37
37
|
email:
|
38
38
|
- neerajdotname@gmail.com
|
@@ -46,6 +46,10 @@ files:
|
|
46
46
|
- README.md
|
47
47
|
- Rakefile
|
48
48
|
- lib/push2heroku.rb
|
49
|
+
- lib/push2heroku/base.rb
|
50
|
+
- lib/push2heroku/config_loader.rb
|
51
|
+
- lib/push2heroku/git.rb
|
52
|
+
- lib/push2heroku/railtie.rb
|
49
53
|
- lib/push2heroku/version.rb
|
50
54
|
- push2heroku.gemspec
|
51
55
|
homepage: ''
|