Skip to content

Commit

Permalink
i18n_tool: verify user.email & user.name are set before commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Loic Dachary committed Mar 21, 2018
1 parent 2b3ca0a commit ad81086
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions securedrop/i18n_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,23 @@ def set_translate_desktop_parser(self, subps):
self.set_translate_parser(subps, parser, translations_dir, sources)
parser.set_defaults(func=self.translate_desktop)

@staticmethod
def require_git_email_name(git_dir):
cmd = ('git -C {d} config --get user.name > /dev/null && '
'git -C {d} config --get user.email > /dev/null'.format(
d=git_dir))
if subprocess.call(cmd, shell=True): # nosec
raise Exception(cmd + ' returned false, please set name and email')
return True

def update_docs(self, args):
l10n_content = '.. GENERATED BY i18n_tool.py DO NOT EDIT:\n\n'
for (code, info) in sorted(I18NTool.SUPPORTED_LANGUAGES.items()):
l10n_content += '* ' + info['name'] + ' (' + code + ')\n'
includes = join(args.documentation_dir, 'includes')
l10n_txt = join(includes, 'l10n.txt')
open(l10n_txt, 'w').write(l10n_content)
self.require_git_email_name(includes)
if self.file_is_modified(l10n_txt):
sh("""
set -ex
Expand Down Expand Up @@ -334,6 +344,7 @@ def add(p):
self.upstream_commit(args, code)

def upstream_commit(self, args, code):
self.require_git_email_name(args.root)
authors = set()
for path in sh("git -C {r} diff --name-only --cached".format(
r=args.root)).split():
Expand Down
15 changes: 15 additions & 0 deletions securedrop/tests/test_i18n_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,21 @@ def test_translate_messages_compile_arg(self, tmpdir):
assert 'code hello i18n' in mo
assert 'template hello i18n' not in mo

def test_require_git_email_name(self, tmpdir):
i18n_tool.sh("""
cd {dir}
git init
""".format(dir=str(tmpdir)))
with pytest.raises(Exception) as excinfo:
i18n_tool.I18NTool.require_git_email_name(str(tmpdir))
assert 'please set name' in excinfo.value.message
i18n_tool.sh("""
cd {dir}
git config user.email "[email protected]"
git config user.name "Your Name"
""".format(dir=str(tmpdir)))
assert i18n_tool.I18NTool.require_git_email_name(str(tmpdir))

def test_update_docs(self, tmpdir, caplog):
os.makedirs(join(str(tmpdir), 'includes'))
i18n_tool.sh("""
Expand Down

0 comments on commit ad81086

Please sign in to comment.