Skip to content

Commit

Permalink
Support releasing feature branch from any repo
Browse files Browse the repository at this point in the history
Allow users to run the release command without requiring
that they first checkout the feature branch.  This allows for
developers to sign-off and release a feature branch much quicker.
  • Loading branch information
wireframe committed Mar 15, 2015
1 parent 2ebcec0 commit 293745b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ options:
NOTE: the `--bump` option will also update the pull request commit status to mark the branch as 'pending peer review'.
This setting is cleared when a reviewer approves or rejects the pull request.

## git release
## git release <feature_branch_name (optional, default: current_branch)

release the current feature branch to master. This operation will perform the following:
release the feature branch to master. This operation will perform the following:

* pull in latest code from remote branch
* merge in latest code from master branch
* pull latest code from remote feature branch
* pull latest code from master branch
* prompt user to confirm they actually want to perform the release
* check if pull request commit status is currently successful
* merge current branch into master
* (optional) cleanup merged branches from remote server

Expand Down
5 changes: 3 additions & 2 deletions lib/thegarage/gitx/cli/release_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ class ReleaseCommand < BaseCommand

desc 'release', 'release the current branch to production'
method_option :cleanup, :type => :boolean, :desc => 'cleanup merged branches after release'
def release
def release(branch = nil)
return unless yes?("Release #{current_branch.name} to production? (y/n)", :green)

branch = current_branch.name
branch ||= current_branch.name
assert_not_protected_branch!(branch, 'release')
checkout_branch(branch)
execute_command(UpdateCommand, :update)

find_or_create_pull_request(branch)
Expand Down
26 changes: 26 additions & 0 deletions spec/thegarage/gitx/cli/release_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
expect(cli).to receive(:yes?).and_return(true)
allow(cli).to receive(:authorization_token).and_return(authorization_token)

expect(cli).to receive(:run_cmd).with("git checkout feature-branch").ordered
expect(cli).to receive(:run_cmd).with("git checkout master").ordered
expect(cli).to receive(:run_cmd).with("git pull origin master").ordered
expect(cli).to receive(:run_cmd).with("git merge --no-ff feature-branch").ordered
Expand All @@ -74,6 +75,29 @@
should meet_expectations
end
end
context 'when target_branch is not nil and user confirms release and pull request exists with success status' do
before do
expect(cli).to receive(:execute_command).with(Thegarage::Gitx::Cli::UpdateCommand, :update)
expect(cli).to receive(:execute_command).with(Thegarage::Gitx::Cli::IntegrateCommand, :integrate, 'staging')
expect(cli).to_not receive(:execute_command).with(Thegarage::Gitx::Cli::CleanupCommand, :cleanup)

expect(cli).to receive(:yes?).and_return(true)
allow(cli).to receive(:authorization_token).and_return(authorization_token)

expect(cli).to receive(:run_cmd).with("git checkout feature-branch").ordered
expect(cli).to receive(:run_cmd).with("git checkout master").ordered
expect(cli).to receive(:run_cmd).with("git pull origin master").ordered
expect(cli).to receive(:run_cmd).with("git merge --no-ff feature-branch").ordered
expect(cli).to receive(:run_cmd).with("git push origin HEAD").ordered

VCR.use_cassette('pull_request_does_exist_with_success_status') do
cli.release 'feature-branch'
end
end
it 'runs expected commands' do
should meet_expectations
end
end
context 'when user confirms release and pull request does not exist' do
let(:new_pull_request) do
{
Expand All @@ -96,6 +120,7 @@
expect(cli).to receive(:yes?).with('Release feature-branch to production? (y/n)', :green).and_return(true)
expect(cli).to receive(:yes?).with('Branch status is currently: pending. Proceed with release? (y/n)', :red).and_return(true)

expect(cli).to receive(:run_cmd).with("git checkout feature-branch").ordered
expect(cli).to receive(:run_cmd).with("git checkout feature-branch").ordered
expect(cli).to receive(:run_cmd).with("git log master...feature-branch --reverse --no-merges --pretty=format:'* %s%n%b'").and_return("2013-01-01 did some stuff").ordered
expect(cli).to receive(:run_cmd).with("git checkout master").ordered
Expand Down Expand Up @@ -129,6 +154,7 @@
expect(cli).to receive(:yes?).and_return(true)
allow(cli).to receive(:authorization_token).and_return(authorization_token)

expect(cli).to receive(:run_cmd).with("git checkout feature-branch").ordered
expect(cli).to receive(:run_cmd).with("git checkout master").ordered
expect(cli).to receive(:run_cmd).with("git pull origin master").ordered
expect(cli).to receive(:run_cmd).with("git merge --no-ff feature-branch").ordered
Expand Down

0 comments on commit 293745b

Please sign in to comment.