Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use the heroku gem's --remote option. Close issue #21.

  • Loading branch information...
commit 9f2addd48b1657295e661805db2ec3717064eeac 1 parent 6e39269
@tapajos tapajos authored
View
2  README.md
@@ -100,7 +100,7 @@ Yes. To indicate that a particular app is using Cedar, run with the -c flag:
a465afd..bc8932b master -> master
==> - true
==> Pushed master -> heroku-staging
- ==> + bundle exec heroku rake db:migrate --app staging-sushi
+ ==> + bundle exec heroku rake db:migrate --remote staging-sushi
... Postgres output removed ...
==> - false
==> Migrated staging-sushi
View
4 features/kumade_executable.feature
@@ -27,7 +27,7 @@ Feature: Kumade executable
run git branch deploy
run git push -f pretend-staging deploy:master
==> Pushed deploy:master -> pretend-staging
- ==> Migrated pretend-staging-app
+ ==> Migrated pretend-staging
run git checkout master && git branch -D deploy
==> Deployed to: pretend-staging
"""
@@ -58,7 +58,7 @@ Feature: Kumade executable
run git branch deploy
run git push -f pretend-staging deploy:master
==> Pushed deploy:master -> pretend-staging
- ==> Migrated pretend-staging-app
+ ==> Migrated pretend-staging
run git checkout new_branch && git branch -D deploy
==> Deployed to: pretend-staging
"""
View
12 lib/kumade/deployer.rb
@@ -36,23 +36,21 @@ def sync_heroku
end
def heroku_migrate
- app = Kumade::Git.app_for(environment)
-
- heroku("rake db:migrate", app) unless pretending
- success("Migrated #{app}")
+ heroku("rake db:migrate") unless pretending
+ success("Migrated #{environment}")
end
def post_deploy
git.delete(DEPLOY_BRANCH, @branch)
end
- def heroku(command, app)
+ def heroku(command)
heroku_command = if @cedar
"bundle exec heroku run"
else
"bundle exec heroku"
end
- run_or_error("#{heroku_command} #{command} --app #{app}",
+ run_or_error("#{heroku_command} #{command} --remote #{environment}",
"Failed to run #{command} on Heroku")
end
@@ -146,7 +144,7 @@ def custom_task?
def ensure_heroku_remote_exists
if git.remote_exists?(environment)
- if app_name = Kumade::Git.app_for(environment)
+ if git.heroku_remote?
success("#{environment} is a Heroku remote")
else
error(%{Cannot deploy: "#{environment}" remote does not point to Heroku})
View
10 lib/kumade/git.rb
@@ -1,18 +1,14 @@
module Kumade
class Git < Base
+ attr_reader :environment
def initialize(pretending, environment)
super()
@pretending = pretending
@environment = environment
end
- def self.app_for(environment)
- heroku_git_url = `git config --get remote.#{environment}.url`.strip
- if heroku_git_url =~ /^git@heroku\.com:(.+)\.git$/
- $1
- else
- nil
- end
+ def heroku_remote?
+ `git config --get remote.#{environment}.url`.strip =~ /^git@heroku\.com:(.+)\.git$/
end
def self.environments
View
23 spec/kumade/deployer_spec.rb
@@ -30,11 +30,10 @@
describe Kumade::Deployer, "#deploy" do
let(:remote_name){ 'staging' }
- let(:app_name){ 'kumade-staging' }
before do
subject.stub(:say)
- force_add_heroku_remote(remote_name, app_name)
+ force_add_heroku_remote(remote_name)
end
it "calls the correct methods in order" do
@@ -361,18 +360,17 @@ class More
describe Kumade::Deployer, "#heroku_migrate" do
let(:environment){ 'staging' }
- let(:app_name){ 'sushi' }
before do
subject.stub(:say)
- force_add_heroku_remote(environment, app_name)
+ force_add_heroku_remote(environment)
end
it "runs db:migrate with the correct app" do
subject.stub(:run => true)
subject.should_receive(:heroku).
- with("rake db:migrate", app_name)
- subject.should_receive(:success).with("Migrated #{app_name}")
+ with("rake db:migrate")
+ subject.should_receive(:success).with("Migrated staging")
subject.heroku_migrate
end
@@ -381,11 +379,10 @@ class More
describe Kumade::Deployer, "#ensure_heroku_remote_exists" do
let(:environment){ 'staging' }
let(:bad_environment){ 'bad' }
- let(:staging_app_name) { 'staging-sushi' }
before do
subject.stub(:say)
- force_add_heroku_remote(environment, staging_app_name)
+ force_add_heroku_remote(environment)
`git remote add #{bad_environment} blerg@example.com`
end
@@ -429,14 +426,12 @@ class More
end
describe Kumade::Deployer, "#heroku" do
- let(:app_name){ 'sushi' }
-
context "when on Cedar" do
subject { Kumade::Deployer.new('staging', false, cedar = true) }
it "runs commands with `run`" do
- subject.should_receive(:run_or_error).with("bundle exec heroku run rake --app #{app_name}", //)
- subject.heroku("rake", app_name)
+ subject.should_receive(:run_or_error).with("bundle exec heroku run rake --remote staging", //)
+ subject.heroku("rake")
end
end
@@ -444,8 +439,8 @@ class More
subject { Kumade::Deployer.new('staging', false, cedar = false) }
it "runs commands without `run`" do
- subject.should_receive(:run_or_error).with("bundle exec heroku rake --app #{app_name}", //)
- subject.heroku("rake", app_name)
+ subject.should_receive(:run_or_error).with("bundle exec heroku rake --remote staging", //)
+ subject.heroku("rake")
end
end
end
View
22 spec/kumade/git_spec.rb
@@ -1,41 +1,35 @@
require 'spec_helper'
-describe Kumade::Git, ".app_for" do
+describe Kumade::Git, "#heroku_remote?" do
let(:environment){ 'staging' }
- let(:app_name){ 'staging_test' }
let(:not_a_heroku_env){ 'fake_heroku' }
let(:not_a_heroku_url){ 'git@github.com:gabebw/kumade.git' }
before do
- force_add_heroku_remote(environment, app_name)
+ force_add_heroku_remote(environment)
`git remote add #{not_a_heroku_env} #{not_a_heroku_url}`
end
after do
remove_remote(environment)
remove_remote(not_a_heroku_env)
end
-
- it "autodetects the Heroku app name" do
- Kumade::Git.app_for(environment).should == app_name
- end
-
- it "is nil if the app cannot be found" do
- Kumade::Git.app_for('xyz').should be_nil
+
+ it "should return true when environment remote is a heroku repository" do
+ Kumade::Git.new(false, environment).heroku_remote?.should be_true
end
- it "is nil if the remote is not a Heroku remote" do
- Kumade::Git.app_for(not_a_heroku_env).should be_nil
+ it "should return false when environment remote isn't a heroku repository" do
+ Kumade::Git.new(false, 'kumade').heroku_remote?.should be_false
end
end
describe Kumade::Git, ".environments" do
let(:environment){ 'staging' }
- let(:app_name){ 'staging_test' }
let(:not_a_heroku_env){ 'fake_heroku' }
let(:not_a_heroku_url){ 'git@github.com:gabebw/kumade.git' }
before do
- force_add_heroku_remote(environment, app_name)
+ force_add_heroku_remote(environment)
`git remote add #{not_a_heroku_env} #{not_a_heroku_url}`
end
after do
View
4 spec/spec_helper.rb
@@ -5,9 +5,9 @@
require 'aruba/api'
module GitRemoteHelpers
- def force_add_heroku_remote(remote_name, app_name)
+ def force_add_heroku_remote(remote_name)
remove_remote(remote_name)
- `git remote add #{remote_name} git@heroku.com:#{app_name}.git`
+ `git remote add #{remote_name} git@heroku.com:#{remote_name}.git`
end
def remove_remote(remote_name)
Please sign in to comment.
Something went wrong with that request. Please try again.