Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit 0d3b4368b31024a49bc98b25a1a4488bdc502a0e

Send commit notification emails for pootle commits
  
9292 @body[:notification_body] = notification_body
9393 end
9494
95 def commit_notification(user, subject, notification_body)
96 setup_email(user)
97 @subject += subject
98 @body[:user] = user
99 @body[:notification_body] = notification_body
100 end
101
95102 protected
96103 def setup_email(user)
97104 @recipients = "#{user.email}"
  
1<%= @notification_body %>
  
1<%= @notification_body %>
  
1# encoding: utf-8
2#--
3# Copyright (C) 2011, Aleksey Lim
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Affero General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU Affero General Public License for more details.
14#
15# You should have received a copy of the GNU Affero General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17#++
18
19module Emailer
20 def notify_emailer(repository, branch, events)
21 events.each do |event|
22 next unless event.commit_details[:committer].login == 'pootle'
23
24 sha = event.commit_details[:id]
25 author = event.commit_details[:commit_author]
26
27 begin
28 files = []
29 Grit::Git.with_timeout(0) do
30 files += repository.git.commit(sha).diffs.map {|i| i.a_path}
31 end
32 langs = files.collect {|i| next unless i =~ /^po\/(.*).po$/; $1}.compact.join(', ')
33 rescue Exception => e
34 logger.warn("Failed to get git diff to compose poole commit files: #{e}")
35 files = []
36 langs = "unknown languages"
37 end
38
39 event.commit_details[:message] =~ / by user ([^\s:]+)/
40 translator = $1 or '<anonymous>'
41
42 subject = "Commit to [#{repository.project.title}] by [#{translator}] for [#{langs}]"
43 body = <<"EOF"
44Project: #{repository.project.title}
45Repository: #{repository.title}
46Branch: #{branch}
47
48Author: #{author}
49Timestamp: #{event.commit_time}
50Url: http://#{GitoriousConfig['gitorious_host']}/#{repository.url_path}/commit/#{event.commit_details[:id]}
51
52#{event.commit_details[:message]}
53
54#{files.map {|i| "- #{i}"}.join("\n")}
55EOF
56
57 user = User.find_by_login('pootle-commits')
58 Mailer.deliver_commit_notification(user, subject, body)
59 end
60 end
61end