-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hooks: add
.arcconfig
change blocking hook for conduit-testing
re…
…pos (Bug 1789686) r=grammar,zeid Adds a hook to check that changes to `.arcconfig` files in `conduit-testing` repos do not revert the file from pointing to the dev Phabricator server. Differential Revision: https://phabricator.services.mozilla.com/D157342 --HG-- extra : moz-landing-system : lando
- Loading branch information
Showing
3 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# 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 | ||
|
||
import json | ||
|
||
from mercurial import error | ||
|
||
from ..checks import ( | ||
PreTxnChangegroupCheck, | ||
print_banner, | ||
) | ||
|
||
|
||
REJECT_MESSAGE = b""" | ||
Push contains unwanted changes to `.arcconfig` files. | ||
Please ensure `.arcconfig` points to the Phab dev server for | ||
`conduit-testing` repos. | ||
""" | ||
|
||
ARCCONFIG_PATH = b".arcconfig" | ||
|
||
DEV_PHAB_URL = "https://phabricator-dev.allizom.org/" | ||
|
||
|
||
class PreventConduitArcconfig(PreTxnChangegroupCheck): | ||
"""Prevent `.arcconfig` updates for `conduit-testing` repos.""" | ||
|
||
@property | ||
def name(self): | ||
return b"prevent_conduit_arcconfig" | ||
|
||
def relevant(self) -> bool: | ||
return b"conduit-testing" in self.repo.root.split(b"/") | ||
|
||
def pre(self, _node): | ||
self.latest_arcconfig_contents = "" | ||
|
||
def check(self, ctx) -> bool: | ||
if ARCCONFIG_PATH in ctx.files(): | ||
fctx = ctx[ARCCONFIG_PATH] | ||
self.latest_arcconfig_contents = fctx.data().decode("utf-8") | ||
|
||
return True | ||
|
||
def post_check(self) -> bool: | ||
if not self.latest_arcconfig_contents: | ||
# No updates to `.arcconfig`. | ||
return True | ||
|
||
try: | ||
arcconfig = json.loads(self.latest_arcconfig_contents) | ||
except json.JSONDecodeError as exc: | ||
raise error.Abort(b"Could not decode `.arcconfig` to JSON.") from exc | ||
|
||
if arcconfig["phabricator.uri"].startswith(DEV_PHAB_URL): | ||
# Latest state of `.arcconfig` maintains dev URL. | ||
return True | ||
|
||
# `.arcconfig` has been updated to point to the wrong server (prod). | ||
print_banner(self.ui, b"error", REJECT_MESSAGE) | ||
return False | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
$ . $TESTDIR/hghooks/tests/common.sh | ||
|
||
`conduit-testing` repos should only allow the dev phab server in `.arcconfig`. | ||
|
||
$ hg init conduit-testing | ||
$ configurehooks conduit-testing | ||
$ hg -q clone conduit-testing client | ||
$ cd client | ||
$ echo '{"phabricator.uri":"https://phabricator-dev.allizom.org/"}' > .arcconfig | ||
$ hg ci -q -A -m "add .arcconfig" | ||
$ hg push | ||
pushing to $TESTTMP/conduit-testing | ||
searching for changes | ||
adding changesets | ||
adding manifests | ||
adding file changes | ||
added 1 changesets with 1 changes to 1 files | ||
|
||
$ echo '{"phabricator.uri":"https://phabricator.services.mozilla.com/"}' > .arcconfig | ||
$ hg ci -q -A -m "update .arcconfig to bad value" | ||
$ hg push | ||
pushing to $TESTTMP/conduit-testing | ||
searching for changes | ||
adding changesets | ||
adding manifests | ||
adding file changes | ||
|
||
************************** ERROR *************************** | ||
Push contains unwanted changes to `.arcconfig` files. | ||
|
||
Please ensure `.arcconfig` points to the Phab dev server for | ||
`conduit-testing` repos. | ||
************************************************************ | ||
|
||
transaction abort! | ||
rollback completed | ||
abort: pretxnchangegroup.mozhooks hook failed | ||
[255] | ||
|
||
Pushes that update `.arcconfig` and then revert it should be allowed. | ||
|
||
$ echo '{"phabricator.uri":"https://phabricator-dev.allizom.org/"}' > .arcconfig | ||
$ hg ci -q -A -m "revert .arcconfig to correct value" | ||
$ hg log -G | ||
@ changeset: 2:743d41d3d1de | ||
| tag: tip | ||
| user: test | ||
| date: Thu Jan 01 00:00:00 1970 +0000 | ||
| summary: revert .arcconfig to correct value | ||
| | ||
o changeset: 1:dcd947bcda7b | ||
| user: test | ||
| date: Thu Jan 01 00:00:00 1970 +0000 | ||
| summary: update .arcconfig to bad value | ||
| | ||
o changeset: 0:58f2675adc14 | ||
user: test | ||
date: Thu Jan 01 00:00:00 1970 +0000 | ||
summary: add .arcconfig | ||
|
||
$ hg push | ||
pushing to $TESTTMP/conduit-testing | ||
searching for changes | ||
adding changesets | ||
adding manifests | ||
adding file changes | ||
added 2 changesets with 2 changes to 1 files | ||
|
||
$ cd .. | ||
|