Skip to content

Commit f818387

Browse files
File Review Tool (#46)
Add file review tool
1 parent 145cddd commit f818387

File tree

5 files changed

+450
-0
lines changed

5 files changed

+450
-0
lines changed

tools/review_file/.env.sample

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Azure OpenAI resource endpoint (no trailing slash)
2+
AZURE_OPENAI_ENDPOINT="<YOUR_AZURE_OPENAI_ENDPOINT>"
3+
4+
# Deployment name you configured in Azure OpenAI
5+
AZURE_OPENAI_DEPLOYMENT="<YOUR_AZURE_OPENAI_DEPLOYMENT_NAME>"
6+
7+
# GitHub Personal Access Token (with repo permissions)
8+
GITHUB_TOKEN="<YOUR_GITHUB_PERSONAL_ACCESS_TOKEN>"
9+
10+
# GitHub repository in 'owner/repo' format
11+
GITHUB_REPOSITORY="<OWNER/REPO>"
12+
13+
# File path in the repo you want to review
14+
INPUT_FILE_PATH="<PATH/TO/INPUT_FILE>"
15+
16+
# (Optional) Name of the branch to review or submit changes to
17+
# Defaults to the default branch of the repository if not set
18+
BRANCH_NAME="<YOUR_TARGET_BRANCH_NAME>"
19+
20+
# (Optional) Additional reviewer instructions to guide the LLM
21+
USER_INSTRUCTIONS="<YOUR_OPTIONAL_REVIEW_INSTRUCTIONS>"
22+
23+
# (Optional) Whether to use LLM to review changes and submit comments, true/false
24+
# Defaults to true if not set
25+
ENABLE_REVIEW_CHANGES=true

tools/review_file/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# review_file.py
2+
3+
## Automated Documentation & Code Review
4+
5+
The `review_file.py` script uses Azure OpenAI and GitHub APIs to automatically review and improve documentation or code files, then creates a pull request with suggested changes. It also analyzes diffs and leaves section-level comments on PRs.
6+
7+
### Usage
8+
9+
1. **Set Required Environment Variables**
10+
you can copy `tools/.env.sample` to `tools/.env`
11+
Ensure the following environment variables are set in your [.env](../tools/.env) file under `/tools`:
12+
- `AZURE_OPENAI_ENDPOINT`
13+
- `AZURE_OPENAI_DEPLOYMENT`
14+
- `GITHUB_TOKEN`
15+
- `GITHUB_REPOSITORY`
16+
- `INPUT_FILE_PATH`
17+
- Optional:
18+
- `BRANCH_NAME` (default: default branch such as `main`)
19+
- `USER_INSTRUCTIONS`
20+
- `ENABLE_REVIEW_CHANGES` (default: `true`)
21+
22+
**💡 Tips for Setting Up `GITHUB_TOKEN`:**
23+
- Go to [https://github.com/settings/tokens](https://github.com/settings/tokens) and click **"Generate new token (Classic)"**.
24+
- Select the following scopes when generating the token:
25+
-`repo` – Full control of private repositories
26+
- If the repository belongs to an organization, make sure:
27+
- You are a **collaborator** or a **member with write access**.
28+
- The organization allows use of classic tokens.
29+
30+
2. **Install Dependencies**
31+
```bash
32+
pip3 install azure-identity python-dotenv PyGithub openai unidiff requests
33+
```
34+
35+
3. **Run the Script**
36+
```bash
37+
python3 tools/review_file.py
38+
```
39+
This will:
40+
- Review the file specified by `INPUT_FILE_PATH` using LLM.
41+
- Create a new branch and commit the revised file.
42+
- Open a pull request with the changes.
43+
- Optionally, analyze the diff and comment on changed sections.
44+
45+
### Notes
46+
47+
- The script is intended for documentation files (e.g., `README.md`) and code comments.
48+
- Ensure your Azure OpenAI and GitHub credentials are valid.
49+
- Comments on PRs are generated using LLM for clarity and rationale.

0 commit comments

Comments
 (0)