Skip to content

Commit

Permalink
i18n_tool: format commit message with localizers credits
Browse files Browse the repository at this point in the history
  • Loading branch information
Loic Dachary committed Mar 26, 2018
1 parent bf8456e commit 3196357
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
37 changes: 35 additions & 2 deletions securedrop/i18n_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import argparse
import logging
import os
import re
import signal
import subprocess
import sys
import textwrap
import version

from os.path import dirname, join, realpath
Expand Down Expand Up @@ -329,8 +331,39 @@ def add(p):
updated = True

if updated:
sh("git -C {r} commit -m 'l10n: updated {l}'".format(
r=args.root, l=code))
self.upstream_commit(args, code)

def upstream_commit(self, args, code):
authors = set()
for path in sh("git -C {r} diff --name-only --cached".format(
r=args.root)).split():
previous_message = sh("git -C {r} log -n 1 {p}".format(
r=args.root, p=path))
m = re.search('copied from (\w+)', previous_message)
if m:
origin = m.group(1)
else:
origin = ''
authors |= set(sh("""
git -C {r} log --format=%aN {o}..i18n/i18n -- {p}
""".format(r=args.root, o=origin, p=path)).strip().split('\n'))
current = sh("git -C {r} rev-parse i18n/i18n".format(
r=args.root)).strip()
info = I18NTool.SUPPORTED_LANGUAGES[code]
message = textwrap.dedent(u"""
l10n: updated {code} {name}
localizers: {authors}
{remote}
copied from {current}
""".format(remote=args.url,
name=info['name'],
authors=", ".join(authors),
code=code,
current=current))
sh(u'git -C {r} commit -m "{message}"'.format(
r=args.root, message=message.replace('"', '\"')).encode('utf-8'))

def set_update_from_weblate_parser(self, subps):
parser = subps.add_parser('update-from-weblate',
Expand Down
19 changes: 16 additions & 3 deletions securedrop/tests/test_i18n_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ def test_update_from_weblate(self, tmpdir, caplog):
cd {d}/$r
git init
git config user.email "[email protected]"
git config user.name "Your Name"
git config user.name "Loïc Nordhøy"
touch README.md
git add README.md
git commit -m 'README' README.md
done
cp -a {o}/i18n/* {d}/i18n
cd {d}/i18n
Expand Down Expand Up @@ -312,6 +315,8 @@ def r():
])
assert 'l10n: updated nl' not in r()
assert 'l10n: updated de_DE' not in r()
message = i18n_tool.sh("git -C {d}/securedrop show".format(d=d))
assert u"Loïc" in message

#
# an update is done to nl in weblate
Expand All @@ -322,9 +327,14 @@ def r():
f=securedrop/translations/nl/LC_MESSAGES/messages.po
sed -i -e 's/inactiviteit/INACTIVITEIT/' $f
git add $f
git config user.email "[email protected]"
git config user.name "Someone Else"
git commit -m 'translation change' $f
""".format(o=self.dir,
d=d))
cd {d}/securedrop
git config user.email "[email protected]"
git config user.name "Someone Else"
""".format(d=d))

#
# the nl translation update from weblate is copied
Expand All @@ -340,6 +350,9 @@ def r():
])
assert 'l10n: updated nl' in r()
assert 'l10n: updated de_DE' not in r()
message = i18n_tool.sh("git -C {d}/securedrop show".format(d=d))
assert "Someone Else" in message
assert u"Loïc" not in message


class TestSh(object):
Expand Down

0 comments on commit 3196357

Please sign in to comment.