Skip to content

Commit 2e0a67e

Browse files
authored
Merge pull request #3126 from regro/revert-3124-reapply-git-backend-6
Revert "Reapply (Git-6) Use new Git Backend in Entire auto_tick flow"
2 parents b2f2cea + 2611036 commit 2e0a67e

17 files changed

+527
-1835
lines changed

conda_forge_tick/auto_tick.py

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import traceback
1010
import typing
1111
from dataclasses import dataclass
12-
from typing import Literal, cast
12+
from typing import Literal, MutableMapping, cast
1313
from urllib.error import URLError
1414
from uuid import uuid4
1515

@@ -31,13 +31,15 @@
3131
from conda_forge_tick.feedstock_parser import BOOTSTRAP_MAPPINGS
3232
from conda_forge_tick.git_utils import (
3333
DryRunBackend,
34-
DuplicatePullRequestError,
3534
GitCli,
3635
GitCliError,
3736
GitPlatformBackend,
3837
RepositoryNotFoundError,
38+
comment_on_pr,
39+
github3_client,
3940
github_backend,
4041
is_github_api_limit_reached,
42+
push_repo,
4143
)
4244
from conda_forge_tick.lazy_json_backends import (
4345
LazyJson,
@@ -70,7 +72,6 @@
7072
)
7173

7274
from .migrators_types import MigrationUidTypedDict
73-
from .models.pr_json import PullRequestData, PullRequestInfoSpecial, PullRequestState
7475

7576
logger = logging.getLogger(__name__)
7677

@@ -422,20 +423,13 @@ def _check_and_process_solvability(
422423
return False
423424

424425

425-
def get_spoofed_closed_pr_info() -> PullRequestInfoSpecial:
426-
return PullRequestInfoSpecial(
427-
id=str(uuid4()),
428-
merged_at="never issued",
429-
state="closed",
430-
)
431-
432-
433426
def run_with_tmpdir(
434427
context: FeedstockContext,
435428
migrator: Migrator,
436429
git_backend: GitPlatformBackend,
437430
rerender: bool = True,
438431
base_branch: str = "main",
432+
dry_run: bool = False,
439433
**kwargs: typing.Any,
440434
) -> tuple[MigrationUidTypedDict, dict] | tuple[Literal[False], Literal[False]]:
441435
"""
@@ -454,6 +448,7 @@ def run_with_tmpdir(
454448
git_backend=git_backend,
455449
rerender=rerender,
456450
base_branch=base_branch,
451+
dry_run=dry_run,
457452
**kwargs,
458453
)
459454

@@ -464,6 +459,7 @@ def run(
464459
git_backend: GitPlatformBackend,
465460
rerender: bool = True,
466461
base_branch: str = "main",
462+
dry_run: bool = False,
467463
**kwargs: typing.Any,
468464
) -> tuple[MigrationUidTypedDict, dict] | tuple[Literal[False], Literal[False]]:
469465
"""For a given feedstock and migration run the migration
@@ -558,64 +554,67 @@ def run(
558554
logger.warning("Skipping migration due to solvability check failure")
559555
return False, False
560556

561-
pr_data: PullRequestData | PullRequestInfoSpecial | None
562-
"""
563-
The PR data for the PR that was created. The contents of this variable will be stored in the bot's database.
564-
None means: We don't update the PR data.
565-
"""
557+
# This is needed because we want to migrate to the new backend step-by-step
558+
repo: github3.repos.Repository | None = github3_client().repository(
559+
context.git_repo_owner, context.git_repo_name
560+
)
561+
562+
assert repo is not None
563+
564+
feedstock_dir = str(context.local_clone_dir.resolve())
565+
566+
# TODO: Better annotation here
567+
pr_json: typing.Union[MutableMapping, None, bool]
566568
if (
567569
isinstance(migrator, MigrationYaml)
568570
and not rerender_info.nontrivial_changes
569571
and context.attrs["name"] != "conda-forge-pinning"
570572
):
571573
# spoof this so it looks like the package is done
572-
pr_data = get_spoofed_closed_pr_info()
574+
pr_json = {
575+
"state": "closed",
576+
"merged_at": "never issued",
577+
"id": str(uuid4()),
578+
}
573579
else:
574-
# push and PR
575-
git_backend.push_to_repository(
576-
owner=git_backend.user,
577-
repo_name=context.git_repo_name,
578-
git_dir=context.local_clone_dir,
579-
branch=branch_name,
580-
)
580+
# push up
581581
try:
582-
pr_data = git_backend.create_pull_request(
583-
target_owner=context.git_repo_owner,
584-
target_repo=context.git_repo_name,
585-
base_branch=base_branch,
586-
head_branch=branch_name,
587-
title=migration_run_data["pr_title"],
582+
pr_json = push_repo(
583+
fctx=context,
584+
feedstock_dir=feedstock_dir,
588585
body=migration_run_data["pr_body"],
586+
repo=repo,
587+
title=migration_run_data["pr_title"],
588+
branch=branch_name,
589+
base_branch=base_branch,
590+
dry_run=dry_run,
589591
)
590-
except DuplicatePullRequestError:
591-
# This shouldn't happen too often anymore since we won't double PR
592-
logger.warning(
593-
f"Attempted to create a duplicate PR for merging {git_backend.user}:{branch_name} "
594-
f"into {context.git_repo_owner}:{base_branch}. Ignoring."
595-
)
596-
# Don't update the PR data
597-
pr_data = None
598592

599-
if (
600-
pr_data
601-
and pr_data.state != PullRequestState.CLOSED
602-
and rerender_info.rerender_comment
603-
):
604-
git_backend.comment_on_pull_request(
605-
repo_owner=context.git_repo_owner,
606-
repo_name=context.git_repo_name,
607-
pr_number=pr_data.number,
608-
comment=rerender_info.rerender_comment,
593+
# This shouldn't happen too often any more since we won't double PR
594+
except github3.GitHubError as e:
595+
if e.msg != "Validation Failed":
596+
raise
597+
else:
598+
print(f"Error during push {e}")
599+
# If we just push to the existing PR then do nothing to the json
600+
pr_json = False
601+
ljpr = False
602+
603+
if pr_json and pr_json["state"] != "closed" and rerender_info.rerender_comment:
604+
comment_on_pr(
605+
pr_json,
606+
rerender_info.rerender_comment,
607+
repo,
609608
)
610609

611-
if pr_data:
612-
pr_lazy_json = LazyJson(
613-
os.path.join("pr_json", f"{pr_data.id}.json"),
610+
if pr_json:
611+
ljpr = LazyJson(
612+
os.path.join("pr_json", str(pr_json["id"]) + ".json"),
614613
)
615-
with pr_lazy_json as __edit_pr_lazy_json:
616-
__edit_pr_lazy_json.update(**pr_data.model_dump(mode="json"))
614+
with ljpr as __ljpr:
615+
__ljpr.update(**pr_json)
617616
else:
618-
pr_lazy_json = False
617+
ljpr = False
619618

620619
# If we've gotten this far then the node is good
621620
with context.attrs["pr_info"] as pri:
@@ -624,7 +623,8 @@ def run(
624623
context.attrs, migrator_name, is_version=is_version_migration
625624
)
626625

627-
return migration_run_data["migrate_return_value"], pr_lazy_json
626+
logger.info("Removing feedstock dir")
627+
return migration_run_data["migrate_return_value"], ljpr
628628

629629

630630
def _compute_time_per_migrator(mctx, migrators):
@@ -707,6 +707,7 @@ def _run_migrator_on_feedstock_branch(
707707
migrator,
708708
fctx: FeedstockContext,
709709
git_backend: GitPlatformBackend,
710+
dry_run,
710711
mctx,
711712
migrator_name,
712713
good_prs,
@@ -722,8 +723,9 @@ def _run_migrator_on_feedstock_branch(
722723
migrator=migrator,
723724
git_backend=git_backend,
724725
rerender=migrator.rerender,
725-
base_branch=base_branch,
726726
hash_type=attrs.get("hash_type", "sha256"),
727+
base_branch=base_branch,
728+
dry_run=dry_run,
727729
)
728730
finally:
729731
fctx.attrs.pop("new_version", None)
@@ -756,7 +758,6 @@ def _run_migrator_on_feedstock_branch(
756758
)
757759

758760
except (github3.GitHubError, github.GithubException) as e:
759-
# TODO: pull this down into run() - also check the other exceptions
760761
if hasattr(e, "msg") and e.msg == "Repository was archived so is read-only.":
761762
attrs["archived"] = True
762763
else:
@@ -1010,6 +1011,7 @@ def _run_migrator(
10101011
migrator=migrator,
10111012
fctx=fctx,
10121013
git_backend=git_backend,
1014+
dry_run=dry_run,
10131015
mctx=mctx,
10141016
migrator_name=migrator_name,
10151017
good_prs=good_prs,

conda_forge_tick/contexts.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ def git_repo_owner(self) -> str:
5555
def git_repo_name(self) -> str:
5656
return f"{self.feedstock_name}-feedstock"
5757

58-
@property
59-
def git_http_ref(self) -> str:
60-
"""
61-
A link to the feedstock's GitHub repository.
62-
"""
63-
return f"https://github.com/{self.git_repo_owner}/{self.git_repo_name}"
64-
6558
@property
6659
def automerge(self) -> bool | str:
6760
"""

0 commit comments

Comments
 (0)