git-commit-notifier 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/LICENSE +1 -1
  2. data/README.textile +20 -5
  3. data/Rakefile +40 -20
  4. data/VERSION +1 -1
  5. data/bin/git-commit-notifier +8 -1
  6. data/config/git-notifier-config.yml.sample +41 -15
  7. data/git-commit-notifier.gemspec +50 -24
  8. data/lib/commit_hook.rb +104 -74
  9. data/lib/diff_to_html.rb +120 -52
  10. data/lib/emailer.rb +43 -22
  11. data/lib/git.rb +36 -26
  12. data/lib/logger.rb +48 -0
  13. data/lib/result_processor.rb +9 -5
  14. data/{test → spec}/fixtures/existing_file_one_line.txt +0 -0
  15. data/{test → spec}/fixtures/git-notifier-group-email-by-push.yml +2 -0
  16. data/{test → spec}/fixtures/git-notifier-ignore-merge.yml +0 -0
  17. data/{test → spec}/fixtures/git-notifier-with-merge.yml +0 -0
  18. data/{test → spec}/fixtures/git_log +0 -0
  19. data/{test → spec}/fixtures/git_show_055850e7d925110322b8db4e17c3b840d76e144c +0 -0
  20. data/{test → spec}/fixtures/git_show_51b986619d88f7ba98be7d271188785cbbb541a0 +0 -0
  21. data/{test → spec}/fixtures/git_show_a4629e707d80a5769f7a71ca6ed9471015e14dc9 +0 -0
  22. data/{test → spec}/fixtures/git_show_dce6ade4cdc2833b53bd600ef10f9bce83c7102d +0 -0
  23. data/{test → spec}/fixtures/git_show_e28ad77bba0574241e6eb64dfd0c1291b221effe +0 -0
  24. data/spec/fixtures/git_show_ff037a73fc1094455e7bbf506171a3f3cf873ae6 +18 -0
  25. data/{test → spec}/fixtures/new_file_one_line.txt +0 -0
  26. data/spec/lib/commit_hook_spec.rb +88 -0
  27. data/spec/lib/diff_to_html_spec.rb +168 -0
  28. data/spec/lib/emailer_spec.rb +102 -0
  29. data/spec/lib/git_spec.rb +93 -0
  30. data/spec/lib/logger_spec.rb +63 -0
  31. data/spec/lib/result_processor_spec.rb +102 -0
  32. data/{test/test_helper.rb → spec/spec_helper.rb} +14 -12
  33. data/template/email.html.erb +2 -2
  34. data/template/styles.css +2 -1
  35. metadata +110 -31
  36. data/test/unit/test_commit_hook.rb +0 -43
  37. data/test/unit/test_diff_to_html.rb +0 -160
  38. data/test/unit/test_result_processor.rb +0 -95
@@ -0,0 +1,93 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+ require 'git'
3
+
4
+ describe Git do
5
+ SAMPLE_REV = '51b986619d88f7ba98be7d271188785cbbb541a0'.freeze
6
+ SAMPLE_REV_2 = '62b986619d88f7ba98be7d271188785cbbb541b1'.freeze
7
+
8
+ describe :from_shell do
9
+ it "should be backtick" do
10
+ Git.from_shell('pwd').should == `pwd`
11
+ end
12
+ end
13
+
14
+ describe :show do
15
+ it "should get data from shell: git show" do
16
+ expected = 'some data from git show'
17
+ mock(Git).from_shell("git show #{SAMPLE_REV} -w") { expected }
18
+ Git.show(SAMPLE_REV).should == expected
19
+ end
20
+
21
+ it "should strip given revision" do
22
+ mock(Git).from_shell("git show #{SAMPLE_REV} -w")
23
+ Git.show("#{SAMPLE_REV}\n")
24
+ end
25
+ end
26
+
27
+ describe :branch_heads do
28
+ before(:each) do
29
+ mock(Git).from_shell("git rev-parse --branches") { "some\npopular\ntext\n" }
30
+ end
31
+
32
+ it "should get branch heads from shell" do
33
+ lambda { Git.branch_heads }.should_not raise_error
34
+ end
35
+
36
+ it "should return array of lines" do
37
+ Git.branch_heads.should == %w[ some popular text ]
38
+ end
39
+ end
40
+
41
+
42
+ describe :repo_name do
43
+ # this spec written because I replaced `pwd` with Dir.pwd
44
+ it "Dir.pwd should be same as `pwd`.chomp" do
45
+ Dir.pwd.should == `pwd`.chomp
46
+ end
47
+
48
+ it "should return hooks.emailprefix if it's not empty" do
49
+ expected = "name of repo"
50
+ mock(Git).from_shell("git config hooks.emailprefix") { expected }
51
+ dont_allow(Dir).pwd
52
+ Git.repo_name.should == expected
53
+ end
54
+
55
+ it "should return folder name if no emailprefix and directory not ended with .git" do
56
+ mock(Git).from_shell("git config hooks.emailprefix") { " " }
57
+ mock(Dir).pwd { "/home/someuser/repositories/myrepo" }
58
+ Git.repo_name.should == "myrepo"
59
+ end
60
+
61
+ it "should return folder name without extension if no emailprefix and directory ended with .git" do
62
+ mock(Git).from_shell("git config hooks.emailprefix") { " " }
63
+ mock(Dir).pwd { "/home/someuser/repositories/myrepo.git" }
64
+ Git.repo_name.should == "myrepo"
65
+ end
66
+ end
67
+
68
+ describe :log do
69
+ it "should run git log with given args" do
70
+ mock(Git).from_shell("git log #{SAMPLE_REV}..#{SAMPLE_REV_2}") { " ok " }
71
+ Git.log(SAMPLE_REV, SAMPLE_REV_2).should == "ok"
72
+ end
73
+ end
74
+
75
+ describe :branch_head do
76
+ it "should run git rev-parse with given treeish" do
77
+ mock(Git).from_shell("git rev-parse #{SAMPLE_REV}") { " ok " }
78
+ Git.branch_head(SAMPLE_REV).should == "ok"
79
+ end
80
+ end
81
+
82
+ describe :mailing_list_address do
83
+ it "should run git config hooks.mailinglist" do
84
+ mock(Git).from_shell("git config hooks.mailinglist") { " ok " }
85
+ Git.mailing_list_address.should == "ok"
86
+ end
87
+ end
88
+
89
+ end
90
+
91
+ __END__
92
+
93
+ vim: tabstop=2 expandtab shiftwidth=2
@@ -0,0 +1,63 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+ require 'logger'
3
+
4
+ describe Logger do
5
+
6
+ describe :debug? do
7
+ it "should be false unless debug section exists" do
8
+ logger = Logger.new({})
9
+ logger.should_not be_debug
10
+ end
11
+
12
+ it "should be false unless debug/enabled" do
13
+ logger = Logger.new("debug" => { "enabled" => false })
14
+ logger.should_not be_debug
15
+ end
16
+
17
+ it "should be true if debug/enabled" do
18
+ logger = Logger.new("debug" => { "enabled" => true })
19
+ logger.should be_debug
20
+ end
21
+ end
22
+
23
+ describe :log_directory do
24
+ it "should be nil unless debug?" do
25
+ logger = Logger.new({})
26
+ logger.should_not be_debug
27
+ logger.log_directory.should be_nil
28
+ end
29
+
30
+ it "should be custom if debug and custom directory specified" do
31
+ expected = Faker::Lorem.sentence
32
+ logger = Logger.new("debug" => { "enabled" => true, "log_directory" => expected})
33
+ logger.log_directory.should == expected
34
+ end
35
+
36
+ it "should be default log directory if debug and custom directory not specified" do
37
+ logger = Logger.new("debug" => { "enabled" => true })
38
+ logger.log_directory.should == Logger::DEFAULT_LOG_DIRECTORY
39
+ end
40
+ end
41
+
42
+ describe :log_path do
43
+ it "should be nil unless debug?" do
44
+ logger = Logger.new({})
45
+ mock(logger).debug? { false }
46
+ logger.log_path.should be_nil
47
+ end
48
+
49
+ it "should be path in log_directory if debug?" do
50
+ logger = Logger.new("debug" => { "enabled" => true })
51
+ File.dirname(logger.log_path).should == logger.log_directory
52
+ end
53
+
54
+ it "should points to LOG_NAME if debug?" do
55
+ logger = Logger.new("debug" => { "enabled" => true })
56
+ File.basename(logger.log_path).should == Logger::LOG_NAME
57
+ end
58
+ end
59
+ end
60
+
61
+ __END__
62
+
63
+ vim: tabstop=2 expandtab shiftwidth=2
@@ -0,0 +1,102 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../spec_helper', __FILE__)
4
+ require 'diff_to_html'
5
+
6
+ describe ResultProcessor do
7
+ before(:all) do
8
+ create_test_input
9
+ end
10
+
11
+ it :processor do
12
+ processor = ResultProcessor.new(@diff)
13
+ removal, addition = processor.results
14
+ removal.should have(1).line
15
+
16
+ removal.first.should be_include('&nbsp;&nbsp;<span class="rr">b</span>')
17
+ removal.first.should be_include('<span class="rr">ton</span>')
18
+ removal.first.split('<span>').should have(1).span # one occurrence (beginning of string)
19
+
20
+ addition.should have(1).line
21
+ addition.first.should be_include('&nbsp;&nbsp;<span class="aa">s</span>')
22
+ addition.first.should be_include('<span class="aa">bmi</span>')
23
+ addition.first.split('<span>').should have(1).span # one occurrence (beginning of string)
24
+ end
25
+
26
+ it "processor with almost no common part" do
27
+ @diff = [
28
+ { :action => :match, :token => ' ' },
29
+ { :action => :match, :token => ' ' },
30
+ { :action => :discard_a, :token => 'button' },
31
+ { :action => :discard_b, :token => 'submit' },
32
+ { :action => :match, :token => 'x' }
33
+ ]
34
+
35
+ processor = ResultProcessor.new(@diff)
36
+ removal, addition = processor.results
37
+
38
+ removal.should have(1).line
39
+ removal.first.should == '&nbsp;&nbsp;buttonx' # no highlight
40
+
41
+ addition.should have(1).line
42
+ addition.first.should == '&nbsp;&nbsp;submitx' # no highlight
43
+ end
44
+
45
+ it "close span tag when having difference at the end" do
46
+ diff = []
47
+ s1 = " submit_to_remote 'create_btn', 'Create', :url => { :action => 'cre"
48
+ s2 = " submit_to_remote 'create_btn', 'Create', :url => { :action => 'sub"
49
+
50
+ s1[0..s1.size-6].each_char do |c|
51
+ diff << { :action => :match, :token => c}
52
+ end
53
+ diff << { :action => :discard_a, :token => 'c' }
54
+ diff << { :action => :discard_a, :token => 'r' }
55
+ diff << { :action => :discard_a, :token => 'e' }
56
+ diff << { :action => :discard_b, :token => 's' }
57
+ diff << { :action => :discard_b, :token => 'u' }
58
+ diff << { :action => :discard_b, :token => 'b' }
59
+
60
+ processor = ResultProcessor.new(diff)
61
+ removal, addition = processor.results
62
+
63
+ removal.should have(1).line
64
+ removal.first.should be_include('action&nbsp;=&gt;<span class="rr">cre</span>')
65
+
66
+ addition.should have(1).line
67
+ addition.first.should be_include('action&nbsp;=&gt;<span class="aa">sub</span>')
68
+ end
69
+
70
+ def create_test_input
71
+ s1 = " button_to_remote 'create_btn', 'Create', :url => { :action => 'create' }"
72
+ s2 = " submit_to_remote 'create_btn', 'Create', :url => { :action => 'create' }"
73
+
74
+ @diff = [
75
+ [ :match, ' ' ],
76
+ [ :match, ' ' ],
77
+ [ :discard_a, 'b' ],
78
+ [ :discard_b, 's' ],
79
+ [ :match, 'u' ],
80
+ [ :discard_b, 'b' ],
81
+ [ :discard_b, 'm' ],
82
+ [ :discard_b, 'i' ],
83
+ [ :match, 't' ],
84
+ [ :discard_a, 't' ],
85
+ [ :discard_a, 'o' ],
86
+ [ :discard_a, 'n' ]
87
+ ]
88
+ @diff = @diff.collect { |d| { :action => d.first, :token => d.last}}
89
+
90
+ s1[@diff.size..-1].each_char do |c|
91
+ @diff << { :action => :match, :token => c }
92
+ end
93
+ end
94
+
95
+ describe :length_in_chars do
96
+ it "should be unicode friendly" do
97
+ processor = ResultProcessor.new(@diff)
98
+ processor.length_in_chars([{ :token => 'японская мама' }]).should == 13
99
+ end
100
+ end
101
+ end
102
+
@@ -1,4 +1,16 @@
1
- require 'test/unit'
1
+ if RUBY_VERSION < '1.9'
2
+ # This is for Unicode support in Ruby 1.8
3
+ $KCODE = 'u';
4
+ require 'jcode'
5
+ end
6
+
7
+ require 'rubygems'
8
+ require 'faker'
9
+ require 'rspec/core'
10
+
11
+ RSpec.configure do |conf|
12
+ conf.mock_with :rr
13
+ end
2
14
 
3
15
  unless defined? REVISIONS
4
16
  REVISIONS = ['e28ad77bba0574241e6eb64dfd0c1291b221effe', # 2 files updated
@@ -7,16 +19,6 @@ unless defined? REVISIONS
7
19
  '51b986619d88f7ba98be7d271188785cbbb541a0', # 3 files updated
8
20
  '055850e7d925110322b8db4e17c3b840d76e144c'] # Empty merge message
9
21
 
22
+ FIXTURES_PATH = (File.dirname(__FILE__) + '/fixtures/').freeze
10
23
  end
11
24
 
12
- class Test::Unit::TestCase
13
-
14
- def read_file(name)
15
- out = ''
16
- File.open(name).each { |line|
17
- out += line
18
- }
19
- out
20
- end
21
-
22
- end
@@ -1,9 +1,9 @@
1
1
  <html><head>
2
- <style>
2
+ <style type="text/css">
3
3
  <%= stylesheet_string %>
4
4
  </style>
5
5
  </head>
6
6
  <body>
7
- <%= html_diff %>
7
+ <%= @html_message %>
8
8
  </body>
9
9
  </html>
data/template/styles.css CHANGED
@@ -6,5 +6,6 @@ table {width:100%;border-collapse:collapse}
6
6
  .a {background-color: #dfd;}
7
7
  .aa {background-color: #afa;}
8
8
  .title {background-color: #ddd; padding: 10px;font-family:Verdana;font-size:12px;}
9
- tr {color:#000;font-family: "Bitstream Vera Sans Mono","Monaco","Courier",monospace}
9
+ td {color:#000;font-family: "Bitstream Vera Sans Mono","Monaco","Courier",monospace}
10
10
  .ln {background-color: #ccc; width:23px; text-align:right}
11
+ td.sep {text-align:center;border-top:1px solid DimGray;border-bottom:1px solid DimGray;}
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-commit-notifier
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 8
9
- - 0
10
- version: 0.8.0
8
+ - 1
9
+ version: 0.8.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Bodo Tasche
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-08-06 00:00:00 +02:00
17
+ date: 2010-11-03 00:00:00 +01:00
19
18
  default_executable: git-commit-notifier
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
@@ -40,7 +38,6 @@ dependencies:
40
38
  requirements:
41
39
  - - ">="
42
40
  - !ruby/object:Gem::Version
43
- hash: 3
44
41
  segments:
45
42
  - 0
46
43
  version: "0"
@@ -54,7 +51,6 @@ dependencies:
54
51
  requirements:
55
52
  - - ">="
56
53
  - !ruby/object:Gem::Version
57
- hash: 3
58
54
  segments:
59
55
  - 0
60
56
  version: "0"
@@ -68,14 +64,91 @@ dependencies:
68
64
  requirements:
69
65
  - - ">="
70
66
  - !ruby/object:Gem::Version
71
- hash: 3
72
67
  segments:
73
68
  - 0
74
69
  version: "0"
75
70
  type: :runtime
76
71
  version_requirements: *id004
72
+ - !ruby/object:Gem::Dependency
73
+ name: rspec-core
74
+ prerelease: false
75
+ requirement: &id005 !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ type: :development
84
+ version_requirements: *id005
85
+ - !ruby/object:Gem::Dependency
86
+ name: rspec-expectations
87
+ prerelease: false
88
+ requirement: &id006 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ type: :development
97
+ version_requirements: *id006
98
+ - !ruby/object:Gem::Dependency
99
+ name: rr
100
+ prerelease: false
101
+ requirement: &id007 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ type: :development
110
+ version_requirements: *id007
111
+ - !ruby/object:Gem::Dependency
112
+ name: faker
113
+ prerelease: false
114
+ requirement: &id008 !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ type: :development
123
+ version_requirements: *id008
124
+ - !ruby/object:Gem::Dependency
125
+ name: rcov
126
+ prerelease: false
127
+ requirement: &id009 !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ type: :development
136
+ version_requirements: *id009
137
+ - !ruby/object:Gem::Dependency
138
+ name: metric_fu
139
+ prerelease: false
140
+ requirement: &id010 !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ segments:
146
+ - 0
147
+ version: "0"
148
+ type: :development
149
+ version_requirements: *id010
77
150
  description: This git commit notifier sends html mails with nice diffs for every changed file.
78
- email: bodo@wannawork.de
151
+ email: bodo@bitboxer.de
79
152
  executables:
80
153
  - git-commit-notifier
81
154
  extensions: []
@@ -97,26 +170,31 @@ files:
97
170
  - lib/diff_to_html.rb
98
171
  - lib/emailer.rb
99
172
  - lib/git.rb
173
+ - lib/logger.rb
100
174
  - lib/result_processor.rb
175
+ - spec/fixtures/existing_file_one_line.txt
176
+ - spec/fixtures/git-notifier-group-email-by-push.yml
177
+ - spec/fixtures/git-notifier-ignore-merge.yml
178
+ - spec/fixtures/git-notifier-with-merge.yml
179
+ - spec/fixtures/git_log
180
+ - spec/fixtures/git_show_055850e7d925110322b8db4e17c3b840d76e144c
181
+ - spec/fixtures/git_show_51b986619d88f7ba98be7d271188785cbbb541a0
182
+ - spec/fixtures/git_show_a4629e707d80a5769f7a71ca6ed9471015e14dc9
183
+ - spec/fixtures/git_show_dce6ade4cdc2833b53bd600ef10f9bce83c7102d
184
+ - spec/fixtures/git_show_e28ad77bba0574241e6eb64dfd0c1291b221effe
185
+ - spec/fixtures/git_show_ff037a73fc1094455e7bbf506171a3f3cf873ae6
186
+ - spec/fixtures/new_file_one_line.txt
187
+ - spec/lib/commit_hook_spec.rb
188
+ - spec/lib/diff_to_html_spec.rb
189
+ - spec/lib/emailer_spec.rb
190
+ - spec/lib/git_spec.rb
191
+ - spec/lib/logger_spec.rb
192
+ - spec/lib/result_processor_spec.rb
193
+ - spec/spec_helper.rb
101
194
  - template/email.html.erb
102
195
  - template/styles.css
103
- - test/fixtures/existing_file_one_line.txt
104
- - test/fixtures/git-notifier-group-email-by-push.yml
105
- - test/fixtures/git-notifier-ignore-merge.yml
106
- - test/fixtures/git-notifier-with-merge.yml
107
- - test/fixtures/git_log
108
- - test/fixtures/git_show_055850e7d925110322b8db4e17c3b840d76e144c
109
- - test/fixtures/git_show_51b986619d88f7ba98be7d271188785cbbb541a0
110
- - test/fixtures/git_show_a4629e707d80a5769f7a71ca6ed9471015e14dc9
111
- - test/fixtures/git_show_dce6ade4cdc2833b53bd600ef10f9bce83c7102d
112
- - test/fixtures/git_show_e28ad77bba0574241e6eb64dfd0c1291b221effe
113
- - test/fixtures/new_file_one_line.txt
114
- - test/test_helper.rb
115
- - test/unit/test_commit_hook.rb
116
- - test/unit/test_diff_to_html.rb
117
- - test/unit/test_result_processor.rb
118
196
  has_rdoc: true
119
- homepage: http://github.com/bodo/git-commit-notifier
197
+ homepage: http://github.com/bitboxer/git-commit-notifier
120
198
  licenses: []
121
199
 
122
200
  post_install_message:
@@ -129,7 +207,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
207
  requirements:
130
208
  - - ">="
131
209
  - !ruby/object:Gem::Version
132
- hash: 3
133
210
  segments:
134
211
  - 0
135
212
  version: "0"
@@ -138,7 +215,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
215
  requirements:
139
216
  - - ">="
140
217
  - !ruby/object:Gem::Version
141
- hash: 3
142
218
  segments:
143
219
  - 0
144
220
  version: "0"
@@ -150,7 +226,10 @@ signing_key:
150
226
  specification_version: 3
151
227
  summary: Sends git commit messages with diffs
152
228
  test_files:
153
- - test/test_helper.rb
154
- - test/unit/test_commit_hook.rb
155
- - test/unit/test_diff_to_html.rb
156
- - test/unit/test_result_processor.rb
229
+ - spec/lib/commit_hook_spec.rb
230
+ - spec/lib/diff_to_html_spec.rb
231
+ - spec/lib/emailer_spec.rb
232
+ - spec/lib/git_spec.rb
233
+ - spec/lib/logger_spec.rb
234
+ - spec/lib/result_processor_spec.rb
235
+ - spec/spec_helper.rb