diff --git a/securedrop/i18n_tool.py b/securedrop/i18n_tool.py index 8d114f3e5dc..bebdcdc78a9 100755 --- a/securedrop/i18n_tool.py +++ b/securedrop/i18n_tool.py @@ -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 @@ -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', diff --git a/securedrop/tests/test_i18n_tool.py b/securedrop/tests/test_i18n_tool.py index 84913ef5848..d4768d57cab 100644 --- a/securedrop/tests/test_i18n_tool.py +++ b/securedrop/tests/test_i18n_tool.py @@ -256,7 +256,10 @@ def test_update_from_weblate(self, tmpdir, caplog): cd {d}/$r git init git config user.email "you@example.com" - 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 @@ -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 @@ -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 "somone@else.com" + 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 "somone@else.com" + git config user.name "Someone Else" + """.format(d=d)) # # the nl translation update from weblate is copied @@ -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):