Skip to content

Commit 490e90d

Browse files
authored
Allow to disable opening the web browser/creating PR (#36)
1 parent 1d90abb commit 490e90d

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

cherry_picker/cherry_picker.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def __init__(
9898
prefix_commit=True,
9999
config=DEFAULT_CONFIG,
100100
chosen_config_path=None,
101+
auto_pr=True,
101102
):
102103

103104
self.chosen_config_path = chosen_config_path
@@ -125,6 +126,7 @@ def __init__(
125126
self.branches = branches
126127
self.dry_run = dry_run
127128
self.push = push
129+
self.auto_pr = auto_pr
128130
self.prefix_commit = prefix_commit
129131

130132
def set_paused_state(self):
@@ -297,6 +299,8 @@ def push_to_remote(self, base_branch, head_branch, commit_message=""):
297299
click.echo(cpe.output)
298300
set_state(WORKFLOW_STATES.PUSHING_TO_REMOTE_FAILED)
299301
else:
302+
if not self.auto_pr:
303+
return
300304
gh_auth = os.getenv("GH_AUTH")
301305
if gh_auth:
302306
set_state(WORKFLOW_STATES.PR_CREATING)
@@ -577,6 +581,17 @@ class state:
577581
default=True,
578582
help="Changes won't be pushed to remote",
579583
)
584+
@click.option(
585+
"--auto-pr/--no-auto-pr",
586+
"auto_pr",
587+
is_flag=True,
588+
default=True,
589+
help=(
590+
"If auto PR is enabled, cherry-picker will automatically open a PR"
591+
" through API if GH_AUTH env var is set, or automatically open the PR"
592+
" creation page in the web browser otherwise."
593+
),
594+
)
580595
@click.option(
581596
"--config-path",
582597
"config_path",
@@ -592,7 +607,7 @@ class state:
592607
@click.argument("branches", nargs=-1)
593608
@click.pass_context
594609
def cherry_pick_cli(
595-
ctx, dry_run, pr_remote, abort, status, push, config_path, commit_sha1, branches
610+
ctx, dry_run, pr_remote, abort, status, push, auto_pr, config_path, commit_sha1, branches
596611
):
597612
"""cherry-pick COMMIT_SHA1 into target BRANCHES."""
598613

@@ -607,6 +622,7 @@ def cherry_pick_cli(
607622
branches,
608623
dry_run=dry_run,
609624
push=push,
625+
auto_pr=auto_pr,
610626
config=config,
611627
chosen_config_path=chosen_config_path,
612628
)

cherry_picker/test.py

+12
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,18 @@ def test_push_to_remote_botflow(tmp_git_repo_dir, monkeypatch):
679679
assert get_state() == WORKFLOW_STATES.PR_CREATING
680680

681681

682+
def test_push_to_remote_no_auto_pr(tmp_git_repo_dir, monkeypatch):
683+
monkeypatch.setenv("GH_AUTH", "True")
684+
with mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True):
685+
cherry_picker = CherryPicker("origin", "xxx", [], auto_pr=False)
686+
687+
with mock.patch.object(cherry_picker, "run_cmd"), mock.patch.object(
688+
cherry_picker, "create_gh_pr"
689+
):
690+
cherry_picker.push_to_remote("main", "backport-branch-test")
691+
assert get_state() == WORKFLOW_STATES.PUSHED_TO_REMOTE
692+
693+
682694
def test_backport_no_branch(tmp_git_repo_dir, monkeypatch):
683695
with mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True):
684696
cherry_picker = CherryPicker("origin", "xxx", [])

0 commit comments

Comments
 (0)