Skip to content

Commit 68c932d

Browse files
Merge branch 'develop' into changelong-generation
2 parents f57c00c + 061eec9 commit 68c932d

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

src/codegen/git/clients/git_repo_client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@
2626
class GitRepoClient:
2727
"""Wrapper around PyGithub's Remote Repository."""
2828

29-
repo: RepoConfig
29+
repo_config: RepoConfig
3030
github_type: GithubType = GithubType.GithubEnterprise
3131
gh_client: GithubClientType
3232
read_client: Repository
3333
access_scope: GithubScope
3434
__write_client: Repository | None # Will not be initialized if access scope is read-only
3535

3636
def __init__(self, repo_config: RepoConfig, github_type: GithubType = GithubType.GithubEnterprise, access_scope: GithubScope = GithubScope.READ) -> None:
37-
self.repo = repo_config
37+
self.repo_config = repo_config
3838
self.github_type = github_type
39-
self.gh_client = GithubClientFactory.create_from_repo(self.repo, github_type)
39+
self.gh_client = GithubClientFactory.create_from_repo(self.repo_config, github_type)
4040
self.read_client = self._create_client(GithubScope.READ)
4141
self.__write_client = self._create_client(GithubScope.WRITE) if access_scope == GithubScope.WRITE else None
4242
self.access_scope = access_scope
4343

4444
def _create_client(self, github_scope: GithubScope = GithubScope.READ) -> Repository:
45-
client = self.gh_client.get_repo_by_full_name(self.repo.full_name, github_scope=github_scope)
45+
client = self.gh_client.get_repo_by_full_name(self.repo_config.full_name, github_scope=github_scope)
4646
if not client:
47-
msg = f"Repo {self.repo.full_name} not found in {self.github_type.value}!"
47+
msg = f"Repo {self.repo_config.full_name} not found in {self.github_type.value}!"
4848
raise ValueError(msg)
4949
return client
5050

@@ -61,7 +61,7 @@ def _write_client(self) -> Repository:
6161

6262
@property
6363
def id(self) -> int:
64-
return self.repo.id
64+
return self.repo_config.id
6565

6666
@property
6767
def default_branch(self) -> str:
@@ -160,7 +160,7 @@ def get_pull_by_branch_and_state(
160160
if not base_branch_name:
161161
base_branch_name = self.default_branch
162162

163-
head_branch_name = f"{self.repo.organization_name}:{head_branch_name}"
163+
head_branch_name = f"{self.repo_config.organization_name}:{head_branch_name}"
164164

165165
# retrieve all pulls ordered by created descending
166166
prs = self.read_client.get_pulls(base=base_branch_name, head=head_branch_name, state=state, sort="created", direction="desc")

src/codegen/git/clients/github_client.py

Lines changed: 3 additions & 3 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, github_scope=GithubScope.READ)
29-
gh_wrapper._write_client = gh_wrapper._create_client_for_repo(repo_config, github_scope=GithubScope.WRITE)
28+
gh_wrapper.read_client = gh_wrapper._create_client_for_repo_config(repo_config, github_scope=GithubScope.READ)
29+
gh_wrapper._write_client = gh_wrapper._create_client_for_repo_config(repo_config, github_scope=GithubScope.WRITE)
3030
return gh_wrapper
3131

3232
@classmethod
@@ -37,7 +37,7 @@ 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_scope: GithubScope = GithubScope.READ) -> Github:
40+
def _create_client_for_repo_config(self, repo_config: RepoConfig, github_scope: GithubScope = GithubScope.READ) -> Github:
4141
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

src/codegen/git/utils/codeowner_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ def create_codeowners_parser_for_repo(py_github_repo: GitRepoClient) -> CodeOwne
3131
return codeowners
3232
except Exception as e:
3333
continue
34-
logger.info(f"Failed to create CODEOWNERS parser for repo: {py_github_repo.repo.id}. Returning None.")
34+
logger.info(f"Failed to create CODEOWNERS parser for repo: {py_github_repo.repo_config.id}. Returning None.")
3535
return None
3636

3737

3838
def get_codeowners_for_pull(repo: GitRepoClient, pull: PullRequest) -> list[str]:
3939
codeowners_parser = create_codeowners_parser_for_repo(repo)
4040
if not codeowners_parser:
41-
logger.warning(f"Failed to create codeowners parser for repo: {repo.repo.id}. Returning empty list.")
41+
logger.warning(f"Failed to create codeowners parser for repo: {repo.repo_config.id}. Returning empty list.")
4242
return []
4343
codeowners_for_pull_set = set()
4444
pull_files = pull.get_files()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import logging
2+
import tempfile
3+
4+
from fastapi import FastAPI
5+
6+
from codegen.runner.models.apis import (
7+
RUN_ON_STRING_ENDPOINT,
8+
GetRunOnStringRequest,
9+
GetRunOnStringResult,
10+
)
11+
from codegen.runner.sandbox.executor import SandboxExecutor
12+
from codegen.sdk.codebase.factory.get_session import get_codebase_session
13+
from codegen.sdk.enums import ProgrammingLanguage
14+
from codegen.shared.compilation.string_to_code import create_execute_function_from_codeblock
15+
16+
logger = logging.getLogger(__name__)
17+
app = FastAPI()
18+
19+
20+
@app.post(RUN_ON_STRING_ENDPOINT)
21+
async def run_on_string(request: GetRunOnStringRequest) -> GetRunOnStringResult:
22+
logger.info(f"====[ run_on_string ]====\n> Codemod source: {request.codemod_source}\n> Input: {request.files}\n> Language: {request.language}\n")
23+
language = ProgrammingLanguage(request.language.upper())
24+
with get_codebase_session(tmpdir=tempfile.mkdtemp(), files=request.files, programming_language=language) as codebase:
25+
executor = SandboxExecutor(codebase)
26+
code_to_exec = create_execute_function_from_codeblock(codeblock=request.codemod_source)
27+
result = await executor.execute(code_to_exec)
28+
logger.info(f"Result: {result}")
29+
return GetRunOnStringResult(result=result)

0 commit comments

Comments
 (0)