git-commit-notifier 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.0
1
+ 0.9.1
@@ -6,24 +6,11 @@ if RUBY_VERSION < '1.9'
6
6
  require 'jcode'
7
7
  end
8
8
 
9
+ require 'rubygems'
10
+
9
11
  # parameters: revision1, revision 2, branch
10
- THIS_FILE = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
11
- $:.unshift File.join(File.dirname(THIS_FILE), "../lib")
12
12
 
13
- require 'git_commit_notifier'
14
- include GitCommitNotifier
13
+ require 'git_commit_notifier/executor'
14
+
15
+ GitCommitNotifier::Executor.run!(ARGV)
15
16
 
16
- case ARGV.length
17
- when 0
18
- CommitHook.show_error("You have to add a path to the config file for git-commit-notifier")
19
- puts "Usage: git-commit-notifier config-script [oldrev newrev [ref]]"
20
- when 1
21
- oldrev, newrev, ref = STDIN.gets.strip.split
22
- CommitHook.run ARGV[0], oldrev, newrev, ref
23
- when 2
24
- CommitHook.run ARGV[0], ARGV[1], ARGV[1], ""
25
- when 3
26
- CommitHook.run ARGV[0], ARGV[1], ARGV[2], ""
27
- else
28
- CommitHook.run ARGV[0], ARGV[1], ARGV[2], ARGV[3]
29
- end
@@ -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.9.0"
8
+ s.version = "0.9.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{2011-04-04}
12
+ s.date = %q{2011-04-05}
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@bitboxer.de}
@@ -35,9 +35,11 @@ Gem::Specification.new do |s|
35
35
  "lib/git_commit_notifier/diff_to_html.rb",
36
36
  "lib/git_commit_notifier/emailer.rb",
37
37
  "lib/git_commit_notifier/escape_helper.rb",
38
+ "lib/git_commit_notifier/executor.rb",
38
39
  "lib/git_commit_notifier/git.rb",
39
40
  "lib/git_commit_notifier/logger.rb",
40
41
  "lib/git_commit_notifier/result_processor.rb",
42
+ "local-run.rb",
41
43
  "spec/fixtures/existing_file_one_line.txt",
42
44
  "spec/fixtures/git-notifier-group-email-by-push.yml",
43
45
  "spec/fixtures/git-notifier-ignore-merge.yml",
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'yaml'
3
2
  require 'cgi'
4
3
  require 'net/smtp'
@@ -34,7 +33,7 @@ module GitCommitNotifier
34
33
  recipient = config["mailinglist"] || Git.mailing_list_address
35
34
 
36
35
  if recipient.nil? || recipient.length == 0
37
- GitCommitNotifier::CommitHook.show_error(
36
+ CommitHook.show_error(
38
37
  "Please add a recipient for the emails. Eg : \n" +
39
38
  " git config hooks.mailinglist developer@example.com"
40
39
  )
@@ -65,7 +64,7 @@ module GitCommitNotifier
65
64
 
66
65
  info("Sending mail...")
67
66
 
68
- diff2html = GitCommitNotifier::DiffToHtml.new(Dir.pwd, config)
67
+ diff2html = DiffToHtml.new(Dir.pwd, config)
69
68
  diff2html.diff_between_revisions(rev1, rev2, prefix, ref_name)
70
69
 
71
70
  diffresult = diff2html.result
@@ -85,7 +84,7 @@ module GitCommitNotifier
85
84
  result = diffresult.first
86
85
  return if result.nil? || !result[:commit_info]
87
86
 
88
- emailer = GitCommitNotifier::Emailer.new(config,
87
+ emailer = Emailer.new(config,
89
88
  :project_path => project_path,
90
89
  :recipient => recipient,
91
90
  :from_address => config["from"] || result[:commit_info][:email],
@@ -103,7 +102,7 @@ module GitCommitNotifier
103
102
  next unless result[:commit_info]
104
103
  nr = number(diffresult.size, i)
105
104
 
106
- emailer = GitCommitNotifier::Emailer.new(config,
105
+ emailer = Emailer.new(config,
107
106
  :project_path => project_path,
108
107
  :recipient => recipient,
109
108
  :from_address => config["from"] || result[:commit_info][:email],
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'diff/lcs'
3
2
  require 'digest/sha1'
4
3
  require 'time'
@@ -35,7 +35,7 @@ class GitCommitNotifier::Emailer
35
35
  end
36
36
 
37
37
  def mail_html_message
38
- html = Emailer.template.result(binding)
38
+ html = GitCommitNotifier::Emailer.template.result(binding)
39
39
  premailer = Premailer.new(html, :with_html_string => true, :adapter => :nokogiri)
40
40
  premailer.to_inline_css
41
41
  end
@@ -87,7 +87,6 @@ class GitCommitNotifier::Emailer
87
87
  end
88
88
 
89
89
  def perform_delivery_nntp(content, nntp_settings)
90
- require 'rubygems'
91
90
  require 'nntp'
92
91
  Net::NNTP.start(nntp_settings['address'], nntp_settings['port']) do |nntp|
93
92
  nntp.post content
@@ -99,40 +98,38 @@ class GitCommitNotifier::Emailer
99
98
  quoted_from_alias = quote_if_necessary("#{@from_alias}",'utf-8')
100
99
  from = @from_alias.empty? ? @from_address : "#{quoted_from_alias} <#{@from_address}>"
101
100
 
102
- content = ["From: #{from}\n",
103
- "#{to_tag}: #{quote_if_necessary(@recipient, 'utf-8')}\n",
104
- "Subject: #{quote_if_necessary(@subject, 'utf-8')}\n",
105
- "X-Mailer: git-commit-notifier\n",
106
- "X-Git-Refname: #{@ref_name}\n",
107
- "X-Git-Oldrev: #{@old_rev}\n",
108
- "X-Git-Newrev: #{@new_rev}\n",
109
- "Mime-Version: 1.0\n",
101
+ content = [
102
+ "From: #{from}",
103
+ "#{to_tag}: #{quote_if_necessary(@recipient, 'utf-8')}",
104
+ "Subject: #{quote_if_necessary(@subject, 'utf-8')}",
105
+ "X-Mailer: git-commit-notifier",
106
+ "X-Git-Refname: #{@ref_name}",
107
+ "X-Git-Oldrev: #{@old_rev}",
108
+ "X-Git-Newrev: #{@new_rev}",
109
+ "Mime-Version: 1.0",
110
110
  "Content-Type: multipart/alternative; boundary=#{boundary}\n\n\n",
111
- "--#{boundary}\n",
112
- "Content-Type: text/plain; charset=utf-8\n",
113
- "Content-Transfer-Encoding: 8bit\n",
111
+ "--#{boundary}",
112
+ "Content-Type: text/plain; charset=utf-8",
113
+ "Content-Transfer-Encoding: 8bit",
114
114
  "Content-Disposition: inline\n\n\n",
115
115
  @text_message,
116
- "\n--#{boundary}\n",
117
- "Content-Type: text/html; charset=utf-8\n",
118
- "Content-Transfer-Encoding: 8bit\n",
116
+ "\n--#{boundary}",
117
+ "Content-Type: text/html; charset=utf-8",
118
+ "Content-Transfer-Encoding: 8bit",
119
119
  "Content-Disposition: inline\n\n\n",
120
120
  mail_html_message,
121
- "\n--#{boundary}--"]
121
+ "--#{boundary}--"]
122
122
 
123
123
  if @recipient.empty?
124
124
  puts content.join("\n")
125
125
  return
126
126
  end
127
127
 
128
- if config['delivery_method'] == 'smtp'
129
- perform_delivery_smtp(content, @config['smtp_server'])
130
- else
131
- if config['delivery_method'] == 'nntp'
132
- perform_delivery_nntp(content, @config['nntp_settings'])
133
- else
134
- perform_delivery_sendmail(content, @config['sendmail_options'])
135
- end
128
+ case config['delivery_method'].to_sym
129
+ when :smtp then perform_delivery_smtp(content, config['smtp_server'])
130
+ when :nntp then perform_delivery_nntp(content, config['nntp_settings'])
131
+ else # sendmail
132
+ perform_delivery_sendmail(content, @config['sendmail_options'])
136
133
  end
137
134
  end
138
135
 
@@ -0,0 +1,25 @@
1
+ # parameters: revision1, revision 2, branch
2
+
3
+ require 'git_commit_notifier'
4
+
5
+ module GitCommitNotifier
6
+ class Executor
7
+ def self.run!(args)
8
+ case args.length
9
+ when 0
10
+ CommitHook.show_error("You have to add a path to the config file for git-commit-notifier")
11
+ puts "Usage: git-commit-notifier config-script [oldrev newrev [ref]]"
12
+ when 1
13
+ oldrev, newrev, ref = $stdin.gets.strip.split
14
+ CommitHook.run args.first, oldrev, newrev, ref
15
+ when 2
16
+ CommitHook.run args.first, args.last, args.last, ""
17
+ when 3
18
+ CommitHook.run args.first, args[1], args.last, ""
19
+ else
20
+ CommitHook.run args.first, args[1], args[2], args[3]
21
+ end
22
+ end
23
+ end
24
+ end
25
+
@@ -1,5 +1,4 @@
1
1
  require 'cgi'
2
-
3
2
  require 'git_commit_notifier/escape_helper'
4
3
 
5
4
  module GitCommitNotifier
data/local-run.rb ADDED
@@ -0,0 +1,17 @@
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
+
9
+ require 'rubygems'
10
+ $LOAD_PATH.unshift(File.expand_path('./lib', File.dirname(__FILE__)))
11
+
12
+ # parameters: revision1, revision 2, branch
13
+
14
+ require 'git_commit_notifier/executor'
15
+
16
+ GitCommitNotifier::Executor.run!(ARGV)
17
+
@@ -1,9 +1,7 @@
1
1
  require File.expand_path('../../../spec_helper', __FILE__)
2
2
  require 'git_commit_notifier'
3
3
 
4
- include GitCommitNotifier
5
-
6
- describe CommitHook do
4
+ describe GitCommitNotifier::CommitHook do
7
5
 
8
6
  it "should ignore merge" do
9
7
  # 4 commits, one email for each of them, without merge
@@ -41,23 +39,23 @@ describe CommitHook do
41
39
  expect_repository_access
42
40
 
43
41
  emailer = mock!.send.times(times).subject
44
- mock(Emailer).new(anything, anything) { emailer }.times(times)
45
- mock(CommitHook).info(/Sending mail/)
42
+ mock(GitCommitNotifier::Emailer).new(anything, anything) { emailer }.times(times)
43
+ mock(GitCommitNotifier::CommitHook).info(/Sending mail/)
46
44
 
47
- any_instance_of(DiffToHtml, :check_handled_commits => lambda { |commits| commits })
48
- CommitHook.run config, REVISIONS.first, REVISIONS.last, branch
45
+ any_instance_of(GitCommitNotifier::DiffToHtml, :check_handled_commits => lambda { |commits| commits })
46
+ GitCommitNotifier::CommitHook.run config, REVISIONS.first, REVISIONS.last, branch
49
47
  end
50
48
 
51
49
 
52
50
  def run_and_reject(config,times,branch)
53
- mock(Git).mailing_list_address { 'recipient@test.com' }
51
+ mock(GitCommitNotifier::Git).mailing_list_address { 'recipient@test.com' }
54
52
 
55
53
  emailer = mock!.send.times(times).subject
56
- mock(Emailer).new(anything, anything).times(times)
54
+ mock(GitCommitNotifier::Emailer).new(anything, anything).times(times)
57
55
 
58
- mock(CommitHook).info(/Supressing mail for branch/)
56
+ mock(GitCommitNotifier::CommitHook).info(/Supressing mail for branch/)
59
57
 
60
- CommitHook.run config, REVISIONS.first, REVISIONS.last, branch
58
+ GitCommitNotifier::CommitHook.run config, REVISIONS.first, REVISIONS.last, branch
61
59
  end
62
60
 
63
61
 
@@ -65,23 +63,23 @@ describe CommitHook do
65
63
  # 1 commit with a from: adress
66
64
  expect_repository_access
67
65
  emailer = mock!.send.subject
68
- mock(Emailer).new(anything, hash_including(:from_address => "max@example.com")) { emailer }
66
+ mock(GitCommitNotifier::Emailer).new(anything, hash_including(:from_address => "max@example.com")) { emailer }
69
67
 
70
- CommitHook.run 'spec/fixtures/git-notifier-group-email-by-push.yml', REVISIONS.first, REVISIONS.last, 'refs/heads/master'
68
+ GitCommitNotifier::CommitHook.run 'spec/fixtures/git-notifier-group-email-by-push.yml', REVISIONS.first, REVISIONS.last, 'refs/heads/master'
71
69
  end
72
70
 
73
71
  def expect_repository_access
74
- mock(Git).log(REVISIONS.first, REVISIONS.last) { IO.read(FIXTURES_PATH + 'git_log') }
75
- mock(Git).mailing_list_address { 'recipient@test.com' }
72
+ mock(GitCommitNotifier::Git).log(REVISIONS.first, REVISIONS.last) { IO.read(FIXTURES_PATH + 'git_log') }
73
+ mock(GitCommitNotifier::Git).mailing_list_address { 'recipient@test.com' }
76
74
  REVISIONS.each do |rev|
77
- mock(Git).show(rev) { IO.read(FIXTURES_PATH + "git_show_#{rev}") }
75
+ mock(GitCommitNotifier::Git).show(rev) { IO.read(FIXTURES_PATH + "git_show_#{rev}") }
78
76
  end
79
77
  end
80
78
 
81
79
  describe :logger do
82
- it "should be nstance of logger" do
83
- stub(CommitHook).config { {} }
84
- CommitHook.logger.should be_kind_of(Logger)
80
+ it "should be instance of logger" do
81
+ stub(GitCommitNotifier::CommitHook).config { {} }
82
+ GitCommitNotifier::CommitHook.logger.should be_kind_of(GitCommitNotifier::Logger)
85
83
  end
86
84
  end
87
85
 
@@ -90,7 +88,7 @@ describe CommitHook do
90
88
  mock($stderr).puts("\n").times(2)
91
89
  mock($stderr).puts(/GIT\sNOTIFIER\sPROBLEM/).times(2)
92
90
  mock($stderr).puts('yes')
93
- CommitHook.show_error('yes')
91
+ GitCommitNotifier::CommitHook.show_error('yes')
94
92
  end
95
93
  end
96
94
 
@@ -98,16 +96,16 @@ describe CommitHook do
98
96
  it "should write to and flush stdout" do
99
97
  mock($stdout).puts('msg')
100
98
  mock($stdout).flush
101
- CommitHook.info('msg')
99
+ GitCommitNotifier::CommitHook.info('msg')
102
100
  end
103
101
  end
104
102
 
105
103
  describe :run do
106
104
  it "should report error when no recipients specified" do
107
105
  mock(File).exists?(:noconfig) { false }
108
- mock(Git).mailing_list_address { nil }
109
- mock(CommitHook).show_error(/recipient/)
110
- CommitHook.run(:noconfig, :rev1, :rev2, 'master')
106
+ mock(GitCommitNotifier::Git).mailing_list_address { nil }
107
+ mock(GitCommitNotifier::CommitHook).show_error(/recipient/)
108
+ GitCommitNotifier::CommitHook.run(:noconfig, :rev1, :rev2, 'master')
111
109
  end
112
110
  end
113
111
 
@@ -2,13 +2,11 @@ require File.expand_path('../../../spec_helper', __FILE__)
2
2
  require 'nokogiri'
3
3
  require 'git_commit_notifier'
4
4
 
5
- include GitCommitNotifier
6
-
7
- describe DiffToHtml do
5
+ describe GitCommitNotifier::DiffToHtml do
8
6
 
9
7
  describe :lines_are_sequential? do
10
8
  before(:all) do
11
- @diff_to_html = DiffToHtml.new
9
+ @diff_to_html = GitCommitNotifier::DiffToHtml.new
12
10
  end
13
11
 
14
12
  it "should be true if left line numbers are sequential" do
@@ -74,25 +72,25 @@ describe DiffToHtml do
74
72
 
75
73
  describe :unique_commits_per_branch? do
76
74
  it "should be false unless specified in config" do
77
- diff = DiffToHtml.new(nil, {})
75
+ diff = GitCommitNotifier::DiffToHtml.new(nil, {})
78
76
  diff.should_not be_unique_commits_per_branch
79
77
  end
80
78
 
81
79
  it "should be false if specified as false in config" do
82
- diff = DiffToHtml.new(nil, { 'unique_commits_per_branch' => false })
80
+ diff = GitCommitNotifier::DiffToHtml.new(nil, { 'unique_commits_per_branch' => false })
83
81
  diff.should_not be_unique_commits_per_branch
84
82
  end
85
83
 
86
84
  it "should be true if specified as true in config" do
87
- diff = DiffToHtml.new(nil, { 'unique_commits_per_branch' => true })
85
+ diff = GitCommitNotifier::DiffToHtml.new(nil, { 'unique_commits_per_branch' => true })
88
86
  diff.should be_unique_commits_per_branch
89
87
  end
90
88
  end
91
89
 
92
90
  describe :get_previous_commits do
93
91
  it "should read and parse previous file if it exists" do
94
- fn = DiffToHtml::HANDLED_COMMITS_FILE
95
- diff = DiffToHtml.new
92
+ fn = GitCommitNotifier::DiffToHtml::HANDLED_COMMITS_FILE
93
+ diff = GitCommitNotifier::DiffToHtml.new
96
94
  mock(File).exists?(fn) { true }
97
95
  mock(IO).read(fn) { "a\nb" }
98
96
  diff.get_previous_commits(fn).should == %w[a b]
@@ -100,12 +98,12 @@ describe DiffToHtml do
100
98
  end
101
99
 
102
100
  it "multiple commits" do
103
- mock(Git).log(REVISIONS.first, REVISIONS.last) { IO.read(FIXTURES_PATH + 'git_log') }
101
+ mock(GitCommitNotifier::Git).log(REVISIONS.first, REVISIONS.last) { IO.read(FIXTURES_PATH + 'git_log') }
104
102
  REVISIONS.each do |rev|
105
- mock(Git).show(rev) { IO.read(FIXTURES_PATH + 'git_show_' + rev) }
103
+ mock(GitCommitNotifier::Git).show(rev) { IO.read(FIXTURES_PATH + 'git_show_' + rev) }
106
104
  end
107
105
 
108
- diff = DiffToHtml.new
106
+ diff = GitCommitNotifier::DiffToHtml.new
109
107
  mock(diff).check_handled_commits(anything) { |commits| commits }
110
108
  diff.diff_between_revisions REVISIONS.first, REVISIONS.last, 'testproject', 'master'
111
109
 
@@ -152,11 +150,11 @@ describe DiffToHtml do
152
150
 
153
151
  it "should get good diff when new branch created" do
154
152
  first_rev, last_rev = %w[ 0000000000000000000000000000000000000000 9b15cebcc5434e27c00a4a2acea43509f9faea21 ]
155
- mock(Git).branch_commits('rvm') { %w[ ff037a73fc1094455e7bbf506171a3f3cf873ae6 ] }
153
+ mock(GitCommitNotifier::Git).branch_commits('rvm') { %w[ ff037a73fc1094455e7bbf506171a3f3cf873ae6 ] }
156
154
  %w[ ff037a73fc1094455e7bbf506171a3f3cf873ae6 ].each do |rev|
157
- mock(Git).show(rev) { IO.read(FIXTURES_PATH + 'git_show_' + rev) }
155
+ mock(GitCommitNotifier::Git).show(rev) { IO.read(FIXTURES_PATH + 'git_show_' + rev) }
158
156
  end
159
- diff = DiffToHtml.new
157
+ diff = GitCommitNotifier::DiffToHtml.new
160
158
  mock(diff).check_handled_commits(anything) { |commits| commits }
161
159
  diff.diff_between_revisions(first_rev, last_rev, 'tm-admin', 'rvm')
162
160
  diff.result.should have(1).commit
@@ -167,7 +165,7 @@ describe DiffToHtml do
167
165
 
168
166
  describe :message_map do
169
167
  before(:each) do
170
- @diff = DiffToHtml.new
168
+ @diff = GitCommitNotifier::DiffToHtml.new
171
169
  end
172
170
 
173
171
  it "should do message mapping" do
@@ -186,18 +184,9 @@ describe DiffToHtml do
186
184
  describe :do_message_integration do
187
185
  before(:each) do
188
186
  @config = Hash.new
189
- @diff = DiffToHtml.new(nil, @config)
190
- end
191
- =begin
192
- return message unless @config['message_integration'].respond_to?(:each_pair)
193
- @config['message_integration'].each_pair do |pm, url|
194
- pm_def = DiffToHtml::INTEGRATION_MAP[pm.to_sym] or next
195
- replace_with = pm_def[:replace_with]
196
- replace_with = replace_with.kind_of?(Proc) ? lambda { |m| pm_def[:replace_with].call(m, url) } : replace_with.gsub('#{url}', url)
197
- message_replace!(message, pm_def[:search_for], replace_with)
198
- end
199
- message
200
- =end
187
+ @diff = GitCommitNotifier::DiffToHtml.new(nil, @config)
188
+ end
189
+
201
190
  it "should do nothing unless message_integration config section exists" do
202
191
  mock.proxy(nil).respond_to?(:each_pair)
203
192
  dont_allow(@diff).message_replace!
@@ -215,7 +204,7 @@ describe DiffToHtml do
215
204
  describe :old_commit? do
216
205
  before(:each) do
217
206
  @config = Hash.new
218
- @diff_to_html = DiffToHtml.new(nil, @config)
207
+ @diff_to_html = GitCommitNotifier::DiffToHtml.new(nil, @config)
219
208
  end
220
209
 
221
210
  it "should be false unless skip_commits_older_than set" do
@@ -239,8 +228,7 @@ describe DiffToHtml do
239
228
 
240
229
  it "should be true if commit is older than required by skip_commits_older_than" do
241
230
  @config['skip_commits_older_than'] = 1
242
- @diff_to_html.old_commit?({:date => (Time.now - 2 * DiffToHtml::SECS_PER_DAY).to_s}).should be_true
231
+ @diff_to_html.old_commit?({:date => (Time.now - 2 * GitCommitNotifier::DiffToHtml::SECS_PER_DAY).to_s}).should be_true
243
232
  end
244
233
  end
245
-
246
234
  end
@@ -2,26 +2,24 @@ require File.expand_path('../../../spec_helper', __FILE__)
2
2
 
3
3
  require 'git_commit_notifier'
4
4
 
5
- include GitCommitNotifier
6
-
7
- describe Emailer do
5
+ describe GitCommitNotifier::Emailer do
8
6
  describe :new do
9
7
  it "should assign config if given" do
10
- Emailer.new({:a => :b}).config[:a].should == :b
8
+ GitCommitNotifier::Emailer.new({:a => :b}).config[:a].should == :b
11
9
  end
12
10
 
13
11
  it "should use empty hash unless config given" do
14
- cfg = Emailer.new(false).config
12
+ cfg = GitCommitNotifier::Emailer.new(false).config
15
13
  cfg.should be_kind_of(Hash)
16
14
  cfg.should be_empty
17
15
  end
18
16
 
19
17
  it "should assign parameters from options" do
20
18
  options = {}
21
- Emailer::PARAMETERS.each do |name|
19
+ GitCommitNotifier::Emailer::PARAMETERS.each do |name|
22
20
  options[name.to_sym] = Faker::Lorem.sentence
23
21
  end
24
- emailer = Emailer.new({}, options)
22
+ emailer = GitCommitNotifier::Emailer.new({}, options)
25
23
  options.each_pair do |key, value|
26
24
  emailer.instance_variable_get("@#{key}").should == value
27
25
  end
@@ -30,15 +28,15 @@ describe Emailer do
30
28
 
31
29
  describe :stylesheet_string do
32
30
  it "should return default stylesheet if custom is not provided" do
33
- emailer = Emailer.new({})
34
- mock(IO).read(Emailer::DEFAULT_STYLESHEET_PATH) { 'ok' }
31
+ emailer = GitCommitNotifier::Emailer.new({})
32
+ mock(IO).read(GitCommitNotifier::Emailer::DEFAULT_STYLESHEET_PATH) { 'ok' }
35
33
  emailer.stylesheet_string.should == 'ok'
36
34
  end
37
35
 
38
36
  it "should return custom stylesheet if custom is provided" do
39
- emailer = Emailer.new({'stylesheet' => '/path/to/custom/stylesheet'})
37
+ emailer = GitCommitNotifier::Emailer.new({'stylesheet' => '/path/to/custom/stylesheet'})
40
38
  mock(IO).read('/path/to/custom/stylesheet') { 'ok' }
41
- dont_allow(IO).read(Emailer::DEFAULT_STYLESHEET_PATH)
39
+ dont_allow(IO).read(GitCommitNotifier::Emailer::DEFAULT_STYLESHEET_PATH)
42
40
  emailer.stylesheet_string.should == 'ok'
43
41
  end
44
42
  end
@@ -46,27 +44,27 @@ describe Emailer do
46
44
  describe :mail_html_message do
47
45
  it "should form inline html" do
48
46
  options = {}
49
- Emailer::PARAMETERS.each do |name|
47
+ GitCommitNotifier::Emailer::PARAMETERS.each do |name|
50
48
  options[name.to_sym] = Faker::Lorem.sentence
51
49
  end
52
- emailer = Emailer.new({}, options)
50
+ emailer = GitCommitNotifier::Emailer.new({}, options)
53
51
  emailer.mail_html_message.should match(/html/)
54
52
  end
55
53
  end
56
54
 
57
55
  describe :template do
58
56
  before(:each) do
59
- Emailer.reset_template
60
- mock(IO).read(Emailer::TEMPLATE) { 'erb' }
57
+ GitCommitNotifier::Emailer.reset_template
58
+ mock(IO).read(GitCommitNotifier::Emailer::TEMPLATE) { 'erb' }
61
59
  end
62
60
 
63
61
  it "should respond to result" do
64
- Emailer.template.should respond_to(:result)
62
+ GitCommitNotifier::Emailer.template.should respond_to(:result)
65
63
  end
66
64
 
67
65
  it "should return Erubis template if Erubis installed" do
68
- mock(Emailer).require('erubis')
69
- dont_allow(Emailer).require('erb')
66
+ mock(GitCommitNotifier::Emailer).require('erubis')
67
+ dont_allow(GitCommitNotifier::Emailer).require('erb')
70
68
  unless defined?(Erubis)
71
69
  module Erubis
72
70
  class Eruby
@@ -76,16 +74,16 @@ describe Emailer do
76
74
  end
77
75
  end
78
76
  mock.proxy(Erubis::Eruby).new('erb')
79
- Emailer.template.should be_kind_of(Erubis::Eruby)
77
+ GitCommitNotifier::Emailer.template.should be_kind_of(Erubis::Eruby)
80
78
  end
81
79
 
82
80
  it "should return ERB template unless Erubis installed" do
83
81
  require 'erb'
84
- mock(Emailer).require('erubis') { raise LoadError.new('erubis') }
85
- mock(Emailer).require('erb')
82
+ mock(GitCommitNotifier::Emailer).require('erubis') { raise LoadError.new('erubis') }
83
+ mock(GitCommitNotifier::Emailer).require('erb')
86
84
  mock.proxy(ERB).new('erb')
87
85
 
88
- Emailer.template.should be_kind_of(ERB)
86
+ GitCommitNotifier::Emailer.template.should be_kind_of(ERB)
89
87
  end
90
88
  end
91
89
  end
@@ -1,42 +1,40 @@
1
1
  require File.expand_path('../../../spec_helper', __FILE__)
2
2
  require 'git_commit_notifier'
3
3
 
4
- include GitCommitNotifier
5
-
6
- describe Git do
4
+ describe GitCommitNotifier::Git do
7
5
  SAMPLE_REV = '51b986619d88f7ba98be7d271188785cbbb541a0'.freeze
8
6
  SAMPLE_REV_2 = '62b986619d88f7ba98be7d271188785cbbb541b1'.freeze
9
7
 
10
8
  describe :from_shell do
11
9
  it "should be backtick" do
12
- Git.from_shell('pwd').should == `pwd`
10
+ GitCommitNotifier::Git.from_shell('pwd').should == `pwd`
13
11
  end
14
12
  end
15
13
 
16
14
  describe :show do
17
15
  it "should get data from shell: git show" do
18
16
  expected = 'some data from git show'
19
- mock(Git).from_shell("git show #{SAMPLE_REV} -w") { expected }
20
- Git.show(SAMPLE_REV).should == expected
17
+ mock(GitCommitNotifier::Git).from_shell("git show #{SAMPLE_REV} -w") { expected }
18
+ GitCommitNotifier::Git.show(SAMPLE_REV).should == expected
21
19
  end
22
20
 
23
21
  it "should strip given revision" do
24
- mock(Git).from_shell("git show #{SAMPLE_REV} -w")
25
- Git.show("#{SAMPLE_REV}\n")
22
+ mock(GitCommitNotifier::Git).from_shell("git show #{SAMPLE_REV} -w")
23
+ GitCommitNotifier::Git.show("#{SAMPLE_REV}\n")
26
24
  end
27
25
  end
28
26
 
29
27
  describe :branch_heads do
30
28
  before(:each) do
31
- mock(Git).from_shell("git rev-parse --branches") { "some\npopular\ntext\n" }
29
+ mock(GitCommitNotifier::Git).from_shell("git rev-parse --branches") { "some\npopular\ntext\n" }
32
30
  end
33
31
 
34
32
  it "should get branch heads from shell" do
35
- lambda { Git.branch_heads }.should_not raise_error
33
+ lambda { GitCommitNotifier::Git.branch_heads }.should_not raise_error
36
34
  end
37
35
 
38
36
  it "should return array of lines" do
39
- Git.branch_heads.should == %w[ some popular text ]
37
+ GitCommitNotifier::Git.branch_heads.should == %w[ some popular text ]
40
38
  end
41
39
  end
42
40
 
@@ -49,42 +47,42 @@ describe Git do
49
47
 
50
48
  it "should return hooks.emailprefix if it's not empty" do
51
49
  expected = "name of repo"
52
- mock(Git).from_shell("git config hooks.emailprefix") { expected }
50
+ mock(GitCommitNotifier::Git).from_shell("git config hooks.emailprefix") { expected }
53
51
  dont_allow(Dir).pwd
54
- Git.repo_name.should == expected
52
+ GitCommitNotifier::Git.repo_name.should == expected
55
53
  end
56
54
 
57
55
  it "should return folder name if no emailprefix and directory not ended with .git" do
58
- mock(Git).from_shell("git config hooks.emailprefix") { " " }
56
+ mock(GitCommitNotifier::Git).from_shell("git config hooks.emailprefix") { " " }
59
57
  mock(Dir).pwd { "/home/someuser/repositories/myrepo" }
60
- Git.repo_name.should == "myrepo"
58
+ GitCommitNotifier::Git.repo_name.should == "myrepo"
61
59
  end
62
60
 
63
61
  it "should return folder name without extension if no emailprefix and directory ended with .git" do
64
- mock(Git).from_shell("git config hooks.emailprefix") { " " }
62
+ mock(GitCommitNotifier::Git).from_shell("git config hooks.emailprefix") { " " }
65
63
  mock(Dir).pwd { "/home/someuser/repositories/myrepo.git" }
66
- Git.repo_name.should == "myrepo"
64
+ GitCommitNotifier::Git.repo_name.should == "myrepo"
67
65
  end
68
66
  end
69
67
 
70
68
  describe :log do
71
69
  it "should run git log with given args" do
72
- mock(Git).from_shell("git log #{SAMPLE_REV}..#{SAMPLE_REV_2}") { " ok " }
73
- Git.log(SAMPLE_REV, SAMPLE_REV_2).should == "ok"
70
+ mock(GitCommitNotifier::Git).from_shell("git log #{SAMPLE_REV}..#{SAMPLE_REV_2}") { " ok " }
71
+ GitCommitNotifier::Git.log(SAMPLE_REV, SAMPLE_REV_2).should == "ok"
74
72
  end
75
73
  end
76
74
 
77
75
  describe :branch_head do
78
76
  it "should run git rev-parse with given treeish" do
79
- mock(Git).from_shell("git rev-parse #{SAMPLE_REV}") { " ok " }
80
- Git.branch_head(SAMPLE_REV).should == "ok"
77
+ mock(GitCommitNotifier::Git).from_shell("git rev-parse #{SAMPLE_REV}") { " ok " }
78
+ GitCommitNotifier::Git.branch_head(SAMPLE_REV).should == "ok"
81
79
  end
82
80
  end
83
81
 
84
82
  describe :mailing_list_address do
85
83
  it "should run git config hooks.mailinglist" do
86
- mock(Git).from_shell("git config hooks.mailinglist") { " ok " }
87
- Git.mailing_list_address.should == "ok"
84
+ mock(GitCommitNotifier::Git).from_shell("git config hooks.mailinglist") { " ok " }
85
+ GitCommitNotifier::Git.mailing_list_address.should == "ok"
88
86
  end
89
87
  end
90
88
 
@@ -1,60 +1,59 @@
1
1
  require File.expand_path('../../../spec_helper', __FILE__)
2
2
  require 'git_commit_notifier'
3
3
 
4
- include GitCommitNotifier
5
-
6
- describe Logger do
4
+ describe GitCommitNotifier::Logger do
7
5
  describe :debug? do
8
6
  it "should be false unless debug section exists" do
9
- logger = Logger.new({})
7
+ logger = GitCommitNotifier::Logger.new({})
10
8
  logger.should_not be_debug
11
9
  end
12
10
 
13
11
  it "should be false unless debug/enabled" do
14
- logger = Logger.new("debug" => { "enabled" => false })
12
+ logger = GitCommitNotifier::Logger.new("debug" => { "enabled" => false })
15
13
  logger.should_not be_debug
16
14
  end
17
15
 
18
16
  it "should be true if debug/enabled" do
19
- logger = Logger.new("debug" => { "enabled" => true })
17
+ logger = GitCommitNotifier::Logger.new("debug" => { "enabled" => true })
20
18
  logger.should be_debug
21
19
  end
22
20
  end
23
21
 
24
22
  describe :log_directory do
25
23
  it "should be nil unless debug?" do
26
- logger = Logger.new({})
24
+ logger = GitCommitNotifier::Logger.new({})
27
25
  logger.should_not be_debug
28
26
  logger.log_directory.should be_nil
29
27
  end
30
28
 
31
29
  it "should be custom if debug and custom directory specified" do
32
30
  expected = Faker::Lorem.sentence
33
- logger = Logger.new("debug" => { "enabled" => true, "log_directory" => expected})
31
+ logger = GitCommitNotifier::Logger.new("debug" => { "enabled" => true, "log_directory" => expected})
34
32
  logger.log_directory.should == expected
35
33
  end
36
34
 
37
35
  it "should be default log directory if debug and custom directory not specified" do
38
- logger = Logger.new("debug" => { "enabled" => true })
39
- logger.log_directory.should == Logger::DEFAULT_LOG_DIRECTORY
36
+ logger = GitCommitNotifier::Logger.new("debug" => { "enabled" => true })
37
+ logger.log_directory.should == GitCommitNotifier::Logger::DEFAULT_LOG_DIRECTORY
40
38
  end
41
39
  end
42
40
 
43
41
  describe :log_path do
44
42
  it "should be nil unless debug?" do
45
- logger = Logger.new({})
43
+ logger = GitCommitNotifier::Logger.new({})
46
44
  mock(logger).debug? { false }
47
45
  logger.log_path.should be_nil
48
46
  end
49
47
 
50
48
  it "should be path in log_directory if debug?" do
51
- logger = Logger.new("debug" => { "enabled" => true })
49
+ logger = GitCommitNotifier::Logger.new("debug" => { "enabled" => true })
52
50
  File.dirname(logger.log_path).should == logger.log_directory
53
51
  end
54
52
 
55
53
  it "should points to LOG_NAME if debug?" do
56
- logger = Logger.new("debug" => { "enabled" => true })
57
- File.basename(logger.log_path).should == Logger::LOG_NAME
54
+ logger = GitCommitNotifier::Logger.new("debug" => { "enabled" => true })
55
+ File.basename(logger.log_path).should == GitCommitNotifier::Logger::LOG_NAME
58
56
  end
59
57
  end
60
58
  end
59
+
@@ -3,15 +3,13 @@
3
3
  require File.expand_path('../../../spec_helper', __FILE__)
4
4
  require 'git_commit_notifier'
5
5
 
6
- include GitCommitNotifier
7
-
8
- describe ResultProcessor do
6
+ describe GitCommitNotifier::ResultProcessor do
9
7
  before(:all) do
10
8
  create_test_input
11
9
  end
12
10
 
13
11
  it :processor do
14
- processor = ResultProcessor.new(@diff)
12
+ processor = GitCommitNotifier::ResultProcessor.new(@diff)
15
13
  removal, addition = processor.results
16
14
  removal.should have(1).line
17
15
 
@@ -34,7 +32,7 @@ describe ResultProcessor do
34
32
  { :action => :match, :token => 'x' }
35
33
  ]
36
34
 
37
- processor = ResultProcessor.new(@diff)
35
+ processor = GitCommitNotifier::ResultProcessor.new(@diff)
38
36
  removal, addition = processor.results
39
37
 
40
38
  removal.should have(1).line
@@ -59,7 +57,7 @@ describe ResultProcessor do
59
57
  diff << { :action => :discard_b, :token => 'u' }
60
58
  diff << { :action => :discard_b, :token => 'b' }
61
59
 
62
- processor = ResultProcessor.new(diff)
60
+ processor = GitCommitNotifier::ResultProcessor.new(diff)
63
61
  removal, addition = processor.results
64
62
 
65
63
  removal.should have(1).line
@@ -96,7 +94,7 @@ describe ResultProcessor do
96
94
 
97
95
  describe :length_in_chars do
98
96
  it "should be unicode friendly" do
99
- processor = ResultProcessor.new(@diff)
97
+ processor = GitCommitNotifier::ResultProcessor.new(@diff)
100
98
  processor.length_in_chars([{ :token => 'японская мама' }]).should == 13
101
99
  end
102
100
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 0
9
- version: 0.9.0
8
+ - 1
9
+ version: 0.9.1
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: 2011-04-04 00:00:00 +02:00
17
+ date: 2011-04-05 00:00:00 +02:00
18
18
  default_executable: git-commit-notifier
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -268,9 +268,11 @@ files:
268
268
  - lib/git_commit_notifier/diff_to_html.rb
269
269
  - lib/git_commit_notifier/emailer.rb
270
270
  - lib/git_commit_notifier/escape_helper.rb
271
+ - lib/git_commit_notifier/executor.rb
271
272
  - lib/git_commit_notifier/git.rb
272
273
  - lib/git_commit_notifier/logger.rb
273
274
  - lib/git_commit_notifier/result_processor.rb
275
+ - local-run.rb
274
276
  - spec/fixtures/existing_file_one_line.txt
275
277
  - spec/fixtures/git-notifier-group-email-by-push.yml
276
278
  - spec/fixtures/git-notifier-ignore-merge.yml