Skip to content

Commit

Permalink
Deployment from branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Polito and Jonathan Jackson authored and mattpolito committed Mar 24, 2014
1 parent 92e4fde commit e9f3b14
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.2.0

- Allow deploy from specific branch.

## 2.1.0

- Run remote tasks on your application
Expand Down
23 changes: 20 additions & 3 deletions lib/paratrooper/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ class Deploy

attr_accessor :app_name, :notifiers, :system_caller, :heroku, :tag_name,
:match_tag_name, :protocol, :deployment_host, :migration_check, :debug,
:screen_notifier
:screen_notifier, :branch_name

alias_method :tag=, :tag_name=
alias_method :match_tag=, :match_tag_name=
alias_method :branch=, :branch_name=

# Public: Initializes a Deploy
#
Expand All @@ -29,9 +30,13 @@ class Deploy
# (optional).
# :heroku - Object wrapper around heroku-api (optional).
# :tag - String name to be used as a git reference
# point (optional).
# point for deploying from specific tag
# (optional).
# :match_tag - String name of git reference point to match
# :tag to (optional).
# :branch - String name to be used as a git reference
# point for deploying from specific branch
# (optional).
# :system_caller - Object responsible for calling system
# commands (optional).
# :protocol - String web protocol to be used when pinging
Expand All @@ -48,6 +53,7 @@ def initialize(app_name, options = {}, &block)
@notifiers = options[:notifiers] || [@screen_notifier]
@heroku = options[:heroku] || HerokuWrapper.new(app_name, options)
@tag_name = options[:tag]
@branch_name = options[:branch]
@match_tag_name = options[:match_tag] || 'master'
@system_caller = options[:system_caller] || SystemCaller.new(debug)
@protocol = options[:protocol] || 'http'
Expand Down Expand Up @@ -109,8 +115,11 @@ def update_repo_tag

# Public: Pushes repository to Heroku.
#
# Based on the following precedence:
# branch_name / tag_name / 'master'
#
def push_repo
reference_point = tag_name || 'master'
reference_point = git_branch_name || git_tag_name || 'master'
callback(:push_repo) do
notify(:push_repo, reference_point: reference_point)
system_call "git push -f #{deployment_remote} #{reference_point}:refs/heads/master"
Expand Down Expand Up @@ -208,6 +217,14 @@ def git_remote(host, name)
"git@#{host}:#{name}.git"
end

def git_branch_name
"refs/heads/#{branch_name}" if branch_name
end

def git_tag_name
"refs/tags/#{tag_name}" if tag_name
end

def deployment_remote
git_remote(deployment_host, app_name)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/paratrooper/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Paratrooper
VERSION = "2.1.0".freeze
VERSION = "2.2.0".freeze
end
42 changes: 38 additions & 4 deletions spec/paratrooper/deploy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
end
end

describe "branch=" do
specify "branch is set and @branch_name holds value" do
deployer.branch = "branch_name"
expect(deployer.branch_name).to eq("branch_name")
end
end

describe "passing a block to initialize" do
it "sets attributes on self" do
deployer = described_class.new(app_name, default_options) do |p|
Expand Down Expand Up @@ -252,11 +259,38 @@
deployer.push_repo
end

it 'pushes repo to heroku' do
expected_call = 'git push -f git@heroku.com:app.git master:refs/heads/master'
system_caller.should_receive(:execute).with(expected_call)
deployer.push_repo
context "when branch_name is available" do
before do
deployer.branch_name = "BRANCH_NAME"
end

it 'pushes branch_name to heroku' do
expected_call = 'git push -f git@heroku.com:app.git refs/heads/BRANCH_NAME:refs/heads/master'
system_caller.should_receive(:execute).with(expected_call)
deployer.push_repo
end
end

context "when tag_name with no branch_name is available" do
before do
deployer.tag_name = "TAG_NAME"
end

it 'pushes branch_name to heroku' do
expected_call = 'git push -f git@heroku.com:app.git refs/tags/TAG_NAME:refs/heads/master'
system_caller.should_receive(:execute).with(expected_call)
deployer.push_repo
end
end

context "when no branch_name or tag_name" do
it 'pushes master repo to heroku' do
expected_call = 'git push -f git@heroku.com:app.git master:refs/heads/master'
system_caller.should_receive(:execute).with(expected_call)
deployer.push_repo
end
end

end

describe "#run_migrations" do
Expand Down

0 comments on commit e9f3b14

Please sign in to comment.