Skip to content

Commit 7659f3c

Browse files
committed
Allow to disable opening the web browser/creating PR (python#36)
1 parent 16e0d6c commit 7659f3c

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):
@@ -300,6 +302,8 @@ def push_to_remote(self, base_branch, head_branch, commit_message=""):
300302
click.echo(cpe.output)
301303
set_state(WORKFLOW_STATES.PUSHING_TO_REMOTE_FAILED)
302304
else:
305+
if not self.auto_pr:
306+
return
303307
gh_auth = os.getenv("GH_AUTH")
304308
if gh_auth:
305309
set_state(WORKFLOW_STATES.PR_CREATING)
@@ -572,6 +576,17 @@ class state:
572576
default=True,
573577
help="Changes won't be pushed to remote",
574578
)
579+
@click.option(
580+
"--auto-pr/--no-auto-pr",
581+
"auto_pr",
582+
is_flag=True,
583+
default=True,
584+
help=(
585+
"If auto PR is enabled, cherry-picker will automatically open a PR"
586+
" through API if GH_AUTH env var is set, or automatically open the PR"
587+
" creation page in the web browser otherwise."
588+
),
589+
)
575590
@click.option(
576591
"--config-path",
577592
"config_path",
@@ -587,7 +602,7 @@ class state:
587602
@click.argument("branches", nargs=-1)
588603
@click.pass_context
589604
def cherry_pick_cli(
590-
ctx, dry_run, pr_remote, abort, status, push, config_path, commit_sha1, branches
605+
ctx, dry_run, pr_remote, abort, status, push, auto_pr, config_path, commit_sha1, branches
591606
):
592607
"""cherry-pick COMMIT_SHA1 into target BRANCHES."""
593608

@@ -602,6 +617,7 @@ def cherry_pick_cli(
602617
branches,
603618
dry_run=dry_run,
604619
push=push,
620+
auto_pr=auto_pr,
605621
config=config,
606622
chosen_config_path=chosen_config_path,
607623
)

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)