Skip to content

Commit aab67c6

Browse files
committed
Notify each commit in one push
1 parent 7ebe06d commit aab67c6

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

bin/commit-email.rb

+14-12
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ def initialize(repo_path)
2626
@repo_path = repo_path
2727
end
2828

29-
# TODO: should we generate info for each revision between oldrev and newrev?
30-
def build(_oldrev, newrev, refname)
31-
diffs = build_diffs(newrev)
29+
def build(oldrev, newrev, refname)
30+
diffs = build_diffs(oldrev, newrev)
3231

3332
info = CommitEmailInfo.new
3433
info.author = git_show(newrev, format: '%an')
@@ -81,14 +80,13 @@ def find_files(diffs, status:)
8180
# }
8281
# }
8382
# }
84-
def build_diffs(revision)
83+
def build_diffs(oldrev, newrev)
8584
diffs = {}
8685

87-
# Using "#{revision}^" instead of oldrev to exclude diff from unrelated revision
88-
numstats = git('diff', '--numstat', "#{revision}^", revision).lines.map { |l| l.strip.split("\t", 3) }
89-
git('diff', '--name-status', "#{revision}^", revision).each_line do |line|
86+
numstats = git('diff', '--numstat', oldrev, newrev).lines.map { |l| l.strip.split("\t", 3) }
87+
git('diff', '--name-status', oldrev, newrev).each_line do |line|
9088
status, path, _newpath = line.strip.split("\t", 3)
91-
diff = build_diff(revision, path, numstats)
89+
diff = build_diff(path, numstats)
9290

9391
case status
9492
when 'A'
@@ -109,7 +107,7 @@ def build_diffs(revision)
109107
diffs
110108
end
111109

112-
def build_diff(revision, path, numstats)
110+
def build_diff(path, numstats)
113111
diff = { added: 0, deleted: 0 } # :body not implemented because not used
114112
line = numstats.find { |(_added, _deleted, file, *)| file == path }
115113
return diff if line.nil?
@@ -468,9 +466,11 @@ def main(repo_path, to, rest)
468466
end
469467
]
470468
when "git"
471-
infos = args.each_slice(3).map do |oldrev, newrev, refname|
472-
p [oldrev, newrev, refname]
473-
GitInfoBuilder.new(repo_path).build(oldrev, newrev, refname)
469+
infos = args.each_slice(3).flat_map do |oldrev, newrev, refname|
470+
revisions = IO.popen(['git', 'log', '--pretty=%H', "#{oldrev}^..#{newrev}"], &:read).lines.map(&:strip)
471+
revisions[0..-2].zip(revisions[1..-1]).map do |old, new|
472+
GitInfoBuilder.new(repo_path).build(old, new, refname)
473+
end
474474
end
475475
else
476476
raise "unsupported vcs #{options.vcs.inspect} is specified"
@@ -483,6 +483,8 @@ def main(repo_path, to, rest)
483483
}
484484
to = [to, *options.to]
485485
infos.each do |info|
486+
puts "#{info.branches.join(', ')}: #{info.revision} (#{info.author})"
487+
486488
from = options.from || info.author_email
487489
sendmail(to, from, make_mail(to, from, info, params))
488490

0 commit comments

Comments
 (0)