Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions src/codegen/git/clients/git_repo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
gh_client: GithubClient
_repo: Repository

def __init__(self, repo_config: RepoConfig) -> None:
def __init__(self, repo_config: RepoConfig, access_token: str) -> None:
self.repo_config = repo_config
self.gh_client = self._create_github_client()
self.gh_client = self._create_github_client(token=access_token)
self._repo = self._create_client()

def _create_github_client(self) -> GithubClient:
return GithubClient()
def _create_github_client(self, token: str) -> GithubClient:
return GithubClient(token=token)

def _create_client(self) -> Repository:
client = self.gh_client.get_repo_by_full_name(self.repo_config.full_name)
Expand Down Expand Up @@ -177,9 +177,9 @@
def get_or_create_pull(
self,
head_branch_name: str,
base_branch_name: str | None = None, # type: ignore[assignment]

Check failure on line 180 in src/codegen/git/clients/git_repo_client.py

View workflow job for this annotation

GitHub Actions / mypy

error: Unused "type: ignore" comment [unused-ignore]
title: str | None = None, # type: ignore[assignment]

Check failure on line 181 in src/codegen/git/clients/git_repo_client.py

View workflow job for this annotation

GitHub Actions / mypy

error: Unused "type: ignore" comment [unused-ignore]
body: str | None = None, # type: ignore[assignment]

Check failure on line 182 in src/codegen/git/clients/git_repo_client.py

View workflow job for this annotation

GitHub Actions / mypy

error: Unused "type: ignore" comment [unused-ignore]
) -> PullRequest | None:
pull = self.get_pull_by_branch_and_state(head_branch_name=head_branch_name, base_branch_name=base_branch_name)
if pull:
Expand Down Expand Up @@ -224,7 +224,7 @@
body="",
)
# TODO: handle PR not mergeable due to merge conflicts
merge = squash_pr.merge(commit_message=squash_commit_msg, commit_title=squash_commit_title, merge_method="squash") # type: ignore[arg-type]

Check failure on line 227 in src/codegen/git/clients/git_repo_client.py

View workflow job for this annotation

GitHub Actions / mypy

error: Item "None" of "PullRequest | None" has no attribute "merge" [union-attr]

def edit_pull(self, pull: PullRequest, title: Opt[str] = NotSet, body: Opt[str] = NotSet, state: Opt[str] = NotSet) -> None:
writable_pr = self.repo.get_pull(pull.number)
Expand Down
14 changes: 2 additions & 12 deletions src/codegen/git/clients/github_client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import logging
from typing import Self

from github import Consts
from github.GithubException import UnknownObjectException
from github.MainClass import Github
from github.Organization import Organization
from github.Repository import Repository

from codegen.git.configs.config import config

logger = logging.getLogger(__name__)


Expand All @@ -18,16 +15,9 @@ class GithubClient:
base_url: str
_client: Github

def __init__(self, base_url: str = Consts.DEFAULT_BASE_URL):
def __init__(self, token: str, base_url: str = Consts.DEFAULT_BASE_URL):
self.base_url = base_url
self._client = Github(config.GITHUB_TOKEN, base_url=base_url)

@classmethod
def from_token(cls, token: str | None = None) -> Self:
"""Option to create a git client from a token"""
gh_wrapper = cls()
gh_wrapper._client = Github(token, base_url=cls.base_url)
return gh_wrapper
self._client = Github(token, base_url=base_url)

@property
def client(self) -> Github:
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/git/repo_operator/remote_repo_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"""A wrapper around GitPython to make it easier to interact with a cloned lowside repo."""

# __init__ attributes
repo_config: RepoConfig

Check failure on line 27 in src/codegen/git/repo_operator/remote_repo_operator.py

View workflow job for this annotation

GitHub Actions / mypy

error: Incompatible types in assignment (expression has type "RepoConfig", base class "RepoOperator" defined the type as "BaseRepoConfig") [assignment]
base_dir: str

# lazy attributes
Expand All @@ -42,7 +42,7 @@
bot_commit: bool = True,
access_token: str | None = None,
) -> None:
super().__init__(repo_config=repo_config, base_dir=base_dir, bot_commit=bot_commit, access_token=access_token)

Check failure on line 45 in src/codegen/git/repo_operator/remote_repo_operator.py

View workflow job for this annotation

GitHub Actions / mypy

error: Argument "repo_config" to "__init__" of "RepoOperator" has incompatible type "RepoConfig"; expected "BaseRepoConfig" [arg-type]
self.setup_repo_dir(setup_option=setup_option, shallow=shallow)

####################################################################################################################
Expand All @@ -58,7 +58,7 @@
@property
def remote_git_repo(self) -> GitRepoClient:
if not self._remote_git_repo:
self._remote_git_repo = GitRepoClient(self.repo_config)
self._remote_git_repo = GitRepoClient(self.repo_config, access_token=self.access_token)

Check failure on line 61 in src/codegen/git/repo_operator/remote_repo_operator.py

View workflow job for this annotation

GitHub Actions / mypy

error: Argument "access_token" to "GitRepoClient" has incompatible type "str | None"; expected "str" [arg-type]
return self._remote_git_repo

@property
Expand All @@ -68,7 +68,7 @@
return self._default_branch

@property
def codeowners_parser(self) -> CodeOwnersParser | None:

Check failure on line 71 in src/codegen/git/repo_operator/remote_repo_operator.py

View workflow job for this annotation

GitHub Actions / mypy

error: Signature of "codeowners_parser" incompatible with supertype "RepoOperator" [override]
if not self._codeowners_parser:
self._codeowners_parser = create_codeowners_parser_for_repo(self.remote_git_repo)
return self._codeowners_parser
Expand Down Expand Up @@ -186,7 +186,7 @@
return res

@cached_property
def base_url(self) -> str | None:

Check failure on line 189 in src/codegen/git/repo_operator/remote_repo_operator.py

View workflow job for this annotation

GitHub Actions / mypy

error: Signature of "base_url" incompatible with supertype "RepoOperator" [override]
repo_config = self.repo_config
clone_url = get_clone_url_for_repo_config(repo_config)
branch = self.get_active_branch_or_commit()
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/codegen/runner/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


@pytest.fixture(autouse=True)
def repo_config() -> RepoConfig:

Check failure on line 26 in tests/integration/codegen/runner/conftest.py

View workflow job for this annotation

GitHub Actions / mypy

error: The return type of a generator function should be "Generator" or one of its supertypes [misc]
yield RepoConfig(
id=321,
name="Kevin-s-Adventure-Game",
Expand All @@ -41,7 +41,7 @@

@pytest.fixture(autouse=True)
def git_repo_client(repo_config: RepoConfig) -> GitRepoClient:
yield GitRepoClient(repo_config=repo_config)
yield GitRepoClient(repo_config=repo_config, access_token=config.GITHUB_TOKEN)


@pytest.fixture(autouse=True)
Expand Down