hghooks: update try syntax hook to account for the task config method (
bug 1380357), r?gps
MozReview-Commit-ID: Facwx4PQVIi
--- a/hghooks/mozhghooks/try_warning.py
+++ b/hghooks/mozhghooks/try_warning.py
@@ -1,44 +1,43 @@
#!/usr/bin/env python
TRY_SYNTAX_MISSING = """
-Your push does not contain any try syntax, so no jobs will be
-scheduled automatically. If this was intentional, you can still
+Your push does not specify any jobs to run on try. You can still
schedule jobs by selecting the drop down at the top right of your
push in treeherder and choosing 'Add new Jobs'.
-If you meant to schedule jobs, remember the try syntax must
-appear in the *last* commit of your push. For assistance with try
-server, see https://wiki.mozilla.org/Try.
+For more information, see https://wiki.mozilla.org/Try.
"""
TRY_JOBS_MISSING = """
Your try syntax would not trigger any jobs. Either specify a build
with '-p' or an arbitrary job with '-j'. If you intended to push
-without triggering any jobs, omit the try syntax completely. For
-assistance with try server, see https://wiki.mozilla.org/Try.
+without triggering any jobs, omit the try syntax completely.
+
+For more information, see https://wiki.mozilla.org/Try.
"""
-def print_banner(level, message):
+def print_banner(ui, level, message):
width = max(len(l) for l in message.splitlines())
banner = [
' {} '.format(level.upper()).center(width, '*'),
message.strip(),
'*' * width,
]
- print('\n' + '\n'.join(banner) + '\n')
+ ui.write('\n' + '\n'.join(banner) + '\n\n')
def hook(ui, repo, source=None, **kwargs):
if source in ('pull', 'strip'):
return 0
- # Block the push unless they use the try_syntax
- # 'try: ' is enough to activate try_parser and get the default set
- comment = repo.changectx('tip').description()
- if "try: " not in comment:
- print_banner('warning', TRY_SYNTAX_MISSING)
- elif "-p none" in comment and "-j" not in comment:
- print_banner('error', TRY_JOBS_MISSING)
+ tip = repo.changectx('tip')
+ comment = tip.description()
+ config_found = 'try_task_config.json' in tip.manifest()
+ syntax_found = 'try:' in comment
+ if not config_found and not syntax_found:
+ print_banner(ui, 'warning', TRY_SYNTAX_MISSING)
+ elif syntax_found and "-p none" in comment and "-j" not in comment:
+ print_banner(ui, 'error', TRY_JOBS_MISSING)
return 1
return 0
--- a/hghooks/tests/test-try-warning.t
+++ b/hghooks/tests/test-try-warning.t
@@ -16,50 +16,49 @@ Pushing a changeset without using try sy
pushing to ../server
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
**************************** WARNING ****************************
- Your push does not contain any try syntax, so no jobs will be
- scheduled automatically. If this was intentional, you can still
+ Your push does not specify any jobs to run on try. You can still
schedule jobs by selecting the drop down at the top right of your
push in treeherder and choosing 'Add new Jobs'.
- If you meant to schedule jobs, remember the try syntax must
- appear in the *last* commit of your push. For assistance with try
- server, see https://wiki.mozilla.org/Try.
+ For more information, see https://wiki.mozilla.org/Try.
*****************************************************************
+
Pushing a changeset with '-p none' should error out
$ echo 'working' > foo
$ hg commit -m 'try: -b do -p none'
$ hg push ../server
pushing to ../server
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
***************************** ERROR ******************************
Your try syntax would not trigger any jobs. Either specify a build
with '-p' or an arbitrary job with '-j'. If you intended to push
- without triggering any jobs, omit the try syntax completely. For
- assistance with try server, see https://wiki.mozilla.org/Try.
+ without triggering any jobs, omit the try syntax completely.
+
+ For more information, see https://wiki.mozilla.org/Try.
******************************************************************
transaction abort!
rollback completed
abort: pretxnchangegroup.try_mandatory hook failed
[255]
-
+
Pushing a changeset with try syntax on the tip should be allowed
$ hg commit --amend -m 'try: -b do -p all'
saved backup bundle to $TESTTMP/client/.hg/strip-backup/0eb01296232e-7764c983-amend-backup.hg (glob)
$ hg push ../server
pushing to ../server
searching for changes
adding changesets