diff options
author | Aleksey Lim <alsroot@sugarlabs.org> | 2011-08-25 21:07:32 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@sugarlabs.org> | 2013-02-03 12:59:25 (GMT) |
commit | 0d3b4368b31024a49bc98b25a1a4488bdc502a0e (patch) | |
tree | d6ebac3bdb0bfa627e523ea1f88f8c13e246d735 | |
parent | d5d92f281a4613620de5dcffeb215833fdf2a026 (diff) |
Send commit notification emails for pootle commits
-rw-r--r-- | app/models/mailer.rb | 7 | ||||
-rw-r--r-- | app/views/mailer/commit_notification.erb | 1 | ||||
-rw-r--r-- | app/views/mailer/commit_notification.html.erb | 1 | ||||
-rw-r--r-- | lib/emailer.rb | 61 |
4 files changed, 70 insertions, 0 deletions
diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 7e5739e..7441370 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -92,6 +92,13 @@ class Mailer < ActionMailer::Base @body[:notification_body] = notification_body end + def commit_notification(user, subject, notification_body) + setup_email(user) + @subject += subject + @body[:user] = user + @body[:notification_body] = notification_body + end + protected def setup_email(user) @recipients = "#{user.email}" diff --git a/app/views/mailer/commit_notification.erb b/app/views/mailer/commit_notification.erb new file mode 100644 index 0000000..5c7edd0 --- /dev/null +++ b/app/views/mailer/commit_notification.erb @@ -0,0 +1 @@ +<%= @notification_body %> diff --git a/app/views/mailer/commit_notification.html.erb b/app/views/mailer/commit_notification.html.erb new file mode 100644 index 0000000..5c7edd0 --- /dev/null +++ b/app/views/mailer/commit_notification.html.erb @@ -0,0 +1 @@ +<%= @notification_body %> diff --git a/lib/emailer.rb b/lib/emailer.rb new file mode 100644 index 0000000..8e56c50 --- /dev/null +++ b/lib/emailer.rb @@ -0,0 +1,61 @@ +# encoding: utf-8 +#-- +# Copyright (C) 2011, Aleksey Lim +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +#++ + +module Emailer + def notify_emailer(repository, branch, events) + events.each do |event| + next unless event.commit_details[:committer].login == 'pootle' + + sha = event.commit_details[:id] + author = event.commit_details[:commit_author] + + begin + files = [] + Grit::Git.with_timeout(0) do + files += repository.git.commit(sha).diffs.map {|i| i.a_path} + end + langs = files.collect {|i| next unless i =~ /^po\/(.*).po$/; $1}.compact.join(', ') + rescue Exception => e + logger.warn("Failed to get git diff to compose poole commit files: #{e}") + files = [] + langs = "unknown languages" + end + + event.commit_details[:message] =~ / by user ([^\s:]+)/ + translator = $1 or '<anonymous>' + + subject = "Commit to [#{repository.project.title}] by [#{translator}] for [#{langs}]" + body = <<"EOF" +Project: #{repository.project.title} +Repository: #{repository.title} +Branch: #{branch} + +Author: #{author} +Timestamp: #{event.commit_time} +Url: http://#{GitoriousConfig['gitorious_host']}/#{repository.url_path}/commit/#{event.commit_details[:id]} + +#{event.commit_details[:message]} + +#{files.map {|i| "- #{i}"}.join("\n")} +EOF + + user = User.find_by_login('pootle-commits') + Mailer.deliver_commit_notification(user, subject, body) + end + end +end |