Skip to content

chore: returns issue comment #607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2025
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
5 changes: 3 additions & 2 deletions src/codegen/git/clients/git_repo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from github.Commit import Commit
from github.GithubException import GithubException, UnknownObjectException
from github.GithubObject import NotSet, Opt
from github.IssueComment import IssueComment
from github.Label import Label
from github.PullRequest import PullRequest
from github.Repository import Repository
Expand Down Expand Up @@ -37,7 +38,7 @@
return GithubClient(token=token)

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

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

View workflow job for this annotation

GitHub Actions / mypy

error: Argument 1 to "get_repo_by_full_name" of "GithubClient" has incompatible type "str | None"; expected "str" [arg-type]
if not client:
msg = f"Repo {self.repo_config.full_name} not found!"
raise ValueError(msg)
Expand Down Expand Up @@ -126,10 +127,10 @@
self,
pull: PullRequest,
body: str,
) -> None:
) -> IssueComment:
# TODO: add protections (ex: can write to PR)
writeable_pr = self.repo.get_pull(pull.number)
writeable_pr.create_issue_comment(body=body)
return writeable_pr.create_issue_comment(body=body)

####################################################################################################################
# PULL REQUESTS
Expand Down Expand Up @@ -173,9 +174,9 @@
def get_or_create_pull(
self,
head_branch_name: str,
base_branch_name: str | None = None, # type: ignore[assignment]

Check failure on line 177 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 178 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 179 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 @@ -220,7 +221,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 224 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
6 changes: 4 additions & 2 deletions src/codegen/git/repo_operator/repo_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from git import Diff, GitCommandError, InvalidGitRepositoryError, Remote
from git import Repo as GitCLI
from git.remote import PushInfoList
from github.IssueComment import IssueComment
from github.PullRequest import PullRequest

from codegen.configs.models.secrets import DefaultSecrets
Expand Down Expand Up @@ -142,7 +143,7 @@
email_level = None
levels = ["system", "global", "user", "repository"]
for level in levels:
with git_cli.config_reader(level) as reader:

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

View workflow job for this annotation

GitHub Actions / mypy

error: Argument 1 to "config_reader" of "Repo" has incompatible type "str"; expected "Literal['system', 'global', 'user', 'repository'] | None" [arg-type]
if reader.has_option("user", "name") and not username:
username = reader.get("user", "name")
user_level = level
Expand Down Expand Up @@ -554,7 +555,7 @@
return content
except UnicodeDecodeError:
print(f"Warning: Unable to decode file {file_path}. Skipping.")
return None

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

View workflow job for this annotation

GitHub Actions / mypy

error: Incompatible return value type (got "None", expected "str") [return-value]

def write_file(self, relpath: str, content: str) -> None:
"""Writes file content to disk"""
Expand Down Expand Up @@ -621,7 +622,7 @@
filepaths = self.get_filepaths_for_repo(ignore_list)
# Iterate through files and yield contents
for rel_filepath in filepaths:
rel_filepath: str

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

View workflow job for this annotation

GitHub Actions / mypy

error: Name "rel_filepath" already defined on line 624 [no-redef]
filepath = os.path.join(self.repo_path, rel_filepath)

# Filter by subdirectory (includes full filenames)
Expand Down Expand Up @@ -652,7 +653,7 @@
list_files = []

for rel_filepath in self.git_cli.git.ls_files().split("\n"):
rel_filepath: str

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

View workflow job for this annotation

GitHub Actions / mypy

error: Name "rel_filepath" already defined on line 655 [no-redef]
if subdirs and not any(d in rel_filepath for d in subdirs):
continue
if extensions is None or any(rel_filepath.endswith(e) for e in extensions):
Expand All @@ -676,7 +677,7 @@

def get_modified_files_in_last_n_days(self, days: int = 1) -> tuple[list[str], list[str]]:
"""Returns a list of files modified and deleted in the last n days"""
modified_files = []

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

View workflow job for this annotation

GitHub Actions / mypy

error: Need type annotation for "modified_files" (hint: "modified_files: list[<type>] = ...") [var-annotated]
deleted_files = []
allowed_extensions = [".py"]

Expand Down Expand Up @@ -717,7 +718,7 @@
"""Returns the data associated with a PR"""
return self.remote_git_repo.get_pr_data(pr_number)

def create_pr_comment(self, pr_number: int, body: str) -> None:
def create_pr_comment(self, pr_number: int, body: str) -> IssueComment:
"""Create a general comment on a pull request.

Args:
Expand All @@ -726,7 +727,8 @@
"""
pr = self.remote_git_repo.get_pull_safe(pr_number)
if pr:
self.remote_git_repo.create_issue_comment(pr, body)
comment = self.remote_git_repo.create_issue_comment(pr, body)
return comment

def create_pr_review_comment(
self,
Expand Down