Skip to content

Commit

Permalink
Revert "(Git-6) Use new Git Backend in Entire auto_tick flow"
Browse files Browse the repository at this point in the history
  • Loading branch information
beckermr authored Oct 21, 2024
1 parent 258878b commit 04c0a95
Show file tree
Hide file tree
Showing 17 changed files with 528 additions and 1,830 deletions.
116 changes: 59 additions & 57 deletions conda_forge_tick/auto_tick.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import traceback
import typing
from dataclasses import dataclass
from typing import Literal, cast
from typing import Literal, MutableMapping, cast
from urllib.error import URLError
from uuid import uuid4

Expand All @@ -31,13 +31,15 @@
from conda_forge_tick.feedstock_parser import BOOTSTRAP_MAPPINGS
from conda_forge_tick.git_utils import (
DryRunBackend,
DuplicatePullRequestError,
GitCli,
GitCliError,
GitPlatformBackend,
RepositoryNotFoundError,
comment_on_pr,
github3_client,
github_backend,
is_github_api_limit_reached,
push_repo,
)
from conda_forge_tick.lazy_json_backends import (
LazyJson,
Expand Down Expand Up @@ -70,7 +72,6 @@
)

from .migrators_types import MigrationUidTypedDict
from .models.pr_json import PullRequestData, PullRequestInfoSpecial, PullRequestState

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -422,20 +423,13 @@ def _check_and_process_solvability(
return False


def get_spoofed_closed_pr_info() -> PullRequestInfoSpecial:
return PullRequestInfoSpecial(
id=str(uuid4()),
merged_at="never issued",
state="closed",
)


def run_with_tmpdir(
context: FeedstockContext,
migrator: Migrator,
git_backend: GitPlatformBackend,
rerender: bool = True,
base_branch: str = "main",
dry_run: bool = False,
**kwargs: typing.Any,
) -> tuple[MigrationUidTypedDict, dict] | tuple[Literal[False], Literal[False]]:
"""
Expand All @@ -454,6 +448,7 @@ def run_with_tmpdir(
git_backend=git_backend,
rerender=rerender,
base_branch=base_branch,
dry_run=dry_run,
**kwargs,
)

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

pr_data: PullRequestData | PullRequestInfoSpecial | None
"""
The PR data for the PR that was created. The contents of this variable will be stored in the bot's database.
None means: We don't update the PR data.
"""
# This is needed because we want to migrate to the new backend step-by-step
repo: github3.repos.Repository | None = github3_client().repository(
context.git_repo_owner, context.git_repo_name
)

assert repo is not None

feedstock_dir = str(context.local_clone_dir.resolve())

# TODO: Better annotation here
pr_json: typing.Union[MutableMapping, None, bool]
if (
isinstance(migrator, MigrationYaml)
and not rerender_info.nontrivial_changes
and context.attrs["name"] != "conda-forge-pinning"
):
# spoof this so it looks like the package is done
pr_data = get_spoofed_closed_pr_info()
pr_json = {
"state": "closed",
"merged_at": "never issued",
"id": str(uuid4()),
}
else:
# push and PR
git_backend.push_to_repository(
owner=git_backend.user,
repo_name=context.git_repo_name,
git_dir=context.local_clone_dir,
branch=branch_name,
)
# push up
try:
pr_data = git_backend.create_pull_request(
target_owner=context.git_repo_owner,
target_repo=context.git_repo_name,
base_branch=base_branch,
head_branch=branch_name,
title=migration_run_data["pr_title"],
pr_json = push_repo(
fctx=context,
feedstock_dir=feedstock_dir,
body=migration_run_data["pr_body"],
repo=repo,
title=migration_run_data["pr_title"],
branch=branch_name,
base_branch=base_branch,
dry_run=dry_run,
)
except DuplicatePullRequestError:
# This shouldn't happen too often anymore since we won't double PR
logger.warning(
f"Attempted to create a duplicate PR for merging {git_backend.user}:{branch_name} "
f"into {context.git_repo_owner}:{base_branch}. Ignoring."
)
# Don't update the PR data
pr_data = None

if (
pr_data
and pr_data.state != PullRequestState.CLOSED
and rerender_info.rerender_comment
):
git_backend.comment_on_pull_request(
repo_owner=context.git_repo_owner,
repo_name=context.git_repo_name,
pr_number=pr_data.number,
comment=rerender_info.rerender_comment,
# This shouldn't happen too often any more since we won't double PR
except github3.GitHubError as e:
if e.msg != "Validation Failed":
raise
else:
print(f"Error during push {e}")
# If we just push to the existing PR then do nothing to the json
pr_json = False
ljpr = False

if pr_json and pr_json["state"] != "closed" and rerender_info.rerender_comment:
comment_on_pr(
pr_json,
rerender_info.rerender_comment,
repo,
)

if pr_data:
pr_lazy_json = LazyJson(
os.path.join("pr_json", f"{pr_data.id}.json"),
if pr_json:
ljpr = LazyJson(
os.path.join("pr_json", str(pr_json["id"]) + ".json"),
)
with pr_lazy_json as __edit_pr_lazy_json:
__edit_pr_lazy_json.update(**pr_data.model_dump(mode="json"))
with ljpr as __ljpr:
__ljpr.update(**pr_json)
else:
pr_lazy_json = False
ljpr = False

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

return migration_run_data["migrate_return_value"], pr_lazy_json
logger.info("Removing feedstock dir")
return migration_run_data["migrate_return_value"], ljpr


def _compute_time_per_migrator(mctx, migrators):
Expand Down Expand Up @@ -707,6 +707,7 @@ def _run_migrator_on_feedstock_branch(
migrator,
fctx: FeedstockContext,
git_backend: GitPlatformBackend,
dry_run,
mctx,
migrator_name,
good_prs,
Expand All @@ -722,8 +723,9 @@ def _run_migrator_on_feedstock_branch(
migrator=migrator,
git_backend=git_backend,
rerender=migrator.rerender,
base_branch=base_branch,
hash_type=attrs.get("hash_type", "sha256"),
base_branch=base_branch,
dry_run=dry_run,
)
finally:
fctx.attrs.pop("new_version", None)
Expand Down Expand Up @@ -756,7 +758,6 @@ def _run_migrator_on_feedstock_branch(
)

except (github3.GitHubError, github.GithubException) as e:
# TODO: pull this down into run() - also check the other exceptions
if hasattr(e, "msg") and e.msg == "Repository was archived so is read-only.":
attrs["archived"] = True
else:
Expand Down Expand Up @@ -1010,6 +1011,7 @@ def _run_migrator(
migrator=migrator,
fctx=fctx,
git_backend=git_backend,
dry_run=dry_run,
mctx=mctx,
migrator_name=migrator_name,
good_prs=good_prs,
Expand Down
7 changes: 0 additions & 7 deletions conda_forge_tick/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ def git_repo_owner(self) -> str:
def git_repo_name(self) -> str:
return f"{self.feedstock_name}-feedstock"

@property
def git_http_ref(self) -> str:
"""
A link to the feedstock's GitHub repository.
"""
return f"https://github.com/{self.git_repo_owner}/{self.git_repo_name}"

@property
def automerge(self) -> bool | str:
"""
Expand Down
Loading

0 comments on commit 04c0a95

Please sign in to comment.