git-commit-notifier 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -9,14 +9,14 @@ as the author, project and branch name.
9
9
 
10
10
  For example:
11
11
 
12
- <pre>[rails][master] Fix Brasilia timezone. [#1180 state:resolved] </pre>
12
+ <pre>[rails][branch] Fix Brasilia timezone. [#1180 state:resolved] </pre>
13
13
 
14
14
  A reply-to header is added containing the author of the commit. This makes
15
15
  follow up really simple. If multiple commits are pushed at once, emails are
16
16
  numbered in chronological order:
17
17
 
18
- <pre> [rails][master][000] Added deprecated warning messages to Float#months and Float#years deprications.
19
- [rails][master][001] Enhance testing for fractional days and weeks. Update changelog.</pre>
18
+ <pre> [rails][branch][000] Added deprecated warning messages to Float#months and Float#years deprications.
19
+ [rails][branch][001] Enhance testing for fractional days and weeks. Update changelog.</pre>
20
20
 
21
21
  Example email:
22
22
 
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ begin
13
13
  gem.add_dependency('diff-lcs')
14
14
  gem.add_dependency('mocha')
15
15
  gem.add_dependency('hpricot')
16
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ gem.add_dependency('tamtam')
17
17
  end
18
18
  Jeweler::GemcutterTasks.new
19
19
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -1,12 +1,14 @@
1
1
  delivery_method: sendmail # smtp or sendmail
2
+ ignore_merge: false # set to true if you want to ignore empty merge messages
2
3
 
3
4
  smtp_server:
4
5
  address: localhost
5
6
  port: 25
6
7
  domain: localhost
7
- user_name:
8
- password:
9
- authentication:
8
+ user_name: user@localhost
9
+ password: password
10
+ authentication: plain
11
+ enable_tls: false
10
12
 
11
13
  sendmail_options:
12
14
  location: /usr/sbin/sendmail
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{git-commit-notifier}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bodo Tasche"]
12
- s.date = %q{2010-03-24}
12
+ s.date = %q{2010-03-25}
13
13
  s.default_executable = %q{git-commit-notifier}
14
14
  s.description = %q{This git commit notifier sends html mails with nice diffs for every changed file.}
15
15
  s.email = %q{bodo@wannawork.de}
@@ -35,7 +35,10 @@ Gem::Specification.new do |s|
35
35
  "lib/result_processor.rb",
36
36
  "template/email.html.erb",
37
37
  "template/styles.css",
38
+ "test/fixtures/git-notifier-ignore-merge.yml",
39
+ "test/fixtures/git-notifier-with-merge.yml",
38
40
  "test/fixtures/git_log",
41
+ "test/fixtures/git_show_055850e7d925110322b8db4e17c3b840d76e144c",
39
42
  "test/fixtures/git_show_51b986619d88f7ba98be7d271188785cbbb541a0",
40
43
  "test/fixtures/git_show_a4629e707d80a5769f7a71ca6ed9471015e14dc9",
41
44
  "test/fixtures/git_show_dce6ade4cdc2833b53bd600ef10f9bce83c7102d",
@@ -65,15 +68,18 @@ Gem::Specification.new do |s|
65
68
  s.add_runtime_dependency(%q<diff-lcs>, [">= 0"])
66
69
  s.add_runtime_dependency(%q<mocha>, [">= 0"])
67
70
  s.add_runtime_dependency(%q<hpricot>, [">= 0"])
71
+ s.add_runtime_dependency(%q<tamtam>, [">= 0"])
68
72
  else
69
73
  s.add_dependency(%q<diff-lcs>, [">= 0"])
70
74
  s.add_dependency(%q<mocha>, [">= 0"])
71
75
  s.add_dependency(%q<hpricot>, [">= 0"])
76
+ s.add_dependency(%q<tamtam>, [">= 0"])
72
77
  end
73
78
  else
74
79
  s.add_dependency(%q<diff-lcs>, [">= 0"])
75
80
  s.add_dependency(%q<mocha>, [">= 0"])
76
81
  s.add_dependency(%q<hpricot>, [">= 0"])
82
+ s.add_dependency(%q<tamtam>, [">= 0"])
77
83
  end
78
84
  end
79
85
 
data/lib/commit_hook.rb CHANGED
@@ -28,6 +28,9 @@ class CommitHook
28
28
  return
29
29
  end
30
30
 
31
+ puts "Sending mail..."
32
+ STDOUT.flush
33
+
31
34
  prefix = Git.repo_name
32
35
  branch_name = (ref_name =~ /master$/i) ? "" : "/#{ref_name.split("/").last}"
33
36
 
@@ -36,8 +39,17 @@ class CommitHook
36
39
 
37
40
  diff2html = DiffToHtml.new(Dir.pwd)
38
41
  diff2html.diff_between_revisions rev1, rev2, prefix, ref_name
39
- diff2html.result.reverse.each_with_index do |result, i|
40
- nr = number(diff2html.result.size, i)
42
+
43
+ result = diff2html.result
44
+
45
+ if (@config["ignore_merge"])
46
+ result = result.reject {|result|
47
+ !result[:commit_info][:merge].nil?
48
+ }
49
+ end
50
+
51
+ result.reverse.each_with_index do |result, i|
52
+ nr = number(result.size, i)
41
53
  emailer = Emailer.new @config, project_path, recipient, result[:commit_info][:email], result[:commit_info][:author],
42
54
  "[#{prefix}#{branch_name}]#{nr} #{result[:commit_info][:message]}", result[:text_content], result[:html_content], rev1, rev2, ref_name
43
55
  emailer.send
data/lib/diff_to_html.rb CHANGED
@@ -222,6 +222,8 @@ class DiffToHtml
222
222
  result[:author], result[:email] = author_name_and_email(line[8..-1])
223
223
  elsif line =~ /^Date/
224
224
  result[:date] = line[8..-1]
225
+ elsif line =~ /^Merge/
226
+ result[:merge] = line[8..-1]
225
227
  else
226
228
  clean_line = line.strip
227
229
  result[:message] << clean_line unless clean_line.empty?
@@ -275,6 +277,7 @@ class DiffToHtml
275
277
  File.open(previous_file, "w"){|f| f << current_list.join("\n") } unless current_list.empty? || defined?(Test::Unit)
276
278
 
277
279
  commits.each_with_index do |commit, i|
280
+
278
281
  raw_diff = Git.show(commit)
279
282
  raise "git show output is empty" if raw_diff.empty?
280
283
  @last_raw = raw_diff
data/lib/emailer.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'yaml'
2
2
  require 'erb'
3
+ require 'tamtam'
3
4
 
4
5
  class Emailer
5
6
 
@@ -17,7 +18,7 @@ class Emailer
17
18
  @new_rev = new_rev
18
19
 
19
20
  template = File.join(File.dirname(__FILE__), '/../template/email.html.erb')
20
- @html_message = ERB.new(File.read(template)).result(binding)
21
+ @html_message = TamTam.inline(:document => ERB.new(File.read(template)).result(binding))
21
22
  end
22
23
 
23
24
  def boundary
@@ -0,0 +1,17 @@
1
+ delivery_method: sendmail # smtp or sendmail
2
+ ignore_merge: true # set to true if you want to ignore empty merge messages
3
+
4
+ smtp_server:
5
+ address: localhost
6
+ port: 25
7
+ domain: localhost
8
+ user_name: user@localhost
9
+ password: password
10
+ authentication: plain
11
+ enable_tls: false
12
+
13
+ sendmail_options:
14
+ location: /usr/sbin/sendmail
15
+ arguments:
16
+
17
+
@@ -0,0 +1,17 @@
1
+ delivery_method: sendmail # smtp or sendmail
2
+ ignore_merge: false # set to true if you want to ignore empty merge messages
3
+
4
+ smtp_server:
5
+ address: localhost
6
+ port: 25
7
+ domain: localhost
8
+ user_name: user@localhost
9
+ password: password
10
+ authentication: plain
11
+ enable_tls: false
12
+
13
+ sendmail_options:
14
+ location: /usr/sbin/sendmail
15
+ arguments:
16
+
17
+
@@ -32,3 +32,10 @@ Date: Mon Oct 6 17:35:21 2008 +0300
32
32
  button input elements have no default behavior to cancel.
33
33
 
34
34
  Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
35
+
36
+ commit 055850e7d925110322b8db4e17c3b840d76e144c
37
+ Merge: 7e4f6b4 4f13525
38
+ Author: Bodo Tasche <bodo@wannawork.de>
39
+ Date: Thu Mar 25 21:02:04 2010 +0100
40
+
41
+ Merge branch 'master' of a/bla2/../bla
@@ -0,0 +1,6 @@
1
+ commit 055850e7d925110322b8db4e17c3b840d76e144c
2
+ Merge: 7e4f6b4 4f13525
3
+ Author: Bodo Tasche <bodo@wannawork.de>
4
+ Date: Thu Mar 25 21:02:04 2010 +0100
5
+
6
+ Merge branch 'master' of a/bla2/../bla
data/test/test_helper.rb CHANGED
@@ -4,7 +4,8 @@ unless defined? REVISIONS
4
4
  REVISIONS = ['e28ad77bba0574241e6eb64dfd0c1291b221effe', # 2 files updated
5
5
  'a4629e707d80a5769f7a71ca6ed9471015e14dc9', # 1 file updated
6
6
  'dce6ade4cdc2833b53bd600ef10f9bce83c7102d', # 6 files updated
7
- '51b986619d88f7ba98be7d271188785cbbb541a0'] # 3 files updated
7
+ '51b986619d88f7ba98be7d271188785cbbb541a0', # 3 files updated
8
+ '055850e7d925110322b8db4e17c3b840d76e144c'] # Empty merge message
8
9
 
9
10
  end
10
11
 
@@ -7,7 +7,15 @@ require File.dirname(__FILE__) + '/../../lib/git'
7
7
 
8
8
  class CommitHookTest < Test::Unit::TestCase
9
9
 
10
- def test_hook
10
+ def test_hook_ignore_merge
11
+ run_with_config('test/fixtures/git-notifier-ignore-merge.yml', 4) # 4 commit, one email for each of them, without merge
12
+ end
13
+
14
+ def test_hook_with_merge
15
+ run_with_config('test/fixtures/git-notifier-with-merge.yml', 5) # 5 commit, one email for each of them, with merge mail
16
+ end
17
+
18
+ def run_with_config(config, times)
11
19
  path = File.dirname(__FILE__) + '/../fixtures/'
12
20
  Git.expects(:log).with(REVISIONS.first, REVISIONS.last).returns(read_file(path + 'git_log'))
13
21
  Git.expects(:mailing_list_address).returns('recipient@test.com')
@@ -15,8 +23,10 @@ class CommitHookTest < Test::Unit::TestCase
15
23
  Git.expects(:show).with(rev).returns(read_file(path + "git_show_#{rev}"))
16
24
  end
17
25
  emailer = mock('Emailer')
18
- Emailer.expects(:new).times(4).returns(emailer) # 4 commit, one email for each of them
19
- emailer.expects(:send).times(4)
20
- CommitHook.run 'config/email.yml.sample', REVISIONS.first, REVISIONS.last, 'refs/heads/master'
26
+ Emailer.expects(:new).times(times).returns(emailer) # 4 commit, one email for each of them
27
+ emailer.expects(:send).times(times)
28
+ CommitHook.run config, REVISIONS.first, REVISIONS.last, 'refs/heads/master'
21
29
  end
30
+
31
+
22
32
  end
@@ -19,7 +19,7 @@ class DiffToHtmlTest < Test::Unit::TestCase
19
19
 
20
20
  diff = DiffToHtml.new
21
21
  diff.diff_between_revisions REVISIONS.first, REVISIONS.last, 'testproject', 'master'
22
- assert_equal 4, diff.result.size # one result for each of the commits
22
+ assert_equal 5, diff.result.size # one result for each of the commits
23
23
 
24
24
  diff.result.each do |html|
25
25
  assert !html.include?('@@') # diff correctly processed
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Bodo Tasche
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-24 00:00:00 +01:00
17
+ date: 2010-03-25 00:00:00 +01:00
18
18
  default_executable: git-commit-notifier
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -53,6 +53,18 @@ dependencies:
53
53
  version: "0"
54
54
  type: :runtime
55
55
  version_requirements: *id003
56
+ - !ruby/object:Gem::Dependency
57
+ name: tamtam
58
+ prerelease: false
59
+ requirement: &id004 !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ type: :runtime
67
+ version_requirements: *id004
56
68
  description: This git commit notifier sends html mails with nice diffs for every changed file.
57
69
  email: bodo@wannawork.de
58
70
  executables:
@@ -79,7 +91,10 @@ files:
79
91
  - lib/result_processor.rb
80
92
  - template/email.html.erb
81
93
  - template/styles.css
94
+ - test/fixtures/git-notifier-ignore-merge.yml
95
+ - test/fixtures/git-notifier-with-merge.yml
82
96
  - test/fixtures/git_log
97
+ - test/fixtures/git_show_055850e7d925110322b8db4e17c3b840d76e144c
83
98
  - test/fixtures/git_show_51b986619d88f7ba98be7d271188785cbbb541a0
84
99
  - test/fixtures/git_show_a4629e707d80a5769f7a71ca6ed9471015e14dc9
85
100
  - test/fixtures/git_show_dce6ade4cdc2833b53bd600ef10f9bce83c7102d