Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
Account for PT status change in the special syntax
Browse files Browse the repository at this point in the history
which includes things like "Fixes", "Deliver", etc.
[#26437519]
  • Loading branch information
stevenharman committed Mar 20, 2012
1 parent 505d49c commit 7eac6a3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/git_tracker/commit_message.rb
Expand Up @@ -5,9 +5,9 @@ def initialize(file)
@file = file
end

def contains?(pattern)
def mentions_story?(number)
message = File.read(@file)
message.include?(pattern)
message =~ %r{\[\w*\s?##{number}]}
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/git_tracker/prepare_commit_message.rb
Expand Up @@ -19,7 +19,7 @@ def run
story = story_number_from_branch

message = CommitMessage.new(file)
exit if message.contains?("[##{story}]")
exit if message.mentions_story?(story)
message.append!("[##{story}]")
end

Expand Down
13 changes: 9 additions & 4 deletions spec/git_tracker/commit_message_spec.rb
Expand Up @@ -8,7 +8,7 @@
-> { GitTracker::CommitMessage.new }.should raise_error ArgumentError
end

describe "#contains?" do
describe "#mentions_story?" do
subject { described_class.new(file) }
let(:file) { "COMMIT_EDITMSG" }
before do
Expand All @@ -17,12 +17,17 @@

context "commit message contains the special Pivotal Tracker story syntax" do
let(:commit_message_text) { example_commit_message("[#8675309]") }
it { subject.should be_contains("[#8675309]") }
it { subject.should be_mentions_story("8675309") }

context "with state change" do
let(:commit_message_text) { example_commit_message("[Fixes #8675309]") }
it { subject.should be_mentions_story("8675309") }
end
end

context "commit message doesn't contain the special Pivotal Tracker story syntax" do
let(:commit_message_text) { example_commit_message("[#not_it]") }
it { subject.should_not be_contains("[#8675309]") }
let(:commit_message_text) { example_commit_message("#8675309") }
it { subject.should_not be_mentions_story("8675309") }
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/git_tracker/prepare_commit_message_spec.rb
Expand Up @@ -46,7 +46,7 @@

context "branch name with a Pivotal Tracker story number" do
let(:story) { "8675309" }
let(:commit_message) { stub("CommitMessage", contains?: false) }
let(:commit_message) { stub("CommitMessage", mentions_story?: false) }
before do
GitTracker::CommitMessage.stub(:new) { commit_message }
end
Expand All @@ -58,7 +58,7 @@

context "number already mentioned in the commit message" do
before do
commit_message.stub(:contains?).with("[#8675309]") { true }
commit_message.stub(:mentions_story?).with("8675309") { true }
end

it "exits without updating the commit message" do
Expand Down

0 comments on commit 7eac6a3

Please sign in to comment.