Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new functionality for review #99

Merged
merged 15 commits into from
May 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,35 @@ We assume you know what you're doing, so if you need something different, do it

After making commits to your branch, run +review+. Didn't push it up? We don't care, we'll do it for you.

$ git reflow review
If you do not pass the title or message options to the review command, you will be given an editor to write your PR request in, similar to `git commit`. The first line is the title, the rest is the body.

From github.com:reenhanced/gitreflow
$ git reflow review

Review your PR:
--------
Title:
rj_209_test

Body:
[lib] updates review command to address issues
--------
Submit pull request? (Y): <enter>
git fetch origin master
From github.com:meesterdude/gitreflow
* branch master -> FETCH_HEAD
Counting objects: 5, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 1.68 KiB, done.
Total 3 (delta 1), reused 0 (delta 0)
To [email protected]:reenhanced/gitreflow.git
c2ec1b1..1103006 nh-readme-update -> nh-readme-update

Successfully created pull request #35: Bootstrapping the readme. This is so I can show how review works
Pull Request URL: https://github.com/reenhanced/gitreflow/pull/35
git push origin rj_test
Everything up-to-date

Successfully created pull request #6: rj_test
Pull Request URL: https://github.com/meesterdude/gitreflow/pull/6
Would you like to open it in your browser? y


[OSX/Ubuntu only] You can automatically open your default web browser to the pull request.
This lets you edit the pull request with all of the detailed information you'll need before submitting it to your team.

We output the pull request URL so you can distribute it to your team without leaving the terminal. But don't be a jerk, update the title and description before you send your work around.
We output the pull request URL so you can distribute it to your team without leaving the terminal.

==== How it works
Behind the scenes, this is how +review+ works:
Expand Down
35 changes: 27 additions & 8 deletions lib/git_reflow/commands/review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,34 @@
c.flag [:t, :title], default_value: 'last commit message'
c.flag [:m, :message], default_value: 'title'
c.action do |global_options,options,args|
review_options = {
'base' => args[0],
'title' => global_options[:title],
'body' => global_options[:message]
}
git_root_dir = run('git rev-parse --show-toplevel').strip
pull_request_msg_file = "#{git_root_dir}/.git/GIT_REFLOW_PR_MSG"

review_options['title'] ||= GitReflow.get_first_commit_message
review_options['body'] ||= review_options['title']
if global_options[:title] || global_options[:message]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since (global_options[:title] || global_options[:message]) == (editor = false), let's just assign this above into a variable: use_editor = ("#{(global_options[:title] || global_options[:message])}".length == 0), then this becomes unless use_editor and we can eliminate the other assignments of editor below

review_options = {
'base' => args[0],
'title' => (global_options[:title] || GitReflow.current_branch),
'body' => global_options[:message]
}
else
File.open(pull_request_msg_file, 'w') do |file|
file.write(GitReflow.current_branch)
end
GitReflow.run("$EDITOR #{pull_request_msg_file}", with_system: true)
pr_msg = File.open(pull_request_msg_file).each_line.map(&:strip).to_a
File.delete(pull_request_msg_file)
title = pr_msg.shift
unless pr_msg.empty?
pr_msg.shift if pr_msg.first.empty?
end
review_options = {'base' => args[0],'title' => title,'body' => pr_msg.join("\n")}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove surrounding blank lines from the pr_msg I just imagine many users adding an extra return between the title and body. so 'body' => pr_msg.reject(&:empty?).join("\n")

end

GitReflow.review review_options
puts "\nReview your PR:\n"
puts "--------\n"
puts "Title:\n#{review_options['title']}\n\n"
puts "Body:\n#{review_options['body']}\n"
puts "--------\n"
GitReflow.review(review_options) unless ask("Submit pull request? (Y)") =~ /n/i
end
end
2 changes: 1 addition & 1 deletion lib/git_reflow/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module GitReflow
VERSION = "0.5.3"
VERSION = "0.6.0"
end