Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/lib/emailer.rb
blob: 8e56c50b8b317176677e713c7cf5c0a3a6381f7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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