Skip to content

Commit b183dab

Browse files
committed
dependency injection for GitPlatformBackend
1 parent 7a5bfca commit b183dab

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

conda_forge_tick/auto_tick.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,9 @@ def get_spoofed_closed_pr_info() -> PullRequestInfoSpecial:
444444
def run_with_tmpdir(
445445
context: FeedstockContext,
446446
migrator: Migrator,
447+
git_backend: GitPlatformBackend,
447448
rerender: bool = True,
448449
base_branch: str = "main",
449-
dry_run: bool = False,
450450
**kwargs: typing.Any,
451451
) -> tuple[MigrationUidTypedDict, dict] | tuple[Literal[False], Literal[False]]:
452452
"""
@@ -462,19 +462,19 @@ def run_with_tmpdir(
462462
return run(
463463
context=cloned_context,
464464
migrator=migrator,
465+
git_backend=git_backend,
465466
rerender=rerender,
466467
base_branch=base_branch,
467-
dry_run=dry_run,
468468
**kwargs,
469469
)
470470

471471

472472
def run(
473473
context: ClonedFeedstockContext,
474474
migrator: Migrator,
475+
git_backend: GitPlatformBackend,
475476
rerender: bool = True,
476477
base_branch: str = "main",
477-
dry_run: bool = False,
478478
**kwargs: typing.Any,
479479
) -> tuple[MigrationUidTypedDict, dict] | tuple[Literal[False], Literal[False]]:
480480
"""For a given feedstock and migration run the migration
@@ -485,12 +485,12 @@ def run(
485485
The current feedstock context, already containing information about a temporary directory for the feedstock.
486486
migrator: Migrator instance
487487
The migrator to run on the feedstock
488+
git_backend: GitPlatformBackend
489+
The git backend to use. Use the DryRunBackend for testing.
488490
rerender : bool
489491
Whether to rerender
490492
base_branch : str, optional
491493
The base branch to which the PR will be targeted.
492-
dry_run : bool, optional
493-
Whether to run in dry run mode.
494494
kwargs: dict
495495
The keyword arguments to pass to the migrator.
496496
@@ -506,8 +506,6 @@ def run(
506506
GitCliError
507507
If an error occurs during a git command which is not suppressed
508508
"""
509-
git_backend: GitPlatformBackend = DryRunBackend() if dry_run else github_backend()
510-
511509
# sometimes we get weird directory issues so make sure we reset
512510
os.chdir(BOT_HOME_DIR)
513511

@@ -715,7 +713,7 @@ def _run_migrator_on_feedstock_branch(
715713
base_branch,
716714
migrator,
717715
fctx: FeedstockContext,
718-
dry_run,
716+
git_backend: GitPlatformBackend,
719717
mctx,
720718
migrator_name,
721719
good_prs,
@@ -729,9 +727,9 @@ def _run_migrator_on_feedstock_branch(
729727
migrator_uid, pr_json = run_with_tmpdir(
730728
context=fctx,
731729
migrator=migrator,
730+
git_backend=git_backend,
732731
rerender=migrator.rerender,
733732
base_branch=base_branch,
734-
dry_run=dry_run,
735733
hash_type=attrs.get("hash_type", "sha256"),
736734
)
737735
finally:
@@ -892,7 +890,7 @@ def _is_migrator_done(_mg_start, good_prs, time_per, pr_limit):
892890
return False
893891

894892

895-
def _run_migrator(migrator, mctx, temp, time_per, dry_run):
893+
def _run_migrator(migrator, mctx, temp, time_per, git_backend: GitPlatformBackend):
896894
_mg_start = time.time()
897895

898896
migrator_name = get_migrator_name(migrator)
@@ -1010,14 +1008,14 @@ def _run_migrator(migrator, mctx, temp, time_per, dry_run):
10101008
)
10111009
):
10121010
good_prs, break_loop = _run_migrator_on_feedstock_branch(
1013-
attrs,
1014-
base_branch,
1015-
migrator,
1016-
fctx,
1017-
dry_run,
1018-
mctx,
1019-
migrator_name,
1020-
good_prs,
1011+
attrs=attrs,
1012+
base_branch=base_branch,
1013+
migrator=migrator,
1014+
fctx=fctx,
1015+
git_backend=git_backend,
1016+
mctx=mctx,
1017+
migrator_name=migrator_name,
1018+
good_prs=good_prs,
10211019
)
10221020
if break_loop:
10231021
break
@@ -1033,8 +1031,7 @@ def _run_migrator(migrator, mctx, temp, time_per, dry_run):
10331031
os.chdir(BOT_HOME_DIR)
10341032

10351033
# Write graph partially through
1036-
if not dry_run:
1037-
dump_graph(mctx.graph)
1034+
dump_graph(mctx.graph)
10381035

10391036
with filter_reprinted_lines("rm-tmp"):
10401037
for f in glob.glob("/tmp/*"):
@@ -1267,13 +1264,15 @@ def main(ctx: CliContext) -> None:
12671264
flush=True,
12681265
)
12691266

1267+
git_backend = github_backend() if not ctx.dry_run else DryRunBackend()
1268+
12701269
for mg_ind, migrator in enumerate(migrators):
12711270
good_prs = _run_migrator(
12721271
migrator,
12731272
mctx,
12741273
temp,
12751274
time_per_migrator[mg_ind],
1276-
ctx.dry_run,
1275+
git_backend,
12771276
)
12781277
if good_prs > 0:
12791278
pass

0 commit comments

Comments
 (0)