Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend new Git Backend #2812

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bb39aaf
add push_to_url
ytausch May 28, 2024
a9b1a60
clean up auto_tick:run signature
ytausch May 28, 2024
c9ad70d
add feedstock attributes to FeedstockContext
ytausch May 29, 2024
77f6cff
add create_pull_request to git backend
ytausch May 30, 2024
c20209a
git add and git commit
ytausch May 30, 2024
60e8f3f
add --allow-empty to git
ytausch May 30, 2024
3df0ec3
add comment_on_pull_request
ytausch May 31, 2024
b832288
add rev-parse HEAD command
ytausch May 31, 2024
e5acd58
add diffed_files to git CLI
ytausch May 31, 2024
b07be04
feat: GitCLi supports hiding tokens
ytausch Jun 11, 2024
c967c20
add more tests for token hiding
ytausch Jun 11, 2024
4235fe5
add feedstock-related data to FeedstockContext
ytausch Jun 13, 2024
cd7c723
use get_bot_token instead of sensitive_env
ytausch Jun 13, 2024
d8f9344
token hiding: no context manager, automatically if token is known
ytausch Jun 13, 2024
623daef
hide tokens in Git Backends automatically, push to repository
ytausch Jun 15, 2024
ed0247d
FIX: forking should do nothing if already exists
ytausch Jun 15, 2024
6bc7714
get_remote_url now redirects forks to upstream
ytausch Jun 15, 2024
2501ba9
detect duplicate pull requests
ytausch Jun 15, 2024
d92ebc9
refactor auto_tick.run using the new git backend
ytausch Jun 15, 2024
3a7589d
refactor: solvability checks in separate method
ytausch Jun 16, 2024
4031866
use temporary directory instead of managing the local feedstock dir m…
ytausch Jun 16, 2024
0983674
dependency injection for GitPlatformBackend
ytausch Jun 24, 2024
ac27f2f
small fixes
ytausch Jun 25, 2024
e013f8c
add tests for _prepare_feedstock_repository, correct import
ytausch Jun 27, 2024
21d4d2e
Dry Run: forking non-existent repo should fail
ytausch Jun 27, 2024
038778f
add tests for commit_migration
ytausch Jun 28, 2024
8438ed5
add tests for is_solvability_check needed (1/2)
ytausch Jun 29, 2024
07ddcba
remove migrators_dir check
ytausch Jul 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
744 changes: 449 additions & 295 deletions conda_forge_tick/auto_tick.py

Large diffs are not rendered by default.

84 changes: 79 additions & 5 deletions conda_forge_tick/contexts.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from __future__ import annotations

import os
import tempfile
import typing
from collections.abc import Iterator
from contextlib import contextmanager
from dataclasses import dataclass
from pathlib import Path

from networkx import DiGraph

from conda_forge_tick.lazy_json_backends import load
from conda_forge_tick.utils import get_keys_default

if typing.TYPE_CHECKING:
from conda_forge_tick.migrators_types import AttrsTypedDict
Expand All @@ -27,10 +34,10 @@ class MigratorSessionContext:
dry_run: bool = True


@dataclass
@dataclass(frozen=True)
class FeedstockContext:
feedstock_name: str
attrs: "AttrsTypedDict"
attrs: AttrsTypedDict
_default_branch: str = None

@property
Expand All @@ -40,6 +47,73 @@ def default_branch(self):
else:
return self._default_branch

@default_branch.setter
def default_branch(self, v):
self._default_branch = v
@property
def git_repo_owner(self) -> str:
return "conda-forge"

@property
def git_repo_name(self) -> str:
return f"{self.feedstock_name}-feedstock"

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

@property
def automerge(self) -> bool | str:
"""
Get the automerge setting of the feedstock.

Note: A better solution to implement this is to use the NodeAttributes Pydantic
model for the attrs field. This will be done in the future.
"""
return get_keys_default(
self.attrs,
["conda-forge.yml", "bot", "automerge"],
{},
False,
)

@property
def check_solvable(self) -> bool:
"""
Get the check_solvable setting of the feedstock.

Note: A better solution to implement this is to use the NodeAttributes Pydantic
model for the attrs field. This will be done in the future.
"""
return get_keys_default(
self.attrs,
["conda-forge.yml", "bot", "check_solvable"],
{},
False,
)

@contextmanager
def reserve_clone_directory(self) -> Iterator[ClonedFeedstockContext]:
"""
Reserve a temporary directory for the feedstock repository that will be available within the context manager.
The returned context object will contain the path to the feedstock repository in local_clone_dir.
After the context manager exits, the temporary directory will be deleted.
"""
with tempfile.TemporaryDirectory() as tmpdir:
local_clone_dir = Path(tmpdir) / self.git_repo_name
local_clone_dir.mkdir()
yield ClonedFeedstockContext(
**self.__dict__,
local_clone_dir=local_clone_dir,
)


@dataclass(frozen=True, kw_only=True)
class ClonedFeedstockContext(FeedstockContext):
"""
A FeedstockContext object that has reserved a temporary directory for the feedstock repository.
"""

# Implementation Note: Keep this class frozen or there will be consistency issues if someone modifies
# a ClonedFeedstockContext object in place - it will not be reflected in the original FeedstockContext object.
local_clone_dir: Path
Loading
Loading