diff --git a/README.md b/README.md index 2a9320b..07afc90 100644 --- a/README.md +++ b/README.md @@ -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 :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) diff --git a/spec/thegarage/gitx/cli/release_command_spec.rb b/spec/thegarage/gitx/cli/release_command_spec.rb index d77ea6f..84b3f13 100644 --- a/spec/thegarage/gitx/cli/release_command_spec.rb +++ b/spec/thegarage/gitx/cli/release_command_spec.rb @@ -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 @@ -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 { @@ -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 @@ -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