Skip to content
This repository has been archived by the owner on Jun 8, 2019. It is now read-only.

Commit

Permalink
Move Kumade.app_for and Kumade.environments to Kumade::Git.app_for an…
Browse files Browse the repository at this point in the history
…d Kumade::Git.environments
  • Loading branch information
tapajos committed Aug 29, 2011
1 parent 239b07b commit 0c7daec
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
12 changes: 0 additions & 12 deletions lib/kumade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@
require 'kumade/railtie'

module Kumade
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
end
def self.environments
url_remotes = `git remote`.strip.split("\n").map{|remote| [remote, `git config --get remote.#{remote}.url`.strip] }.select{|remote| remote.last =~ /^git@heroku\.com:(.+)\.git$/}.map{|remote| remote.first}
end

def self.on_cedar!(app)
@cedar_apps ||= []
@cedar_apps << app
Expand Down
4 changes: 2 additions & 2 deletions lib/kumade/deployer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def sync_heroku
end

def heroku_migrate
app = Kumade.app_for(environment)
app = Kumade::Git.app_for(environment)

heroku("rake db:migrate", app) unless pretending
success("Migrated #{app}")
Expand Down Expand Up @@ -146,7 +146,7 @@ def custom_task?

def ensure_heroku_remote_exists
if git.remote_exists?(environment)
if app_name = Kumade.app_for(environment)
if app_name = Kumade::Git.app_for(environment)
success("#{environment} is a Heroku remote")
else
error(%{Cannot deploy: "#{environment}" remote does not point to Heroku})
Expand Down
13 changes: 13 additions & 0 deletions lib/kumade/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ def initialize(pretending, environment)
@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
end

def self.environments
url_remotes = `git remote`.strip.split("\n").map{|remote| [remote, `git config --get remote.#{remote}.url`.strip] }.select{|remote| remote.last =~ /^git@heroku\.com:(.+)\.git$/}.map{|remote| remote.first}
end

def push(branch, remote = 'origin', force = false)
command = ["git push"]
command << "-f" if force
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/deploy.rake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace :deploy do
Kumade.environments.each do |environment|
Kumade::Git.environments.each do |environment|
desc "Deploy to #{environment} environment"
task environment do
Kumade::Runner.run([environment])
Expand Down
16 changes: 8 additions & 8 deletions spec/kumade_spec.rb → spec/kumade/git_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'spec_helper'

describe Kumade, ".app_for" do
describe Kumade::Git, ".app_for" 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' }
let(:not_a_heroku_url){ 'git@github.com:gabebw/Kumade::Git.git' }

before do
force_add_heroku_remote(environment, app_name)
Expand All @@ -16,23 +16,23 @@
end

it "autodetects the Heroku app name" do
Kumade.app_for(environment).should == app_name
Kumade::Git.app_for(environment).should == app_name
end

it "is nil if the app cannot be found" do
Kumade.app_for('xyz').should be_nil
Kumade::Git.app_for('xyz').should be_nil
end

it "is nil if the remote is not a Heroku remote" do
Kumade.app_for(not_a_heroku_env).should be_nil
Kumade::Git.app_for(not_a_heroku_env).should be_nil
end
end

describe Kumade, ".environments" do
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' }
let(:not_a_heroku_url){ 'git@github.com:gabebw/Kumade::Git.git' }

before do
force_add_heroku_remote(environment, app_name)
Expand All @@ -44,6 +44,6 @@
end

it "should return all environments" do
Kumade.environments.should == ["staging"]
Kumade::Git.environments.should == ["staging"]
end
end

0 comments on commit 0c7daec

Please sign in to comment.