git-commit-notifier 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +21 -0
- data/Gemfile.lock +105 -0
- data/README.textile +6 -1
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/bin/git-commit-notifier +3 -1
- data/config/git-notifier-config.yml.sample +28 -4
- data/git-commit-notifier.gemspec +81 -56
- data/lib/git_commit_notifier.rb +8 -0
- data/lib/git_commit_notifier/commit_hook.rb +130 -0
- data/lib/git_commit_notifier/diff_callback.rb +22 -0
- data/lib/git_commit_notifier/diff_to_html.rb +471 -0
- data/lib/{emailer.rb → git_commit_notifier/emailer.rb} +47 -31
- data/lib/git_commit_notifier/escape_helper.rb +5 -0
- data/lib/{git.rb → git_commit_notifier/git.rb} +1 -1
- data/lib/{logger.rb → git_commit_notifier/logger.rb} +1 -1
- data/lib/git_commit_notifier/result_processor.rb +131 -0
- data/spec/fixtures/git-notifier-with-branch-restrictions.yml +22 -0
- data/spec/lib/{commit_hook_spec.rb → git_commit_notifier/commit_hook_spec.rb} +37 -11
- data/spec/lib/{diff_to_html_spec.rb → git_commit_notifier/diff_to_html_spec.rb} +94 -16
- data/spec/lib/{emailer_spec.rb → git_commit_notifier/emailer_spec.rb} +9 -20
- data/spec/lib/{git_spec.rb → git_commit_notifier/git_spec.rb} +4 -6
- data/spec/lib/{logger_spec.rb → git_commit_notifier/logger_spec.rb} +4 -7
- data/spec/lib/{result_processor_spec.rb → git_commit_notifier/result_processor_spec.rb} +4 -2
- data/template/email.html.erb +1 -1
- metadata +150 -50
- data/.gitignore +0 -21
- data/lib/commit_hook.rb +0 -129
- data/lib/diff_to_html.rb +0 -449
- data/lib/result_processor.rb +0 -126
data/lib/result_processor.rb
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
require 'cgi'
|
2
|
-
|
3
|
-
class ResultProcessor
|
4
|
-
# input (loaded in @diff) is an array having Hash elements:
|
5
|
-
# { :action => action, :token => string }
|
6
|
-
# action can be :discard_a, :discard_b or :match
|
7
|
-
|
8
|
-
# output: two formatted html strings, one for the removals and one for the additions
|
9
|
-
|
10
|
-
def results
|
11
|
-
close_tags # close last tag
|
12
|
-
[array_of_lines(@result[:removal]), array_of_lines(@result[:addition])]
|
13
|
-
end
|
14
|
-
|
15
|
-
def length_in_chars(diff)
|
16
|
-
diff.inject(0) do |length, s|
|
17
|
-
token = s[:token]
|
18
|
-
token_length = token.respond_to?(:jlength) ? token.jlength : token.length
|
19
|
-
length + token_length
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def initialize(diff)
|
26
|
-
@diff = diff
|
27
|
-
init
|
28
|
-
filter_replaced_lines
|
29
|
-
process
|
30
|
-
end
|
31
|
-
|
32
|
-
def init
|
33
|
-
@result = { :addition => [], :removal => [] }
|
34
|
-
@tag_open = { :addition => false, :removal => false}
|
35
|
-
end
|
36
|
-
|
37
|
-
def process
|
38
|
-
@highlight = !@diff.select { |d| d[:action] == :match}.empty? # highlight only if block contains both matches and differences
|
39
|
-
@diff.each do |diff|
|
40
|
-
case diff[:action]
|
41
|
-
when :match
|
42
|
-
match(diff)
|
43
|
-
when :discard_a
|
44
|
-
discard_a(diff)
|
45
|
-
when :discard_b
|
46
|
-
discard_b(diff)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def discard_match(position, token)
|
52
|
-
# replace it with 2 changes
|
53
|
-
@diff[position][:action] = :discard_a
|
54
|
-
@diff.insert(position, { :action => :discard_b, :token => token} )
|
55
|
-
end
|
56
|
-
|
57
|
-
def filter_replaced_lines
|
58
|
-
# if a block is replaced by an other one, lcs-diff will find even the single common word between the old and the new content
|
59
|
-
# no need for intelligent diff in this case, simply show the removed and the added block with no highlighting
|
60
|
-
# rule: if less than 33% of a block is not a match, we don't need intelligent diff for that block
|
61
|
-
match_length = length_in_chars(@diff.select { |d| d[:action] == :match })
|
62
|
-
total_length = length_in_chars(@diff)
|
63
|
-
|
64
|
-
if total_length.to_f / match_length > 3.3
|
65
|
-
@diff.each_with_index do |d, i|
|
66
|
-
next if d[:action] != :match
|
67
|
-
discard_match(i, d[:token])
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def match(diff)
|
73
|
-
close_tags
|
74
|
-
all_actions do |action|
|
75
|
-
close_last_tag(diff)
|
76
|
-
@result[action] << escape_content(diff[:token])
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def discard_a(diff)
|
81
|
-
open_tag(:removal, diff[:token])
|
82
|
-
close_last_tag(diff)
|
83
|
-
@result[:removal] << escape_content(diff[:token])
|
84
|
-
end
|
85
|
-
|
86
|
-
def discard_b(diff)
|
87
|
-
open_tag(:addition, diff[:token])
|
88
|
-
close_last_tag(diff)
|
89
|
-
@result[:addition] << escape_content(diff[:token])
|
90
|
-
end
|
91
|
-
|
92
|
-
def all_actions
|
93
|
-
[:addition, :removal].each do |action|
|
94
|
-
yield(action)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def open_tag(action, next_token)
|
99
|
-
return if !@highlight || next_token.strip.empty? # don't open span tag if no highlighting is needed or the first token is empty
|
100
|
-
unless @tag_open[action]
|
101
|
-
klass = action == :addition ? 'aa' : 'rr'
|
102
|
-
@result[action] << "<span class=\"#{klass}\">"
|
103
|
-
@tag_open[action] = true
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def close_tags
|
108
|
-
return unless @highlight
|
109
|
-
all_actions do |action|
|
110
|
-
if @tag_open[action]
|
111
|
-
@result[action] << "</span>"
|
112
|
-
@tag_open[action] = false
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def close_last_tag(diff)
|
118
|
-
return unless @highlight
|
119
|
-
close_tags if diff[:token] == "\n"
|
120
|
-
end
|
121
|
-
|
122
|
-
def array_of_lines(tokens)
|
123
|
-
tokens.join('').split("\n")
|
124
|
-
end
|
125
|
-
|
126
|
-
end
|