Skip to content

Commit

Permalink
fix: try to fix pygithub api
Browse files Browse the repository at this point in the history
  • Loading branch information
williamfzc committed Apr 19, 2023
1 parent 66d729b commit 9210c35
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
29 changes: 21 additions & 8 deletions comment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import typing

from github import Github
from github3 import GitHub as Github3
from github3.pulls import PullRequest
from github3.repos import Repository
from loguru import logger

from object import LineStat
Expand All @@ -22,19 +25,29 @@ def send_comment(token: str, repo_id: str, issue_number: int, content: str):
pr.create_issue_comment(content)


def send_code_comments(token: str, commit_id: str, repo_id: str, issue_number: int, lines: typing.List[LineStat]):
g = Github(token)
repo = g.get_repo(repo_id)
pr = repo.get_pull(issue_number)
def send_code_comments(
token: str,
commit_id: str,
repo_id: str,
issue_number: int,
lines: typing.List[LineStat],
):
gg = Github3(token=token)
owner, cur_repo = repo_id.split("/")
repo: Repository = gg.repository(owner, cur_repo)

logger.info(f"target commit: {commit_id}")
pr: PullRequest = repo.pull_request(issue_number)
logger.info(f"target pr: {issue_number}")

target = repo.get_commit(commit_id)
logger.info(f"target commit: {target}")
for each_line in lines:
if each_line.refScope.crossFileRefCount > 0:
logger.info(f"leave comment in {each_line.fileName} L{each_line.lineNumber}")
logger.info(
f"leave comment in {each_line.fileName} L{each_line.lineNumber}"
)
pr.create_review_comment(
f"[diffctx] cross file reference: {each_line.refScope.crossFileRefCount}",
target,
commit_id,
each_line.fileName,
each_line.lineNumber,
)
10 changes: 6 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ def process_with_ai(raw: str) -> str:
"""

completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": req}])
model="gpt-3.5-turbo", messages=[{"role": "user", "content": req}]
)
return completion.choices[0].message.content


def convert_csv_to_md(csv_file) -> str:
with open(csv_file, 'r') as f:
with open(csv_file, "r") as f:
markdown_table = csv_to_table(f, ",")
md_table_raw = md_table(markdown_table)
return md_table_raw
Expand Down Expand Up @@ -160,7 +160,9 @@ def main():

# feedback
if not issue_number:
logger.warning("This action is not triggered by a PR. Will not leave any comments.")
logger.warning(
"This action is not triggered by a PR. Will not leave any comments."
)
return
send_comment(repo_token, repo_name, int(issue_number), final_content)

Expand Down
6 changes: 5 additions & 1 deletion object.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ class ReferenceScope(BaseModel):
crossDirRefCount: int

def is_safe(self):
return self.totalRefCount == 0 and self.crossFileRefCount == 0 and self.crossDirRefCount == 0
return (
self.totalRefCount == 0
and self.crossFileRefCount == 0
and self.crossDirRefCount == 0
)


class LineStat(BaseModel):
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ loguru==0.7.0
PyGithub==1.58.1
openai==0.27.4
csvtomd==0.3.0
pydantic~=1.7.3
pydantic~=1.7.3
github3.py~=3.2.0

0 comments on commit 9210c35

Please sign in to comment.