|
| 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