Skip to content

Commit

Permalink
🎨 Move conf path from global scope to CherryPicker
Browse files Browse the repository at this point in the history
  • Loading branch information
webknjaz committed Jan 7, 2019
1 parent 9e2ff3f commit 1994136
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions cherry_picker/cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 1994136

Please sign in to comment.