Skip to content

Commit fdfe835

Browse files
caroljung-cgtkucar
authored and
tkucar
committed
Fix GithubClient constructor (#352)
1 parent 609c0b6 commit fdfe835

File tree

4 files changed

+8
-18
lines changed

4 files changed

+8
-18
lines changed

src/codegen/git/clients/git_repo_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ class GitRepoClient:
2828
gh_client: GithubClient
2929
_repo: Repository
3030

31-
def __init__(self, repo_config: RepoConfig) -> None:
31+
def __init__(self, repo_config: RepoConfig, access_token: str) -> None:
3232
self.repo_config = repo_config
33-
self.gh_client = self._create_github_client()
33+
self.gh_client = self._create_github_client(token=access_token)
3434
self._repo = self._create_client()
3535

36-
def _create_github_client(self) -> GithubClient:
37-
return GithubClient()
36+
def _create_github_client(self, token: str) -> GithubClient:
37+
return GithubClient(token=token)
3838

3939
def _create_client(self) -> Repository:
4040
client = self.gh_client.get_repo_by_full_name(self.repo_config.full_name)

src/codegen/git/clients/github_client.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import logging
2-
from typing import Self
32

43
from github import Consts
54
from github.GithubException import UnknownObjectException
65
from github.MainClass import Github
76
from github.Organization import Organization
87
from github.Repository import Repository
98

10-
from codegen.git.configs.config import config
11-
129
logger = logging.getLogger(__name__)
1310

1411

@@ -18,16 +15,9 @@ class GithubClient:
1815
base_url: str
1916
_client: Github
2017

21-
def __init__(self, base_url: str = Consts.DEFAULT_BASE_URL):
18+
def __init__(self, token: str, base_url: str = Consts.DEFAULT_BASE_URL):
2219
self.base_url = base_url
23-
self._client = Github(config.GITHUB_TOKEN, base_url=base_url)
24-
25-
@classmethod
26-
def from_token(cls, token: str | None = None) -> Self:
27-
"""Option to create a git client from a token"""
28-
gh_wrapper = cls()
29-
gh_wrapper._client = Github(token, base_url=cls.base_url)
30-
return gh_wrapper
20+
self._client = Github(token, base_url=base_url)
3121

3222
@property
3323
def client(self) -> Github:

src/codegen/git/repo_operator/remote_repo_operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def clone_url(self) -> str:
5858
@property
5959
def remote_git_repo(self) -> GitRepoClient:
6060
if not self._remote_git_repo:
61-
self._remote_git_repo = GitRepoClient(self.repo_config)
61+
self._remote_git_repo = GitRepoClient(self.repo_config, access_token=self.access_token)
6262
return self._remote_git_repo
6363

6464
@property

tests/integration/codegen/runner/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def op(repo_config: RepoConfig) -> Generator[RemoteRepoOperator, None, None]:
4141

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

4646

4747
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)