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.
- data/LICENSE +1 -1
- data/README.textile +20 -5
- data/Rakefile +40 -20
- data/VERSION +1 -1
- data/bin/git-commit-notifier +8 -1
- data/config/git-notifier-config.yml.sample +41 -15
- data/git-commit-notifier.gemspec +50 -24
- data/lib/commit_hook.rb +104 -74
- data/lib/diff_to_html.rb +120 -52
- data/lib/emailer.rb +43 -22
- data/lib/git.rb +36 -26
- data/lib/logger.rb +48 -0
- data/lib/result_processor.rb +9 -5
- data/{test → spec}/fixtures/existing_file_one_line.txt +0 -0
- data/{test → spec}/fixtures/git-notifier-group-email-by-push.yml +2 -0
- data/{test → spec}/fixtures/git-notifier-ignore-merge.yml +0 -0
- data/{test → spec}/fixtures/git-notifier-with-merge.yml +0 -0
- data/{test → spec}/fixtures/git_log +0 -0
- data/{test → spec}/fixtures/git_show_055850e7d925110322b8db4e17c3b840d76e144c +0 -0
- data/{test → spec}/fixtures/git_show_51b986619d88f7ba98be7d271188785cbbb541a0 +0 -0
- data/{test → spec}/fixtures/git_show_a4629e707d80a5769f7a71ca6ed9471015e14dc9 +0 -0
- data/{test → spec}/fixtures/git_show_dce6ade4cdc2833b53bd600ef10f9bce83c7102d +0 -0
- data/{test → spec}/fixtures/git_show_e28ad77bba0574241e6eb64dfd0c1291b221effe +0 -0
- data/spec/fixtures/git_show_ff037a73fc1094455e7bbf506171a3f3cf873ae6 +18 -0
- data/{test → spec}/fixtures/new_file_one_line.txt +0 -0
- data/spec/lib/commit_hook_spec.rb +88 -0
- data/spec/lib/diff_to_html_spec.rb +168 -0
- data/spec/lib/emailer_spec.rb +102 -0
- data/spec/lib/git_spec.rb +93 -0
- data/spec/lib/logger_spec.rb +63 -0
- data/spec/lib/result_processor_spec.rb +102 -0
- data/{test/test_helper.rb → spec/spec_helper.rb} +14 -12
- data/template/email.html.erb +2 -2
- data/template/styles.css +2 -1
- metadata +110 -31
- data/test/unit/test_commit_hook.rb +0 -43
- data/test/unit/test_diff_to_html.rb +0 -160
- data/test/unit/test_result_processor.rb +0 -95
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2008, 2010 Bodo Tasche, Csoma Zoltan, Primalgrasp
|
1
|
+
Copyright (c) 2008, 2010 Bodo Tasche, Akzhan Abdulin, Csoma Zoltan, Primalgrasp
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person
|
4
4
|
obtaining a copy of this software and associated documentation
|
data/README.textile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
h1. Git Commit Notifier
|
2
2
|
|
3
|
-
__by Bodo Tasche (bodo 'at' wannawork 'dot' de), Csoma Zoltan (Primalgrasp) (zoltan 'at' primalgrasp 'dot' com)__
|
3
|
+
__by Bodo Tasche (bodo 'at' wannawork 'dot' de), Akzhan Abdulin (akzhan 'dot' abdulin 'at' gmail 'dot' com), Csoma Zoltan (Primalgrasp) (zoltan 'at' primalgrasp 'dot' com)__
|
4
4
|
|
5
5
|
Sends email commit messages splitting commits that were pushed in one step.
|
6
6
|
Email is delivered as text or HTML with changes refined per word. Emails
|
@@ -44,6 +44,13 @@ git-commit-notifier path_to_config.yml
|
|
44
44
|
|
45
45
|
An example for the config file can be found in <a href="http://github.com/bitboxer/git-commit-notifier/blob/master/config/git-notifier-config.yml.sample">config/git-notifier-config.yml.sample</a>.
|
46
46
|
|
47
|
+
If you want to send mails on each commit instead on each pull, you should add a file called "post-commit" with this content:
|
48
|
+
|
49
|
+
<pre>
|
50
|
+
#!/bin/sh
|
51
|
+
echo "HEAD^1 HEAD refs/heads/master" | git-commit-notifier path_to_config.yml
|
52
|
+
</pre>
|
53
|
+
|
47
54
|
h2. Integration with Redmine, Bugzilla, MediaWiki
|
48
55
|
|
49
56
|
Git-commit-notifier supports easy integration with Redmine, Bugzilla and MediaWiki. All you need is to uncomment the according line in the configuration and change the links to your software installations instead of example ones (no trailing slash please).
|
@@ -67,6 +74,17 @@ Key and value are enclosed into single quotes. \b means that "follow" must not b
|
|
67
74
|
|
68
75
|
More examples can be found in the config file.
|
69
76
|
|
77
|
+
h2. Logic of commits handling
|
78
|
+
|
79
|
+
Commit notifier use special files named *previously.txt to track already
|
80
|
+
handled commits to not send repeated messages about commits.
|
81
|
+
|
82
|
+
By default all commits tracked through overall repository so after merge action
|
83
|
+
You should not receive messages about commits those already posted in other branches.
|
84
|
+
|
85
|
+
This behaviour can be changed using unique_commits_per_branch option. When it's true,
|
86
|
+
you should receive new message about commit when it's merged in other branch.
|
87
|
+
|
70
88
|
h2. Note on Patches/Pull Requests
|
71
89
|
|
72
90
|
* Fork the project.
|
@@ -81,10 +99,7 @@ h2. Troubleshooting
|
|
81
99
|
|
82
100
|
h3. Permission denied - /var/git/repo/previously.txt (Errno::EACCES)
|
83
101
|
|
84
|
-
The file __previously.txt__ is created at the first commit. If you moved the file to the server, you have to check the rights to that file and fix them if needed.
|
85
|
-
|
86
|
-
<pre>sudo touch /var/git/repo/previously.txt
|
87
|
-
sudo chmod a+x /var/git/repo/previously.txt</pre>
|
102
|
+
The file __previously.txt__ is created at the first commit. If you moved the file to the server, you have to check the rights to that file and fix them if needed. The git repo owner needs the right to write into that file.
|
88
103
|
|
89
104
|
h2. License
|
90
105
|
|
data/Rakefile
CHANGED
@@ -1,55 +1,75 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
3
|
|
4
|
+
APP_ROOT = File.dirname(__FILE__).freeze
|
5
|
+
|
4
6
|
begin
|
5
7
|
require 'jeweler'
|
6
8
|
Jeweler::Tasks.new do |gem|
|
7
9
|
gem.name = "git-commit-notifier"
|
8
10
|
gem.summary = %Q{Sends git commit messages with diffs}
|
9
11
|
gem.description = %Q{This git commit notifier sends html mails with nice diffs for every changed file.}
|
10
|
-
gem.email = "bodo@
|
11
|
-
gem.homepage = "http://github.com/
|
12
|
+
gem.email = "bodo@bitboxer.de"
|
13
|
+
gem.homepage = "http://github.com/bitboxer/git-commit-notifier"
|
12
14
|
gem.authors = ["Bodo Tasche"]
|
13
15
|
gem.add_dependency('diff-lcs')
|
14
16
|
gem.add_dependency('mocha')
|
15
17
|
gem.add_dependency('hpricot')
|
16
18
|
gem.add_dependency('tamtam')
|
19
|
+
gem.add_development_dependency('rspec-core')
|
20
|
+
gem.add_development_dependency('rspec-expectations')
|
21
|
+
gem.add_development_dependency('rr')
|
22
|
+
gem.add_development_dependency('faker')
|
23
|
+
gem.add_development_dependency('rcov')
|
24
|
+
gem.add_development_dependency('metric_fu')
|
17
25
|
end
|
18
26
|
Jeweler::GemcutterTasks.new
|
19
27
|
rescue LoadError
|
20
28
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
29
|
end
|
22
30
|
|
23
|
-
require 'rake/testtask'
|
24
|
-
Rake::TestTask.new(:test) do |test|
|
25
|
-
test.libs << 'lib' << 'test'
|
26
|
-
test.pattern = 'test/**/test_*.rb'
|
27
|
-
test.verbose = true
|
28
|
-
end
|
29
|
-
|
30
31
|
begin
|
31
|
-
require '
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
test.verbose = true
|
32
|
+
require 'rspec/core/rake_task'
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new do |t|
|
35
|
+
t.rspec_opts = ["-c", "-f progress"]
|
36
36
|
end
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
|
38
|
+
RSpec::Core::RakeTask.new(:rcov) do |t|
|
39
|
+
t.rcov = true
|
40
|
+
t.ruby_opts = '-w'
|
41
|
+
t.rspec_opts = ["-c", "-f progress"]
|
42
|
+
t.rcov_opts = %q[-Ilib --exclude "spec/*,gems/*"]
|
40
43
|
end
|
44
|
+
rescue LoadError
|
45
|
+
$stderr.puts "RSpec not available. Install it with: gem install rspec-core rspec-expectations"
|
41
46
|
end
|
42
47
|
|
43
|
-
task :
|
48
|
+
task :default => :spec
|
44
49
|
|
45
|
-
|
50
|
+
begin
|
51
|
+
require 'metric_fu'
|
52
|
+
rescue LoadError
|
53
|
+
$stderr.puts "metric_fu not available. Install it with: gem install metric_fu"
|
54
|
+
end
|
46
55
|
|
47
56
|
require 'rake/rdoctask'
|
48
57
|
Rake::RDocTask.new do |rdoc|
|
49
|
-
version = File.
|
58
|
+
version = File.exists?('VERSION') ? IO.read('VERSION') : ""
|
50
59
|
|
51
60
|
rdoc.rdoc_dir = 'rdoc'
|
52
61
|
rdoc.title = "git-commit-notifier #{version}"
|
53
62
|
rdoc.rdoc_files.include('README*')
|
54
63
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
64
|
end
|
65
|
+
|
66
|
+
begin
|
67
|
+
gem 'code-cleaner'
|
68
|
+
desc 'Clean code for whitespaces and tabs'
|
69
|
+
task :'code:clean' do
|
70
|
+
system('code-cleaner lib spec Rakefile bin/git-commit-notifier')
|
71
|
+
end
|
72
|
+
rescue LoadError
|
73
|
+
$stderr.puts "code-cleaner not available. Install it with: gem install code-cleaner"
|
74
|
+
end
|
75
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.1
|
data/bin/git-commit-notifier
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
if RUBY_VERSION < '1.9'
|
4
|
+
# This is for Unicode support in Ruby 1.8
|
5
|
+
$KCODE = 'u';
|
6
|
+
require 'jcode'
|
7
|
+
end
|
8
|
+
|
2
9
|
# parameters: revision1, revision 2, branch
|
3
10
|
THIS_FILE = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
|
4
11
|
$:.unshift File.join(File.dirname(THIS_FILE), "../lib")
|
@@ -17,4 +24,4 @@ when 3
|
|
17
24
|
CommitHook.run ARGV[0], ARGV[1], ARGV[2], ""
|
18
25
|
else
|
19
26
|
CommitHook.run ARGV[0], ARGV[1], ARGV[2], ARGV[3]
|
20
|
-
end
|
27
|
+
end
|
@@ -1,18 +1,22 @@
|
|
1
|
-
# The recipient for the commit:
|
2
|
-
mailinglist: developers@example.com
|
3
|
-
|
4
1
|
# set to true if you want to ignore empty merge messages
|
5
2
|
ignore_merge: false
|
6
3
|
|
7
4
|
# Optional parameter for the subject-line of the mail
|
8
5
|
# emailprefix: GIT
|
9
6
|
|
10
|
-
# Decorate files with link to a webview. Possible values: none, gitweb or gitorious
|
11
|
-
link_files: none
|
12
|
-
|
13
7
|
# Limit lines per diff
|
14
8
|
# lines_per_diff: 300
|
15
9
|
|
10
|
+
# The recipient for the commit:
|
11
|
+
mailinglist: developers@example.com
|
12
|
+
|
13
|
+
# The from addres. If not defined it will use
|
14
|
+
# the address that is configured in git
|
15
|
+
# from: sender@example.com
|
16
|
+
|
17
|
+
# stylesheet file (embedded template/styles.css by default)
|
18
|
+
# stylesheet: /absolute/path/to/readable/stylesheet.css
|
19
|
+
|
16
20
|
# select the delivery method: smtp or sendmail
|
17
21
|
delivery_method: sendmail
|
18
22
|
|
@@ -34,15 +38,8 @@ sendmail_options:
|
|
34
38
|
location: /usr/sbin/sendmail
|
35
39
|
arguments: -i -t
|
36
40
|
|
37
|
-
# commit
|
38
|
-
|
39
|
-
# '\brefs\s*\#(\d+)': 'http://example.com/redmine/issues/show/\1'
|
40
|
-
|
41
|
-
# Uncomment if you want to create links in your commit text
|
42
|
-
message_integration:
|
43
|
-
# mediawiki: http://example.com/wiki # will rework [[text]] to MediaWiki pages
|
44
|
-
# redmine: http://redmine.example.com # will rework refs #123 to Redmine issues
|
45
|
-
# bugzilla: http://bz.example.com # will rework BUG 123 to Bugzilla bugs
|
41
|
+
# Decorate files and commit ids with link to a webview. Possible values: none, gitweb, gitorious, cgit or trac
|
42
|
+
link_files: none
|
46
43
|
|
47
44
|
# If link_files is set to "gitweb", you need to configure the path to your gitweb
|
48
45
|
# instance and the project name.
|
@@ -57,3 +54,32 @@ gitorious:
|
|
57
54
|
project: backend
|
58
55
|
repository: sql-scripts
|
59
56
|
|
57
|
+
# if link_files is set to "cgit", you need to configure the path to your cgit
|
58
|
+
cgit:
|
59
|
+
path: http://example.com/path_to_cgit
|
60
|
+
project: backend
|
61
|
+
|
62
|
+
# If link_files is set to "trac", you need to configure the path to your trac
|
63
|
+
# instance
|
64
|
+
trac:
|
65
|
+
path: http://example.com/changeset
|
66
|
+
|
67
|
+
# commit message URL map
|
68
|
+
message_map:
|
69
|
+
# '\brefs\s*\#(\d+)': 'http://example.com/redmine/issues/show/\1'
|
70
|
+
|
71
|
+
# Uncomment if you want to create links in your commit text
|
72
|
+
message_integration:
|
73
|
+
# mediawiki: http://example.com/wiki # will rework [[text]] to MediaWiki pages
|
74
|
+
# redmine: http://redmine.example.com # will rework refs #123 to Redmine issues
|
75
|
+
# bugzilla: http://bz.example.com # will rework BUG 123 to Bugzilla bugs
|
76
|
+
# fogbugz: http://yourondemand.fogbugz.com/? # will rework BugzId: 123 to FogBugz cases
|
77
|
+
|
78
|
+
# Track unique commits per branch?
|
79
|
+
unique_commits_per_branch: false
|
80
|
+
|
81
|
+
# This is developer debugging options. Do not uncomment it if You aren't Jedi
|
82
|
+
# debug:
|
83
|
+
# enable: true
|
84
|
+
# log_directory: /path/to/log/directory
|
85
|
+
|
data/git-commit-notifier.gemspec
CHANGED
@@ -5,14 +5,14 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{git-commit-notifier}
|
8
|
-
s.version = "0.8.
|
8
|
+
s.version = "0.8.1"
|
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-
|
12
|
+
s.date = %q{2010-11-03}
|
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
|
-
s.email = %q{bodo@
|
15
|
+
s.email = %q{bodo@bitboxer.de}
|
16
16
|
s.executables = ["git-commit-notifier"]
|
17
17
|
s.extra_rdoc_files = [
|
18
18
|
"LICENSE",
|
@@ -32,35 +32,43 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/diff_to_html.rb",
|
33
33
|
"lib/emailer.rb",
|
34
34
|
"lib/git.rb",
|
35
|
+
"lib/logger.rb",
|
35
36
|
"lib/result_processor.rb",
|
37
|
+
"spec/fixtures/existing_file_one_line.txt",
|
38
|
+
"spec/fixtures/git-notifier-group-email-by-push.yml",
|
39
|
+
"spec/fixtures/git-notifier-ignore-merge.yml",
|
40
|
+
"spec/fixtures/git-notifier-with-merge.yml",
|
41
|
+
"spec/fixtures/git_log",
|
42
|
+
"spec/fixtures/git_show_055850e7d925110322b8db4e17c3b840d76e144c",
|
43
|
+
"spec/fixtures/git_show_51b986619d88f7ba98be7d271188785cbbb541a0",
|
44
|
+
"spec/fixtures/git_show_a4629e707d80a5769f7a71ca6ed9471015e14dc9",
|
45
|
+
"spec/fixtures/git_show_dce6ade4cdc2833b53bd600ef10f9bce83c7102d",
|
46
|
+
"spec/fixtures/git_show_e28ad77bba0574241e6eb64dfd0c1291b221effe",
|
47
|
+
"spec/fixtures/git_show_ff037a73fc1094455e7bbf506171a3f3cf873ae6",
|
48
|
+
"spec/fixtures/new_file_one_line.txt",
|
49
|
+
"spec/lib/commit_hook_spec.rb",
|
50
|
+
"spec/lib/diff_to_html_spec.rb",
|
51
|
+
"spec/lib/emailer_spec.rb",
|
52
|
+
"spec/lib/git_spec.rb",
|
53
|
+
"spec/lib/logger_spec.rb",
|
54
|
+
"spec/lib/result_processor_spec.rb",
|
55
|
+
"spec/spec_helper.rb",
|
36
56
|
"template/email.html.erb",
|
37
|
-
"template/styles.css"
|
38
|
-
"test/fixtures/existing_file_one_line.txt",
|
39
|
-
"test/fixtures/git-notifier-group-email-by-push.yml",
|
40
|
-
"test/fixtures/git-notifier-ignore-merge.yml",
|
41
|
-
"test/fixtures/git-notifier-with-merge.yml",
|
42
|
-
"test/fixtures/git_log",
|
43
|
-
"test/fixtures/git_show_055850e7d925110322b8db4e17c3b840d76e144c",
|
44
|
-
"test/fixtures/git_show_51b986619d88f7ba98be7d271188785cbbb541a0",
|
45
|
-
"test/fixtures/git_show_a4629e707d80a5769f7a71ca6ed9471015e14dc9",
|
46
|
-
"test/fixtures/git_show_dce6ade4cdc2833b53bd600ef10f9bce83c7102d",
|
47
|
-
"test/fixtures/git_show_e28ad77bba0574241e6eb64dfd0c1291b221effe",
|
48
|
-
"test/fixtures/new_file_one_line.txt",
|
49
|
-
"test/test_helper.rb",
|
50
|
-
"test/unit/test_commit_hook.rb",
|
51
|
-
"test/unit/test_diff_to_html.rb",
|
52
|
-
"test/unit/test_result_processor.rb"
|
57
|
+
"template/styles.css"
|
53
58
|
]
|
54
|
-
s.homepage = %q{http://github.com/
|
59
|
+
s.homepage = %q{http://github.com/bitboxer/git-commit-notifier}
|
55
60
|
s.rdoc_options = ["--charset=UTF-8"]
|
56
61
|
s.require_paths = ["lib"]
|
57
62
|
s.rubygems_version = %q{1.3.7}
|
58
63
|
s.summary = %q{Sends git commit messages with diffs}
|
59
64
|
s.test_files = [
|
60
|
-
"
|
61
|
-
"
|
62
|
-
"
|
63
|
-
"
|
65
|
+
"spec/lib/commit_hook_spec.rb",
|
66
|
+
"spec/lib/diff_to_html_spec.rb",
|
67
|
+
"spec/lib/emailer_spec.rb",
|
68
|
+
"spec/lib/git_spec.rb",
|
69
|
+
"spec/lib/logger_spec.rb",
|
70
|
+
"spec/lib/result_processor_spec.rb",
|
71
|
+
"spec/spec_helper.rb"
|
64
72
|
]
|
65
73
|
|
66
74
|
if s.respond_to? :specification_version then
|
@@ -72,17 +80,35 @@ Gem::Specification.new do |s|
|
|
72
80
|
s.add_runtime_dependency(%q<mocha>, [">= 0"])
|
73
81
|
s.add_runtime_dependency(%q<hpricot>, [">= 0"])
|
74
82
|
s.add_runtime_dependency(%q<tamtam>, [">= 0"])
|
83
|
+
s.add_development_dependency(%q<rspec-core>, [">= 0"])
|
84
|
+
s.add_development_dependency(%q<rspec-expectations>, [">= 0"])
|
85
|
+
s.add_development_dependency(%q<rr>, [">= 0"])
|
86
|
+
s.add_development_dependency(%q<faker>, [">= 0"])
|
87
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
88
|
+
s.add_development_dependency(%q<metric_fu>, [">= 0"])
|
75
89
|
else
|
76
90
|
s.add_dependency(%q<diff-lcs>, [">= 0"])
|
77
91
|
s.add_dependency(%q<mocha>, [">= 0"])
|
78
92
|
s.add_dependency(%q<hpricot>, [">= 0"])
|
79
93
|
s.add_dependency(%q<tamtam>, [">= 0"])
|
94
|
+
s.add_dependency(%q<rspec-core>, [">= 0"])
|
95
|
+
s.add_dependency(%q<rspec-expectations>, [">= 0"])
|
96
|
+
s.add_dependency(%q<rr>, [">= 0"])
|
97
|
+
s.add_dependency(%q<faker>, [">= 0"])
|
98
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
99
|
+
s.add_dependency(%q<metric_fu>, [">= 0"])
|
80
100
|
end
|
81
101
|
else
|
82
102
|
s.add_dependency(%q<diff-lcs>, [">= 0"])
|
83
103
|
s.add_dependency(%q<mocha>, [">= 0"])
|
84
104
|
s.add_dependency(%q<hpricot>, [">= 0"])
|
85
105
|
s.add_dependency(%q<tamtam>, [">= 0"])
|
106
|
+
s.add_dependency(%q<rspec-core>, [">= 0"])
|
107
|
+
s.add_dependency(%q<rspec-expectations>, [">= 0"])
|
108
|
+
s.add_dependency(%q<rr>, [">= 0"])
|
109
|
+
s.add_dependency(%q<faker>, [">= 0"])
|
110
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
111
|
+
s.add_dependency(%q<metric_fu>, [">= 0"])
|
86
112
|
end
|
87
113
|
end
|
88
114
|
|
data/lib/commit_hook.rb
CHANGED
@@ -1,99 +1,129 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require 'yaml'
|
2
3
|
require 'cgi'
|
3
4
|
require 'net/smtp'
|
4
|
-
require 'sha1'
|
5
|
+
require 'digest/sha1'
|
5
6
|
|
7
|
+
require 'logger'
|
6
8
|
require 'diff_to_html'
|
7
9
|
require 'emailer'
|
8
10
|
require 'git'
|
9
11
|
|
10
12
|
class CommitHook
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
class << self
|
15
|
+
attr_reader :config
|
16
|
+
|
17
|
+
def show_error(message)
|
18
|
+
$stderr.puts "************** GIT NOTIFIER PROBLEM *******************"
|
19
|
+
$stderr.puts "\n"
|
20
|
+
$stderr.puts message
|
21
|
+
$stderr.puts "\n"
|
22
|
+
$stderr.puts "************** GIT NOTIFIER PROBLEM *******************"
|
23
|
+
end
|
19
24
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
project_path = Dir.getwd
|
25
|
-
recipient = @config["mailinglist"] || Git.mailing_list_address
|
26
|
-
|
27
|
-
if (recipient.nil? || recipient.length == 0)
|
28
|
-
CommitHook.show_error(
|
29
|
-
"Please add a recipient for the emails. Eg : \n" +
|
30
|
-
" git config hooks.mailinglist developer@example.com")
|
31
|
-
return
|
25
|
+
def info(message)
|
26
|
+
$stdout.puts message
|
27
|
+
$stdout.flush
|
32
28
|
end
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
|
30
|
+
def logger
|
31
|
+
@logger ||= Logger.new(config)
|
32
|
+
end
|
33
|
+
|
34
|
+
def run(config_name, rev1, rev2, ref_name)
|
35
|
+
@config = File.exists?(config_name) ? YAML::load_file(config_name) : {}
|
36
|
+
|
37
|
+
project_path = Dir.getwd
|
38
|
+
recipient = config["mailinglist"] || Git.mailing_list_address
|
39
|
+
|
40
|
+
if recipient.nil? || recipient.length == 0
|
41
|
+
CommitHook.show_error(
|
42
|
+
"Please add a recipient for the emails. Eg : \n" +
|
43
|
+
" git config hooks.mailinglist developer@example.com"
|
44
|
+
)
|
45
|
+
return
|
46
|
+
end
|
47
|
+
|
48
|
+
logger.debug('----')
|
49
|
+
logger.debug("pwd: #{Dir.pwd}")
|
50
|
+
logger.debug("ref_name: #{ref_name}")
|
51
|
+
logger.debug("rev1: #{rev1}")
|
52
|
+
logger.debug("rev2: #{rev2}")
|
53
|
+
|
54
|
+
|
55
|
+
info("Sending mail...")
|
56
|
+
|
37
57
|
prefix = @config["emailprefix"] || Git.repo_name
|
38
58
|
branch_name = (ref_name =~ /master$/i) ? "" : "/#{ref_name.split("/").last}"
|
39
59
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
diffresult = diff2html.result
|
60
|
+
logger.debug("prefix: #{prefix}")
|
61
|
+
logger.debug("branch: #{branch_name}")
|
44
62
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
63
|
+
diff2html = DiffToHtml.new(Dir.pwd, config)
|
64
|
+
diff2html.diff_between_revisions(rev1, rev2, prefix, ref_name)
|
65
|
+
|
66
|
+
diffresult = diff2html.result
|
50
67
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
html << result[:html_content]
|
68
|
+
if config["ignore_merge"]
|
69
|
+
diffresult = diffresult.reject do |result|
|
70
|
+
!result[:commit_info][:merge].nil?
|
71
|
+
end
|
56
72
|
end
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
recipient,
|
79
|
-
result[:commit_info][:email],
|
80
|
-
result[:commit_info][:author],
|
81
|
-
"[#{prefix}#{branch_name}]#{nr} #{result[:commit_info][:message]}",
|
82
|
-
result[:text_content],
|
83
|
-
result[:html_content],
|
84
|
-
rev1,
|
85
|
-
rev2,
|
86
|
-
ref_name
|
73
|
+
|
74
|
+
if config["group_email_by_push"]
|
75
|
+
text, html = [], []
|
76
|
+
diffresult.each_with_index do |result, i|
|
77
|
+
text << result[:text_content]
|
78
|
+
html << result[:html_content]
|
79
|
+
end
|
80
|
+
result = diffresult.first
|
81
|
+
return if result.nil? || !result[:commit_info]
|
82
|
+
|
83
|
+
emailer = Emailer.new(config,
|
84
|
+
:project_path => project_path,
|
85
|
+
:recipient => recipient,
|
86
|
+
:from_address => config["from"] || result[:commit_info][:email],
|
87
|
+
:from_alias => result[:commit_info][:author],
|
88
|
+
:subject => "[#{prefix}#{branch_name}] #{diffresult.size > 1 ? "#{diffresult.size} commits: " : ''}#{result[:commit_info][:message]}",
|
89
|
+
:text_message => text.join("------------------------------------------\n\n"),
|
90
|
+
:html_message => html.join("<hr /><br />"),
|
91
|
+
:old_rev => rev1,
|
92
|
+
:new_rev => rev2,
|
93
|
+
:ref_name => ref_name
|
87
94
|
)
|
88
95
|
emailer.send
|
96
|
+
else
|
97
|
+
diffresult.reverse.each_with_index do |result, i|
|
98
|
+
next unless result[:commit_info]
|
99
|
+
nr = number(diffresult.size, i)
|
100
|
+
|
101
|
+
emailer = Emailer.new(config,
|
102
|
+
:project_path => project_path,
|
103
|
+
:recipient => recipient,
|
104
|
+
:from_address => config["from"] || result[:commit_info][:email],
|
105
|
+
:from_alias => result[:commit_info][:author],
|
106
|
+
:subject => "[#{prefix}#{branch_name}]#{nr} #{result[:commit_info][:message]}",
|
107
|
+
:text_message => result[:text_content],
|
108
|
+
:html_message => result[:html_content],
|
109
|
+
:old_rev => rev1,
|
110
|
+
:new_rev => rev2,
|
111
|
+
:ref_name => ref_name
|
112
|
+
)
|
113
|
+
emailer.send
|
114
|
+
end
|
89
115
|
end
|
90
116
|
end
|
91
|
-
end
|
92
117
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
118
|
+
def number(total_entries, i)
|
119
|
+
return '' if total_entries <= 1
|
120
|
+
digits = total_entries < 10 ? 1 : 3
|
121
|
+
'[' + sprintf("%0#{digits}d", i + 1) + ']'
|
122
|
+
end
|
97
123
|
end
|
98
|
-
|
99
124
|
end
|
125
|
+
|
126
|
+
__END__
|
127
|
+
|
128
|
+
vim: tabstop=2:expandtab:shiftwidth=2
|
129
|
+
|