Bug 1394891 - Require an r+ from a list of reviewers to modify an FTL file. r=pike,glob
MozReview-Commit-ID: AvZ26EZ48Ol
new file mode 100644
--- /dev/null
+++ b/hghooks/mozhghooks/check/prevent_ftl_changes.py
@@ -0,0 +1,66 @@
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+from __future__ import absolute_import
+from mozautomation.commitparser import (
+ parse_requal_reviewers,
+)
+
+from ..checks import (
+ PreTxnChangegroupCheck,
+ print_banner,
+)
+
+FTL_DRIVERS = [
+ ("Francesco Lodolo", "flod"),
+ ("Zibi Braniecki", "gandalf"),
+ ("Axel Hecht", "pike"),
+ ("Stas Malolepszy", "stas")
+]
+
+
+FTL_COMMIT_FOUND = """
+You are trying to commit a change to an FTL file.
+At the moment modifying FTL files requires a review from
+one of the L10n Drivers.
+Please, request review from either:
+"""
+
+for (name, nick) in FTL_DRIVERS:
+ FTL_COMMIT_FOUND += " - {} (:{})\n".format(name, nick)
+
+
+class FTLCheck(PreTxnChangegroupCheck):
+ """Prevents FTL file modifications without appropriate review.
+
+ FTL is a new localization format currently being introduced
+ into Gecko and Firefox.
+ During the initial period we keep tight control over new
+ FTL strings being added to the repository.
+
+ In this period, we require that one of the L10n Drivers
+ reviews every commit that touched an FTL file.
+ """
+ @property
+ def name(self):
+ return 'ftl_check'
+
+ def relevant(self):
+ return self.repo_metadata['firefox_releasing']
+
+ def pre(self):
+ pass
+
+ def check(self, ctx):
+ if any(f.endswith('.ftl') for f in ctx.files()):
+ requal = parse_requal_reviewers(ctx.description())
+ reviewers = [nick for (name, nick) in FTL_DRIVERS]
+ if any(nick in reviewers for nick in requal):
+ return True
+
+ print_banner(self.ui, 'error', FTL_COMMIT_FOUND)
+ return False
+ return True
+
+ def post_check(self):
+ return True
--- a/hghooks/mozhghooks/extension.py
+++ b/hghooks/mozhghooks/extension.py
@@ -15,26 +15,28 @@ buglink = 'https://bugzilla.mozilla.org/
def get_check_classes(hook):
# TODO come up with a mechanism for automatically discovering checks
# so we don't have to enumerate them all.
from mozhghooks.check import (
advertise_upgrade,
prevent_cross_channel_messages,
+ prevent_ftl_changes,
prevent_subrepos,
prevent_symlinks,
single_root,
try_task_config_file,
)
# TODO check to hook mapping should also be automatically discovered.
if hook == 'pretxnchangegroup':
return (
prevent_cross_channel_messages.XChannelMessageCheck,
+ prevent_ftl_changes.FTLCheck,
prevent_subrepos.PreventSubReposCheck,
prevent_symlinks.PreventSymlinksCheck,
single_root.SingleRootCheck,
try_task_config_file.TryConfigCheck,
)
elif hook == 'changegroup':
return (
new file mode 100644
--- /dev/null
+++ b/hghooks/tests/test-prevent-ftl-changes.t
@@ -0,0 +1,58 @@
+ $ . $TESTDIR/hghooks/tests/common.sh
+
+Commit adding an FTL file without appropriate reviewer errors
+
+ $ hg init normal
+ $ configurehooks normal
+ $ touch normal/.hg/IS_FIREFOX_REPO
+ $ hg -q clone normal client-normal
+ $ cd client-normal
+ $ touch test.ftl
+ $ hg -q commit -A -m 'add test.ftl'
+ $ hg push
+ pushing to $TESTTMP/normal
+ searching for changes
+ adding changesets
+ adding manifests
+ adding file changes
+ added 1 changesets with 1 changes to 1 files
+
+ ************************ ERROR *************************
+ You are trying to commit a change to an FTL file.
+ At the moment modifying FTL files requires a review from
+ one of the L10n Drivers.
+ Please, request review from either:
+ - Francesco Lodolo (:flod)
+ - Zibi Braniecki (:gandalf)
+ - Axel Hecht (:pike)
+ - Stas Malolepszy (:stas)
+ ********************************************************
+
+ transaction abort!
+ rollback completed
+ abort: pretxnchangegroup.mozhooks hook failed
+ [255]
+
+Commit adding an FTL file with appropriate reviewer works
+
+ $ hg commit --amend -m 'add test.ftl. r=flod'
+ saved backup bundle to $TESTTMP/client-normal/.hg/strip-backup/caf1d529f784-2085d403-amend-backup.hg (glob)
+ $ hg push
+ pushing to $TESTTMP/normal
+ searching for changes
+ adding changesets
+ adding manifests
+ adding file changes
+ added 1 changesets with 1 changes to 1 files
+
+Commit adding an FTL file with appropriate reviewer works
+
+ $ touch test2.ftl
+ $ hg -q commit -A -m 'add test2.ftl. r=someonelse,stas'
+ $ hg push
+ pushing to $TESTTMP/normal
+ searching for changes
+ adding changesets
+ adding manifests
+ adding file changes
+ added 1 changesets with 1 changes to 1 files