Skip to content

Commit dc1c1f5

Browse files
chore: add scope args to get token (#82)
1 parent b7f2bce commit dc1c1f5

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/codegen/git/clients/github_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class GithubClient:
2525
@classmethod
2626
def from_repo_config(cls, repo_config: RepoConfig) -> Self:
2727
gh_wrapper = cls()
28-
gh_wrapper.read_client = gh_wrapper._create_client_for_repo(repo_config)
29-
gh_wrapper._write_client = gh_wrapper._create_client_for_repo(repo_config)
28+
gh_wrapper.read_client = gh_wrapper._create_client_for_repo(repo_config, github_scope=GithubScope.READ)
29+
gh_wrapper._write_client = gh_wrapper._create_client_for_repo(repo_config, github_scope=GithubScope.WRITE)
3030
return gh_wrapper
3131

3232
@classmethod
@@ -37,8 +37,8 @@ def from_token(cls, token: str | None = None) -> Self:
3737
gh_wrapper._write_client = Github(token, base_url=cls.base_url)
3838
return gh_wrapper
3939

40-
def _create_client_for_repo(self, repo_config: RepoConfig) -> Github:
41-
token = get_token_for_repo_config(repo_config=repo_config, github_type=self.type)
40+
def _create_client_for_repo(self, repo_config: RepoConfig, github_scope: GithubScope = GithubScope.READ) -> Github:
41+
token = get_token_for_repo_config(repo_config=repo_config, github_type=self.type, github_scope=github_scope)
4242
return Github(token, base_url=self.base_url)
4343

4444
def _get_client_for_scope(self, github_scope: GithubScope) -> Github:

src/codegen/git/configs/token.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import logging
22

33
from codegen.git.configs.config import config
4-
from codegen.git.schemas.github import GithubType
4+
from codegen.git.schemas.github import GithubScope, GithubType
55
from codegen.git.schemas.repo_config import RepoConfig
66

77
logger = logging.getLogger(__name__)
88

99

10-
def get_token_for_repo_config(repo_config: RepoConfig, github_type: GithubType = GithubType.GithubEnterprise) -> str:
11-
# TODO: implement config such that we can retrieve tokens for different repos
10+
def get_token_for_repo_config(
11+
repo_config: RepoConfig,
12+
github_type: GithubType = GithubType.GithubEnterprise,
13+
github_scope: GithubScope = GithubScope.READ,
14+
) -> str:
15+
# TODO: implement config such that we can retrieve tokens for different repos + read/write scopes
1216
if github_type == GithubType.GithubEnterprise:
1317
return config.LOWSIDE_TOKEN
1418
elif github_type == GithubType.Github:

0 commit comments

Comments
 (0)