Bug 1391675 - [tryselect] Move --no-push into common arguments, r=armenzg

The main motivation behind this change is to make testing easier, so e.g:
./mach try fuzzy --no-push
and
./mach try syntax --no-push

both work the same way.

MozReview-Commit-ID: LmjA3Kq7xKN

--HG--
extra : rebase_source : 49beb7e1ae0f7502966ebadc4d9c37cae4357df4
This commit is contained in:
Andrew Halberstadt 2017-08-21 13:14:31 -04:00
parent 60a3f8a31c
commit dd95aa68cc
4 changed files with 47 additions and 32 deletions

View File

@ -11,7 +11,15 @@ from .templates import all_templates
class BaseTryParser(ArgumentParser):
name = 'try'
common_arguments = []
common_arguments = [
[['--no-push'],
{'dest': 'push',
'action': 'store_false',
'help': 'Do not push to try as a result of running this command (if '
'specified this command will only print calculated try '
'syntax and selection info).',
}],
]
arguments = []
templates = []

View File

@ -196,7 +196,8 @@ def format_header():
return FZF_HEADER.format(shortcuts=', '.join(shortcuts), t=terminal)
def run_fuzzy_try(update=False, query=None, templates=None, full=False, parameters=None, **kwargs):
def run_fuzzy_try(update=False, query=None, templates=None, full=False, parameters=None,
push=True, **kwargs):
fzf = fzf_bootstrap(update)
if not fzf:
@ -204,7 +205,7 @@ def run_fuzzy_try(update=False, query=None, templates=None, full=False, paramete
return
vcs = VCSHelper.create()
vcs.check_working_directory()
vcs.check_working_directory(push)
all_tasks = generate_tasks(parameters, full)
@ -230,4 +231,4 @@ def run_fuzzy_try(update=False, query=None, templates=None, full=False, paramete
return
msg = "Pushed via 'mach try fuzzy', see diff for scheduled tasks"
return vcs.push_to_try(msg, selected, templates)
return vcs.push_to_try(msg, selected, templates, push=push)

View File

@ -57,13 +57,6 @@ class SyntaxParser(BaseTryParser):
'help': 'When -u and paths are supplied run only the intersection of the '
'tests specified by the two arguments.',
}],
[['--no-push'],
{'dest': 'push',
'action': 'store_false',
'help': 'Do not push to try as a result of running this command (if '
'specified this command will only print calculated try '
'syntax and selection info).',
}],
[['--save'],
{'dest': 'save',
'action': 'store',
@ -706,11 +699,10 @@ class AutoTry(object):
for flavor, paths in paths_by_flavor.iteritems():
print("%s: %s" % (flavor, ",".join(paths)))
if kwargs["verbose"] or not kwargs["push"]:
if kwargs["verbose"]:
print('The following try syntax was calculated:\n%s' % msg)
if kwargs["push"]:
self.vcs.push_to_try(msg)
self.vcs.push_to_try(msg, push=kwargs['push'])
if kwargs["save"] is not None:
self.save_config(kwargs["save"], msg)

View File

@ -86,13 +86,38 @@ class VCSHelper(object):
json.dump(try_task_config, fh, indent=2)
return config
def check_working_directory(self):
def check_working_directory(self, push=True):
if not push:
return
if self.has_uncommitted_changes:
print(UNCOMMITTED_CHANGES)
sys.exit(1)
def push_to_try(self, msg, labels=None, templates=None, push=True):
self.check_working_directory(push)
config = None
if labels:
config = self.write_task_config(labels, templates)
try:
if not push:
print("Calculated try selector:")
if config:
with open(config) as fh:
print(fh.read())
else:
print(msg)
return
self._push_to_try(msg, config)
finally:
if config and os.path.isfile(config):
os.remove(config)
@abstractmethod
def push_to_try(self, msg, labels=None):
def _push_to_try(self, msg, config):
pass
@abstractproperty
@ -106,14 +131,10 @@ class VCSHelper(object):
class HgHelper(VCSHelper):
def push_to_try(self, msg, labels=None, templates=None):
self.check_working_directory()
if labels:
config = self.write_task_config(labels, templates)
self.run(['hg', 'add', config])
def _push_to_try(self, msg, config):
try:
if config:
self.run(['hg', 'add', config])
return subprocess.check_call(['hg', 'push-to-try', '-m', msg])
except subprocess.CalledProcessError:
try:
@ -124,9 +145,6 @@ class HgHelper(VCSHelper):
finally:
self.run(['hg', 'revert', '-a'])
if labels and os.path.isfile(config):
os.remove(config)
@property
def files_changed(self):
return self.run(['hg', 'log', '-r', '::. and not public()',
@ -140,19 +158,15 @@ class HgHelper(VCSHelper):
class GitHelper(VCSHelper):
def push_to_try(self, msg, labels=None, templates=None):
self.check_working_directory()
def _push_to_try(self, msg, config):
try:
subprocess.check_output(['git', 'cinnabar', '--version'], stderr=subprocess.STDOUT)
except subprocess.CalledProcessError:
print(GIT_CINNABAR_NOT_FOUND)
return 1
if labels:
config = self.write_task_config(labels, templates)
if config:
self.run(['git', 'add', config])
subprocess.check_call(['git', 'commit', '--allow-empty', '-m', msg])
try:
return subprocess.call(['git', 'push', 'hg::ssh://hg.mozilla.org/try',