git_tracking 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -54,8 +54,15 @@ class GitTracking
54
54
 
55
55
  def post_commit
56
56
  @api_key = config.last_api_key
57
- story = get_story(config.last_story_id)
58
- story.notes.create(:text => config.last_commit_info)
57
+ if config.last_story_completed?
58
+ completed = GitTracking.highline.ask("Does this commit complete the story?", ["yes", "no"]) do |q|
59
+ q.default = "yes"
60
+ end
61
+ if completed == "yes"
62
+ story = get_story(config.last_story_id)
63
+ story.notes.create(:text => config.commits_for_last_story)
64
+ end
65
+ end
59
66
  end
60
67
 
61
68
  def pivotal_project
@@ -28,9 +28,15 @@ class GitTracking
28
28
  @config[:keys].invert[last_api_key]
29
29
  end
30
30
 
31
- def last_commit_info
32
- info = `git log -n 1`.split("\n")
33
- info = "#{info.first}\n#{info.last}"
31
+ def last_story_completed?
32
+ !!`git log -n 1`.match(/complete|finish/i)
33
+ end
34
+
35
+ def commits_for_last_story
36
+ commits = `git log --grep='#{self.last_story_id}'`.split(/^commit /).map{|c| c.split("\n")}
37
+ commits.each do |cl|
38
+ cl.map!(&:strip).reject!{|c| c == "" || c.match(/^\W*$|^Author|^Date|^\[#\d{6,7}\]/) }
39
+ end.flatten.join("\n")
34
40
  end
35
41
 
36
42
  def author
@@ -1,3 +1,3 @@
1
1
  class GitTracking
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -1,4 +1,4 @@
1
- require 'lib/git_tracking'
1
+ require 'git_tracking'
2
2
 
3
3
  describe GitTracking::Config do
4
4
  before(:all) do
@@ -15,7 +15,11 @@ describe GitTracking::Config do
15
15
  system "git config git-tracking.last-story-id '#{@orig_last_story_id}'"
16
16
  end
17
17
 
18
- after(:each) { File.delete(".git_tracking") if File.exists?(".git_tracking") }
18
+ after(:each) do
19
+ File.delete "foo.txt" if File.exists? "foo.txt"
20
+ File.delete ".git_tracking" if File.exists?(".git_tracking")
21
+ end
22
+
19
23
  let(:config) { GitTracking::Config.new }
20
24
 
21
25
  it "#initialize should merge in config from .git_tracking file" do
@@ -91,29 +95,6 @@ describe GitTracking::Config do
91
95
  config.authors.should == ["Joe", "Bob", "Steve"]
92
96
  end
93
97
 
94
- describe "#last_commit_info" do
95
- before(:all) do
96
- File.rename ".git", ".git_old" if File.exists? ".git"
97
- end
98
- before(:each) do
99
- system "git init; git add README; git commit -m 'initial commit'"
100
- end
101
- after(:each) do
102
- File.delete "foo.txt" if File.exists? "foo.txt"
103
- system "rm -rf .git" if File.exists? ".git"
104
- end
105
- after(:all) do
106
- File.rename ".git_old", ".git" if File.exists? ".git_old"
107
- end
108
-
109
- it "should return info about the last commit" do
110
- f = File.new("foo.txt", "w") {|f| f.puts "lalala"}
111
- system "git add foo.txt"
112
- system "git commit -m '[#1235] Story info\n - best commit evar'"
113
- config.last_commit_info.should match(/commit \w{40,40}\n - best commit evar/)
114
- end
115
- end
116
-
117
98
  it "#last_story_id should return the git-tracking.last-story-id from git config" do
118
99
  system "git config git-tracking.last-story-id '736741'"
119
100
  config.last_story_id.should == '736741'
@@ -144,6 +125,50 @@ describe GitTracking::Config do
144
125
  config.last_email.should == "foo@bar.com"
145
126
  end
146
127
 
128
+ context "specs that require messing with git" do
129
+ before(:all) do
130
+ File.rename ".git", ".git_old" if File.exists? ".git"
131
+ end
132
+ after(:all) do
133
+ File.rename ".git_old", ".git" if File.exists? ".git_old"
134
+ end
135
+ before(:each) do
136
+ system "git init; git add README; git commit -m 'initial commit'"
137
+ end
138
+ after(:each) do
139
+ system "rm -rf .git" if File.exists? ".git"
140
+ File.delete "foo.txt" if File.exists? "foo.txt"
141
+ File.delete "bar.txt" if File.exists? "bar.txt"
142
+ end
143
+
144
+ it "#commits_for_last_story should return all commit messages with a given story id" do
145
+ f = File.new("foo.txt", "w") {|f| f.puts "lalala"}
146
+ system "git add foo.txt"
147
+ system "git commit -m '[#1235932] Story info\n - best commit evar'"
148
+ f = File.new("bar.txt", "w") {|f| f.puts "lalala"}
149
+ system "git add bar.txt"
150
+ system "git commit -m '[#1235932] Story info\n - finishing the best feature evar'"
151
+ config.should_receive(:last_story_id).and_return('1235932')
152
+ config.commits_for_last_story.should match(/[0-9a-f]{40}\n- finishing the best feature evar\n[0-9a-f]{40}\n- best commit evar/)
153
+ end
154
+
155
+ describe "#last_story_completed?" do
156
+ it "should return true if the last commit message contains 'completed' or 'finished'" do
157
+ f = File.new("foo.txt", "w") {|f| f.puts "lalala"}
158
+ system "git add foo.txt"
159
+ system "git commit -m '[#1235] Story info\n - Completes best commit evar'"
160
+ config.last_story_completed?.should be_true
161
+ end
162
+
163
+ it "should return false if the last commit message doesn't contain 'completed' or 'finished'" do
164
+ f = File.new("foo.txt", "w") {|f| f.puts "lalala"}
165
+ system "git add foo.txt"
166
+ system "git commit -m '[#1235] Story info\n - best commit evar'"
167
+ config.last_story_completed?.should be_false
168
+ end
169
+ end
170
+ end
171
+
147
172
  describe "#project_id" do
148
173
  it "should return the project_id" do
149
174
  config.instance_eval { @config[:project_id] = '7472' }
@@ -1,4 +1,4 @@
1
- require 'lib/git_tracking'
1
+ require 'git_tracking'
2
2
 
3
3
  describe GitTracking, "detect" do
4
4
  before(:all) do
@@ -44,15 +44,47 @@ STRING
44
44
  end
45
45
  end
46
46
 
47
- it ".post_commit should create a comment on the story with the commit msg and hash" do
48
- story = mock("story")
49
- notes = mock("notes")
50
- GitTracking.stub(:get_story).and_return(story)
51
- GitTracking.should_not_receive(:story_id)
52
- story.should_receive(:notes).and_return(notes)
53
- GitTracking.config.should_receive(:last_commit_info).and_return("984752 [#27491] Best commit evar")
54
- notes.should_receive(:create).with(:text => "984752 [#27491] Best commit evar")
55
- GitTracking.post_commit
47
+ describe ".post_commit" do
48
+ let(:story) {mock("story")}
49
+ let(:notes) {mock("notes")}
50
+ before(:each) do
51
+ GitTracking.config.stub(:last_api_key).and_return("12345")
52
+ GitTracking.stub(:get_story).and_return(story)
53
+ story.stub(:notes).and_return(notes)
54
+ GitTracking.should_not_receive(:story_id) # avoid double-prompting
55
+ end
56
+
57
+ it "should do nothing if the story is not finished" do
58
+ GitTracking.config.should_receive(:last_story_completed?).and_return(false)
59
+ GitTracking.highline.should_not_receive(:ask)
60
+ GitTracking.config.should_not_receive(:commits_for_story)
61
+ notes.should_not_receive(:create)
62
+ GitTracking.post_commit
63
+ end
64
+
65
+ it "should create a comment on the story with the commit msg and hash if the story is finished" do
66
+ commits = <<COMMITS
67
+ commit 12345678
68
+ - Did stuff
69
+ commit 98765456
70
+ - Did more stuff
71
+ commit 97230182
72
+ - Finished stuff
73
+ COMMITS
74
+ GitTracking.config.should_receive(:last_story_completed?).and_return(true)
75
+ GitTracking.highline.should_receive(:ask).with("Does this commit complete the story?", ["yes", "no"]).and_return("yes")
76
+ GitTracking.config.should_receive(:commits_for_last_story).and_return(commits)
77
+ notes.should_receive(:create).with(:text => commits)
78
+ GitTracking.post_commit
79
+ end
80
+
81
+ it "should allow the user to indicate the story was not finished" do
82
+ GitTracking.config.should_receive(:last_story_completed?).and_return(true)
83
+ GitTracking.highline.should_receive(:ask).with("Does this commit complete the story?", ["yes", "no"]).and_return("no")
84
+ GitTracking.config.should_not_receive(:commits_for_last_story)
85
+ notes.should_not_receive(:create)
86
+ GitTracking.post_commit
87
+ end
56
88
  end
57
89
 
58
90
  describe ".story" do
@@ -145,6 +177,7 @@ STRING
145
177
  it "should get the token" do
146
178
  project = mock("project")
147
179
  PivotalTracker::Project.should_receive(:find).and_return(project)
180
+ GitTracking.should_receive(:project_id).and_return("87655")
148
181
  GitTracking.should_receive(:api_key).and_return("alksjd9123lka")
149
182
  GitTracking.pivotal_project.should == project
150
183
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Steve Hull
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-08 00:00:00 -08:00
18
+ date: 2010-11-17 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency