Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Send an email to the requester when the change is merged

Signed-off-by: Ryan Burrows <rhburrows@gmail.com>
  • Loading branch information...
commit b8605a6f310d0a3ecc390234cc4321c6f12aa45f 1 parent 7561861
@rhburrows authored
View
19 features/reviewer_accepts_changes.feature
@@ -36,3 +36,22 @@ Feature: Code Reviewer accepts changes
And I am on branch "master"
When I run "reviewr accept review_12345678"
Then reviewr should delete origin branch "review_12345678"
+
+ Scenario: Reviewr sends an email saying the branch has been merged
+ Given remote branch "review_12345678" will apply cleanly
+ And the review was requested by "coder@site.com"
+ And my git email is "reviewer@site.com"
+ When I run "reviewr accept review_12345678"
+ Then reviewr should send an email to "coder@site.com" with body:
+ """
+ Hi,
+
+ I have reviewed your changes for branch review_12345678 and decided to
+ merge them in.
+
+ Thanks!
+
+ """
+
+ Scenario: Reviewr deletes the local working copy of the review branch
+
View
13 features/step_definitions/reviewr_steps.rb
@@ -1,3 +1,16 @@
+Given /^the review was requested by "([^\"]*)"$/ do |email|
+ mock_git('git log -n 1',
+ [ "commit 1234567891234567823467",
+ "Author: Cody McCoder",
+ "Date: Tue Apr 27 22:35:55 2010 -0700",
+ "",
+ "Code Review Request",
+ "===================",
+ "requested_by: coder@site.com",
+ "requested_from: reviewer@site.com"
+ ].join("\n"))
+end
+
When /^I run "reviewr ([^\"]*)"$/ do |opts|
reviewr(opts.split(' ')).run
end
View
9 lib/reviewr/cli/accept.rb
@@ -13,12 +13,21 @@ def execute
unless project.rebase_review
output.print "Branch '#{arguments.first}' won't merge cleanly"
else
+ # This must be run while on the review branch
+ project.to = project.requester_email
+
project.change_branch(merge_branch)
project.merge_commits
project.push_branch(merge_branch)
project.delete_remote_review_branch
+
+ Mailer.new(project).send(email_body)
end
end
+
+ def email_body
+ read_template('accept_email.erb')
+ end
end
end
end
View
9 lib/reviewr/cli/command.rb
@@ -29,6 +29,15 @@ def prompt_for_user
project.remote_repo = repo unless repo.empty?
end
+ def read_template(name)
+ @templates ||= {}
+ @templates[name] ||= ERB.new(File.read(File.join(File.dirname(__FILE__),
+ '..',
+ 'templates',
+ name)))
+ @templates[name].result(binding)
+ end
+
private
def no_echo(input)
View
11 lib/reviewr/cli/request.rb
@@ -27,17 +27,6 @@ def commit_msg
def email_body
read_template('request_email.erb')
end
-
- private
-
- def read_template(name)
- @templates ||= {}
- @templates[name] ||= ERB.new(File.read(File.join(File.dirname(__FILE__),
- '..',
- 'templates',
- name)))
- @templates[name].result(binding)
- end
end
end
end
View
4 lib/reviewr/git.rb
@@ -77,6 +77,10 @@ def cherry_pick(commit)
execute("git cherry-pick #{commit}")
end
+ def log(n)
+ execute("git log -n #{n}")
+ end
+
def execute(cmd)
`#{cmd}`
end
View
8 lib/reviewr/project.rb
@@ -68,5 +68,13 @@ def merge_commits
def delete_remote_review_branch
git.push_branch(":#{review_branch}")
end
+
+ def requester_email
+ msg = git.log(1)
+ if msg
+ m = msg.match(/^requested_by: ([^\s]+)/)
+ m && m[1]
+ end
+ end
end
end
View
6 lib/reviewr/templates/accept_email.erb
@@ -0,0 +1,6 @@
+Hi,
+
+I have reviewed your changes for branch <%= project.review_branch %> and decided to
+merge them in.
+
+Thanks!
View
30 spec/reviewr/cli/accept_spec.rb
@@ -5,9 +5,11 @@ module CLI
describe Accept do
let(:project){ double("Project").as_null_object }
let(:accept){ Accept.new(project) }
+ let(:mailer){ double("Mailer").as_null_object }
describe "#call" do
before do
+ Mailer.stub(:new).and_return(mailer)
accept.stub(:prompt_for_user)
accept.arguments = []
accept.output = double("Output").as_null_object
@@ -71,6 +73,34 @@ module CLI
project.should_receive(:delete_remote_review_branch)
accept.call
end
+
+ it "sets the to address to the review requester's" do
+ project.stub(:requester_email).and_return("coder@site.com")
+ project.should_receive(:to=).with("coder@site.com")
+ accept.call
+ end
+
+ it "sends an email to the review requester" do
+ accept.stub(:email_body).and_return("email")
+ mailer.should_receive(:send).with("email")
+ accept.call
+ end
+ end
+ end
+
+ describe "#email_body" do
+ THE_BODY= <<-END
+Hi,
+
+I have reviewed your changes for branch review_12345678 and decided to
+merge them in.
+
+Thanks!
+ END
+
+ it "generates the email body based on the project" do
+ project.stub(:review_branch).and_return("review_12345678")
+ accept.email_body.should == THE_BODY
end
end
end
View
7 spec/reviewr/git_spec.rb
@@ -146,5 +146,12 @@ module Reviewr
git.cherry_pick('commit')
end
end
+
+ describe "#log" do
+ it "calls log with n = the number passed" do
+ git.should_receive(:execute).with('git log -n 1')
+ git.log(1)
+ end
+ end
end
end
View
20 spec/reviewr/project_spec.rb
@@ -119,5 +119,25 @@ module Reviewr
project.delete_remote_review_branch
end
end
+
+ describe "#requester_email" do
+ it "reads the last commit message from git" do
+ git.should_receive(:log).with(1)
+ project.requester_email
+ end
+
+ it "parses out the requester email and returns it" do
+ git.stub(:log).and_return([ "commit 1234567891234567823467",
+ "Author: Cody McCoder",
+ "Date: Tue Apr 27 22:35:55 2010 -0700",
+ "",
+ "Code Review Request",
+ "===================",
+ "requested_by: coder@site.com",
+ "requested_from: reviewer@site.com"
+ ].join("\n"))
+ project.requester_email.should == "coder@site.com"
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.