From 1994136fadb9f730271fa07a6e5104c367e0f434 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Mon, 7 Jan 2019 18:38:05 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Move=20conf=20path=20from=20glob?= =?UTF-8?q?al=20scope=20to=20CherryPicker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cherry_picker/cherry_picker/cherry_picker.py | 34 +++++++++----------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/cherry_picker/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker/cherry_picker.py index c2510d0..a470fdf 100755 --- a/cherry_picker/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker/cherry_picker.py @@ -15,14 +15,6 @@ from . import __version__ - -chosen_config_path = None -"""The config reference used in the current runtime. - -It starts with a Git revision specifier, followed by a colon -and a path relative to the repo root. -""" - CREATE_PR_URL_TEMPLATE = ("https://github.com/gitapi/repos/" "{config[team]}/{config[repo]}/pulls") DEFAULT_CONFIG = collections.ChainMap({ @@ -58,8 +50,16 @@ def __init__(self, pr_remote, commit_sha1, branches, *, dry_run=False, push=True, prefix_commit=True, config=DEFAULT_CONFIG, + chosen_config_path=None, ): + self.chosen_config_path = chosen_config_path + """The config reference used in the current runtime. + + It starts with a Git revision specifier, followed by a colon + and a path relative to the repo root. + """ + self.config = config self.check_repo() # may raise InvalidRepoException @@ -80,6 +80,12 @@ def __init__(self, pr_remote, commit_sha1, branches, self.push = push self.prefix_commit = prefix_commit + def set_paused_state(): + """Save paused progress state into Git config.""" + if self.chosen_config_path is not None: + save_cfg_vals_to_git_cfg(config_path=self.chosen_config_path) + set_state('BACKPORT_PAUSED') + @property def upstream(self): """Get the remote name to use for upstream branches @@ -475,13 +481,13 @@ def cherry_pick_cli(ctx, click.echo("\U0001F40D \U0001F352 \u26CF") - global chosen_config_path chosen_config_path, config = load_config(config_path) try: cherry_picker = CherryPicker(pr_remote, commit_sha1, branches, dry_run=dry_run, - push=push, config=config) + push=push, config=config, + chosen_config_path=chosen_config_path) except InvalidRepoException: click.echo(f"You're not inside a {config['repo']} repo right now! \U0001F645") sys.exit(-1) @@ -649,14 +655,6 @@ def get_sha1_from(commitish): return subprocess.check_output(cmd).strip().decode('utf-8') -def set_paused_state(): - """Save paused progress state into Git config.""" - global chosen_config_path - if chosen_config_path is not None: - save_cfg_vals_to_git_cfg(config_path=chosen_config_path) - set_state('BACKPORT_PAUSED') - - def reset_stored_config_ref(): """Remove the config path option from Git config.""" wipe_cfg_vals_from_git_cfg('config_path')