Skip to content

Commit

Permalink
Merge branch 'review-release-from-any-branch'
Browse files Browse the repository at this point in the history
* review-release-from-any-branch:
  Support releasing feature branch from any repo
  update docs
  bump version
  Support optional branch name for git review command
  • Loading branch information
wireframe committed Mar 16, 2015
2 parents f31e181 + 293745b commit 04f7fc4
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 15 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ update the local feature branch with latest remote changes plus upstream release

integrate the current feature branch into an aggregate branch (ex: prototype, staging)

## git review
## git review <feature_branch_name (optional, default: current_branch)>

create a pull request on github for peer review of the current branch. This command is re-runnable
in order to re-assign pull requests.
Expand All @@ -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
5 changes: 2 additions & 3 deletions lib/thegarage/gitx/cli/review_command.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'thor'
require 'thegarage/gitx'
require 'thegarage/gitx/cli/base_command'
require 'thegarage/gitx/cli/update_command'
require 'thegarage/gitx/github'

module Thegarage
Expand Down Expand Up @@ -41,10 +40,10 @@ class ReviewCommand < BaseCommand
method_option :approve, :type => :boolean, :desc => 'approve the pull request an post comment on pull request'
method_option :reject, :type => :boolean, :desc => 'reject the pull request an post comment on pull request'
# @see http://developer.github.com/v3/pulls/
def review
def review(branch = nil)
fail 'Github authorization token not found' unless authorization_token

branch = current_branch.name
branch ||= current_branch.name
pull_request = find_or_create_pull_request(branch)
bump_pull_request(pull_request) if options[:bump]
approve_pull_request(pull_request) if options[:approve]
Expand Down
2 changes: 2 additions & 0 deletions lib/thegarage/gitx/github.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'octokit'
require 'fileutils'
require 'yaml'
require 'thegarage/gitx/cli/update_command'

module Thegarage
module Gitx
Expand All @@ -20,6 +21,7 @@ module Github
def find_or_create_pull_request(branch)
pull_request = find_pull_request(branch)
pull_request ||= begin
checkout_branch(branch)
execute_command(Thegarage::Gitx::Cli::UpdateCommand, :update)
pull_request = create_pull_request(branch)
say 'Created pull request: '
Expand Down
2 changes: 1 addition & 1 deletion lib/thegarage/gitx/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Thegarage
module Gitx
VERSION = '2.12.0'
VERSION = '2.13.0'
end
end
2 changes: 1 addition & 1 deletion spec/thegarage/gitx/cli/integrate_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
expect(cli).to receive(:run_cmd).with("git merge feature-branch").ordered
expect(cli).to receive(:run_cmd).with("git push origin HEAD").ordered
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

stub_request(:post, 'https://api.github.com/repos/thegarage/thegarage-gitx/pulls').to_return(:status => 201, :body => new_pull_request.to_json, :headers => {'Content-Type' => 'application/json'})
Expand Down
30 changes: 27 additions & 3 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,8 @@
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
expect(cli).to receive(:run_cmd).with("git pull origin master").ordered
Expand Down Expand Up @@ -128,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 All @@ -140,9 +167,6 @@
it 'runs expected commands' do
should meet_expectations
end
it 'prunes merged branches (git cleanup)' do
should meet_expectations
end
end
end
end
36 changes: 36 additions & 0 deletions spec/thegarage/gitx/cli/review_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
expect(Thegarage::Gitx::Cli::UpdateCommand).to receive(:new).and_return(fake_update_command)

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 log master...feature-branch --reverse --no-merges --pretty=format:'* %s%n%b'").and_return("* old commit\n\n* new commit").ordered
expect(cli).to receive(:ask_editor).with("### Changelog\n* old commit\n\n* new commit\n#{Thegarage::Gitx::Github::PULL_REQUEST_FOOTER}", anything).and_return('description')

Expand All @@ -59,6 +60,41 @@
should meet_expectations
end
end
context 'when target branch is not nil and pull request does not exist' do
let(:authorization_token) { '123123' }
let(:changelog) { '* made some fixes' }
let(:fake_update_command) { double('fake update command', update: nil) }
let(:new_pull_request) do
{
html_url: "https://path/to/html/pull/request",
issue_url: "https://api/path/to/issue/url",
number: 10,
head: {
ref: "branch_name"
}
}
end
before do
expect(Thegarage::Gitx::Cli::UpdateCommand).to receive(:new).and_return(fake_update_command)

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 log master...feature-branch --reverse --no-merges --pretty=format:'* %s%n%b'").and_return("* old commit\n\n* new commit").ordered
expect(cli).to receive(:ask_editor).with("### Changelog\n* old commit\n\n* new commit\n#{Thegarage::Gitx::Github::PULL_REQUEST_FOOTER}", anything).and_return('description')

stub_request(:post, 'https://api.github.com/repos/thegarage/thegarage-gitx/pulls').to_return(:status => 201, :body => new_pull_request.to_json, :headers => {'Content-Type' => 'application/json'})

VCR.use_cassette('pull_request_does_not_exist') do
cli.review 'feature-branch'
end
end
it 'creates github pull request' do
should meet_expectations
end
it 'runs expected commands' do
should meet_expectations
end
end
context 'when authorization_token is missing' do
let(:authorization_token) { nil }
it do
Expand Down

0 comments on commit 04f7fc4

Please sign in to comment.