Skip to content

Commit

Permalink
Send an email to the requester when the change is merged
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Burrows <rhburrows@gmail.com>
  • Loading branch information
rhburrows committed Apr 29, 2010
1 parent 7561861 commit b8605a6
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 11 deletions.
19 changes: 19 additions & 0 deletions features/reviewer_accepts_changes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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

13 changes: 13 additions & 0 deletions features/step_definitions/reviewr_steps.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions lib/reviewr/cli/accept.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions lib/reviewr/cli/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 0 additions & 11 deletions lib/reviewr/cli/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions lib/reviewr/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/reviewr/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions lib/reviewr/templates/accept_email.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Hi,

I have reviewed your changes for branch <%= project.review_branch %> and decided to
merge them in.

Thanks!
30 changes: 30 additions & 0 deletions spec/reviewr/cli/accept_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions spec/reviewr/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions spec/reviewr/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b8605a6

Please sign in to comment.