Skip to content

Commit 7994a17

Browse files
committed
fix: try to fix pygithub api
1 parent 66d729b commit 7994a17

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

comment.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import typing
22

33
from github import Github
4+
from github3 import GitHub as Github3
5+
from github3.pulls import PullRequest
6+
from github3.repos import Repository
47
from loguru import logger
58

69
from object import LineStat
@@ -22,16 +25,27 @@ def send_comment(token: str, repo_id: str, issue_number: int, content: str):
2225
pr.create_issue_comment(content)
2326

2427

25-
def send_code_comments(token: str, commit_id: str, repo_id: str, issue_number: int, lines: typing.List[LineStat]):
26-
g = Github(token)
27-
repo = g.get_repo(repo_id)
28-
pr = repo.get_pull(issue_number)
28+
def send_code_comments(
29+
token: str,
30+
commit_id: str,
31+
repo_id: str,
32+
issue_number: int,
33+
lines: typing.List[LineStat],
34+
):
35+
gg = Github3(token=token)
36+
owner, cur_repo = repo_id.split("/")
37+
repo: Repository = gg.repository(owner, cur_repo)
2938

30-
target = repo.get_commit(commit_id)
39+
target = repo.commit(commit_id)
3140
logger.info(f"target commit: {target}")
41+
42+
pr: PullRequest = repo.pull_request(issue_number)
43+
3244
for each_line in lines:
3345
if each_line.refScope.crossFileRefCount > 0:
34-
logger.info(f"leave comment in {each_line.fileName} L{each_line.lineNumber}")
46+
logger.info(
47+
f"leave comment in {each_line.fileName} L{each_line.lineNumber}"
48+
)
3549
pr.create_review_comment(
3650
f"[diffctx] cross file reference: {each_line.refScope.crossFileRefCount}",
3751
target,

main.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ def process_with_ai(raw: str) -> str:
9494
"""
9595

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

101101

102102
def convert_csv_to_md(csv_file) -> str:
103-
with open(csv_file, 'r') as f:
103+
with open(csv_file, "r") as f:
104104
markdown_table = csv_to_table(f, ",")
105105
md_table_raw = md_table(markdown_table)
106106
return md_table_raw
@@ -160,7 +160,9 @@ def main():
160160

161161
# feedback
162162
if not issue_number:
163-
logger.warning("This action is not triggered by a PR. Will not leave any comments.")
163+
logger.warning(
164+
"This action is not triggered by a PR. Will not leave any comments."
165+
)
164166
return
165167
send_comment(repo_token, repo_name, int(issue_number), final_content)
166168

object.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ class ReferenceScope(BaseModel):
77
crossDirRefCount: int
88

99
def is_safe(self):
10-
return self.totalRefCount == 0 and self.crossFileRefCount == 0 and self.crossDirRefCount == 0
10+
return (
11+
self.totalRefCount == 0
12+
and self.crossFileRefCount == 0
13+
and self.crossDirRefCount == 0
14+
)
1115

1216

1317
class LineStat(BaseModel):

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ loguru==0.7.0
22
PyGithub==1.58.1
33
openai==0.27.4
44
csvtomd==0.3.0
5-
pydantic~=1.7.3
5+
pydantic~=1.7.3
6+
github3.py~=3.2.0

0 commit comments

Comments
 (0)