diff --git a/src/codegen/git/clients/github_client.py b/src/codegen/git/clients/github_client.py index e2571b05f..903cdbfd8 100644 --- a/src/codegen/git/clients/github_client.py +++ b/src/codegen/git/clients/github_client.py @@ -25,8 +25,8 @@ class GithubClient: @classmethod def from_repo_config(cls, repo_config: RepoConfig) -> Self: gh_wrapper = cls() - gh_wrapper.read_client = gh_wrapper._create_client_for_repo(repo_config) - gh_wrapper._write_client = gh_wrapper._create_client_for_repo(repo_config) + gh_wrapper.read_client = gh_wrapper._create_client_for_repo(repo_config, github_scope=GithubScope.READ) + gh_wrapper._write_client = gh_wrapper._create_client_for_repo(repo_config, github_scope=GithubScope.WRITE) return gh_wrapper @classmethod @@ -37,8 +37,8 @@ def from_token(cls, token: str | None = None) -> Self: gh_wrapper._write_client = Github(token, base_url=cls.base_url) return gh_wrapper - def _create_client_for_repo(self, repo_config: RepoConfig) -> Github: - token = get_token_for_repo_config(repo_config=repo_config, github_type=self.type) + def _create_client_for_repo(self, repo_config: RepoConfig, github_scope: GithubScope = GithubScope.READ) -> Github: + token = get_token_for_repo_config(repo_config=repo_config, github_type=self.type, github_scope=github_scope) return Github(token, base_url=self.base_url) def _get_client_for_scope(self, github_scope: GithubScope) -> Github: diff --git a/src/codegen/git/configs/token.py b/src/codegen/git/configs/token.py index de1a543c3..61283c2e8 100644 --- a/src/codegen/git/configs/token.py +++ b/src/codegen/git/configs/token.py @@ -1,14 +1,18 @@ import logging from codegen.git.configs.config import config -from codegen.git.schemas.github import GithubType +from codegen.git.schemas.github import GithubScope, GithubType from codegen.git.schemas.repo_config import RepoConfig logger = logging.getLogger(__name__) -def get_token_for_repo_config(repo_config: RepoConfig, github_type: GithubType = GithubType.GithubEnterprise) -> str: - # TODO: implement config such that we can retrieve tokens for different repos +def get_token_for_repo_config( + repo_config: RepoConfig, + github_type: GithubType = GithubType.GithubEnterprise, + github_scope: GithubScope = GithubScope.READ, +) -> str: + # TODO: implement config such that we can retrieve tokens for different repos + read/write scopes if github_type == GithubType.GithubEnterprise: return config.LOWSIDE_TOKEN elif github_type == GithubType.Github: