Skip to content
This repository was archived by the owner on Jul 23, 2025. It is now read-only.

Commit e7b8cb9

Browse files
feat: Add documentation review prompt (#83)
Co-authored-by: Maxime Rey <87315832+MaxJPRey@users.noreply.github.com>
1 parent 47dc441 commit e7b8cb9

File tree

8 files changed

+284
-116
lines changed

8 files changed

+284
-116
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,4 @@ cython_debug/
157157
#.idea/
158158

159159
# End of https://www.toptal.com/developers/gitignore/api/python
160+
.vscode/

.pre-commit-config.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@ repos:
88
- id: isort
99

1010
- repo: https://github.com/psf/black
11-
rev: 23.7.0 # IF VERSION CHANGES --> MODIFY "blacken-docs" MANUALLY AS WELL!!
11+
rev: 23.9.1 # IF VERSION CHANGES --> MODIFY "blacken-docs" MANUALLY AS WELL!!
1212
hooks:
1313
- id: black
14-
args:
15-
- --line-length=88
1614

1715
- repo: https://github.com/adamchainz/blacken-docs
1816
rev: 1.15.0
1917
hooks:
2018
- id: blacken-docs
21-
additional_dependencies: [black==23.7.0]
19+
additional_dependencies: [black==23.9.1]
2220

2321
- repo: https://github.com/PyCQA/flake8
2422
rev: 6.1.0

src/review/bot/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Copyright (c) 2023 ANSYS, Inc. All rights reserved
21
"""OpenAI LLM powered Review-bot."""
32

43
try:
@@ -9,4 +8,4 @@
98
__version__ = importlib_metadata.version(__name__.replace(".", "-"))
109

1110
from .misc import open_logger
12-
from .open_ai_interface import review_patch, review_patch_local
11+
from .open_ai_interface import review_file, review_folder, review_patch, review_patch_local

src/review/bot/gh_interface.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313

1414
def _fetch_file_content(file_data, headers):
1515
"""Fetch the content of a single file."""
16-
content_response = requests.get(
17-
file_data["contents_url"], headers=headers, timeout=10
18-
)
16+
content_response = requests.get(file_data["contents_url"], headers=headers, timeout=10)
1917

2018
if content_response.status_code == 200:
2119
content = content_response.json()
@@ -73,28 +71,15 @@ def get_changed_files_and_contents(owner, repo, pull_number, gh_access_token=Non
7371
7472
"""
7573
access_token = _get_gh_token() if gh_access_token is None else gh_access_token
76-
url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{pull_number}"
77-
# url = f"https://github.com/{owner}/{repo}/pull/{pull_number}.diff"
78-
headers = {
79-
"Authorization": f"Bearer {access_token}",
80-
# "Content-type": "application/vnd.github.diff",
81-
}
82-
83-
response = requests.get(url, headers=headers, timeout=10)
84-
if response.status_code != 200:
85-
raise RuntimeError(
86-
f"Error fetching pull request files from:\n{url}\n\n{response.status_code}"
87-
)
88-
89-
files = response.json()
9074

9175
url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{pull_number}/files"
9276
headers = {"Authorization": f"Bearer {access_token}"}
9377
response = requests.get(url, headers=headers, timeout=10)
9478

9579
if response.status_code != 200:
96-
print(f"Error fetching pull request files: {response.status_code}")
97-
return
80+
raise RuntimeError(
81+
f"Error fetching pull request files from:\n{url}\n\n{response.status_code}"
82+
)
9883

9984
files = response.json()
10085
threads = []

src/review/bot/misc.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,13 @@ def get_client(config_file: str = None) -> Union[OpenAI, AzureOpenAI]:
7171
raise OSError('Missing "OPEN_AI_TOKEN" environment variable')
7272

7373
if api_type == "azure":
74-
client = AzureOpenAI(
75-
azure_endpoint=api_base, api_key=access_token, api_version=api_version
76-
)
74+
client = AzureOpenAI(azure_endpoint=api_base, api_key=access_token, api_version=api_version)
7775
else:
7876
client = OpenAI(api_key=access_token)
7977
return client
8078

8179

82-
def open_logger(
83-
loglevel="DEBUG", formatstr="%(name)-20s - %(levelname)-8s - %(message)s"
84-
):
80+
def open_logger(loglevel="DEBUG", formatstr="%(name)-20s - %(levelname)-8s - %(message)s"):
8581
"""Start logging to standard output.
8682
8783
Parameters
@@ -301,13 +297,9 @@ def parse_suggestions(text_block: str):
301297
"Suggestion does not contain a path to a file in the proper position, it will be ignored."
302298
)
303299
else:
304-
LOG.warning(
305-
"Suggestion is missing some section, this suggestion will be ignored."
306-
)
300+
LOG.warning("Suggestion is missing some section, this suggestion will be ignored.")
307301
if not validate_output(suggestions):
308-
raise ValidationErrorException(
309-
"Output format is not well formed.", llm_output=text_block
310-
)
302+
raise ValidationErrorException("Output format is not well formed.", llm_output=text_block)
311303
if len(suggestions) == 0:
312304
raise ValidationErrorException(
313305
"Output is empty due to all suggestions being malformed.",

0 commit comments

Comments
 (0)