forked from codedog-ai/codedog
-
Notifications
You must be signed in to change notification settings - Fork 0
Test 0329 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Test 0329 #3
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5cf2bb7
Add comprehensive test suite for codedog components
13fd240
Fix test cases to handle model validations and mocking
a13c8ed
Fix code style issues in test suite according to flake8 standards
c4c5a6a
yeah
dfbfb7e
Test commit for automatic review
04d7482
Test commit for automatic review
dd749a9
add lines of cod statistics and support r1
fd354c1
测试自动代码评审和邮件报告功能
4097ea3
修复自动代码评审功能并添加类型检查
34558b9
修复代码评审报告中评分提取问题,使其能够匹配带有 ** 标记的分数
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,127 +1,177 @@ | ||
| # 🐶 Codedog | ||
| # Codedog: AI-Powered Code Review Assistant | ||
|
|
||
| [](https://pypi.org/project/codedog/) | ||
| [](https://pypi.org/project/codedog/) | ||
| [](https://opensource.org/licenses/MIT) | ||
|
|
||
| Codedog leverages Large Language Models (LLMs) like GPT to automatically review your pull requests on platforms like GitHub and GitLab, providing summaries and potential suggestions. | ||
|
|
||
| ## Features | ||
|
|
||
| * **Pull Request Summarization**: Generates concise summaries of PR changes, including categorization (feature, fix, etc.) and identification of major files. | ||
| * **Code Change Summarization**: Summarizes individual file diffs. | ||
| * **Code Review Suggestions**: Provides feedback and suggestions on code changes (experimental). | ||
| * **Multi-language Support**: Includes templates for English and Chinese reports. | ||
| * **Platform Support**: Works with GitHub and GitLab. | ||
| * **Automated Code Review**: Uses LLMs to analyze code changes, provide feedback, and suggest improvements | ||
| * **Scoring System**: Evaluates code across multiple dimensions, including correctness, readability, and maintainability | ||
| * **Multiple LLM Support**: Works with OpenAI (including GPT-4o), Azure OpenAI, DeepSeek, and MindConnect R1 models (see [Models Guide](docs/models.md)) | ||
| * **Email Notifications**: Sends code review reports via email (see [Email Setup Guide](docs/email_setup.md)) | ||
| * **Commit-Triggered Reviews**: Automatically reviews code when commits are made (see [Commit Review Guide](docs/commit_review.md)) | ||
| * **Developer Evaluation**: Evaluates a developer's code over a specific time period | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| * **Python**: Version 3.10 or higher (as the project now requires `^3.10`). | ||
| * **Poetry**: A dependency management tool for Python. Installation instructions: [Poetry Docs](https://python-poetry.org/docs/#installation). | ||
| * **Git**: For interacting with repositories. | ||
| * **(Optional) Homebrew**: For easier installation of Python versions on macOS. | ||
| * **API Keys**: | ||
| * OpenAI API Key (or Azure OpenAI credentials). | ||
| * GitHub Personal Access Token (with `repo` scope) or GitLab Personal Access Token (with `api` scope). | ||
|
|
||
| ## Setup | ||
|
|
||
| 1. **Clone the Repository**: | ||
| ```bash | ||
| git clone https://github.com/codedog-ai/codedog.git # Or your fork | ||
| cd codedog | ||
| ``` | ||
|
|
||
| 2. **Configure Python Version (if needed)**: | ||
| The project requires Python `^3.10` (3.10 or higher, but less than 4.0). | ||
| * If your default Python doesn't meet this, install a compatible version (e.g., using Homebrew `brew install python@3.12`, pyenv, etc.). | ||
| * Tell Poetry to use the correct Python executable (replace path if necessary): | ||
| ```bash | ||
| poetry env use /opt/homebrew/bin/python3.12 # Example for Homebrew on Apple Silicon | ||
| # or | ||
| poetry env use /path/to/your/python3.10+ | ||
| ``` | ||
|
|
||
| 3. **Install Dependencies**: | ||
| Poetry will create a virtual environment and install all necessary packages defined in `pyproject.toml` and `poetry.lock`. | ||
| ```bash | ||
| poetry install --with test,dev # Include optional dev and test dependencies | ||
| ``` | ||
| *(Note: If you encounter issues connecting to package sources, ensure you have internet access. The configuration previously used a mirror but has been reverted to the default PyPI.)* | ||
|
|
||
| [](https://github.com/Arcadia822/codedog/actions/workflows/flake8.yml) | ||
| [](https://github.com/Arcadia822/codedog/actions/workflows/test.yml) | ||
| [](https://github.com/Arcadia822/codedog/actions/workflows/test.yml) | ||
| [](https://discord.gg/6adMQxSpJS) | ||
|
|
||
| Review your Github/Gitlab PR with ChatGPT | ||
|
|
||
| **Codedog is update to langchain v0.2** | ||
|
|
||
|
|
||
| ## What is codedog? | ||
|
|
||
| Codedog is a code review automation tool benefit the power of LLM (Large Language Model) to help developers | ||
| review code faster and more accurately. | ||
|
|
||
| Codedog is based on OpenAI API and Langchain. | ||
|
|
||
| ## Quickstart | ||
|
|
||
| ### Review your pull request via Github App | ||
|
|
||
| Install our github app [codedog-assistant](https://github.com/apps/codedog-assistant) | ||
|
|
||
| ### Start with your own code | ||
|
|
||
| As a example, we will use codedog to review a pull request on Github. | ||
|
|
||
| 0. Install codedog | ||
|
|
||
| ```bash | ||
| pip install codedog | ||
| ``` | ||
|
|
||
| codedog currently only supports python 3.10. | ||
|
|
||
| 1. Get a github pull request | ||
| ```python | ||
| from github import Github | ||
|
|
||
| github_token="YOUR GITHUB TOKEN" | ||
| repository = "codedog-ai/codedog" | ||
| pull_request_number = 2 | ||
|
|
||
| github = Github(github_token) | ||
| retriever = GithubRetriever(github, repository, pull_requeest_number) | ||
| ``` | ||
|
|
||
|
|
||
| 2. Summarize the pull request | ||
|
|
||
| Since `PRSummaryChain` uses langchain's output parser, we suggest to use GPT-4 to improve formatting accuracy. | ||
|
|
||
| ```python | ||
| from codedog.chains import PRSummaryChain | ||
|
|
||
| openai_api_key = "YOUR OPENAI API KEY WITH GPT4" | ||
|
|
||
| # PR Summary uses output parser | ||
| llm35 = ChatOpenAI(openai_api_key=openai_api_key, model="gpt-3.5-turbo") | ||
|
|
||
| llm4 = ChatOpenAI(openai_api_key=openai_api_key, model="gpt-4") | ||
|
|
||
| summary_chain = PRSummaryChain.from_llm(code_summary_llm=llm35, pr_summary_llm=llm4, verbose=True) | ||
|
|
||
| summary = summary_chain({"pull_request": retriever.pull_request}, include_run_info=True) | ||
| ## Configuration | ||
|
|
||
| print(summary) | ||
| Codedog uses environment variables for configuration. You can set these directly in your shell, or use a `.env` file (you might need to install `python-dotenv` separately in your environment: `poetry run pip install python-dotenv`). | ||
|
|
||
| **Required:** | ||
|
|
||
| * **Platform Token**: | ||
| * For GitHub: `GITHUB_TOKEN="your_github_personal_access_token"` | ||
| * For GitLab: `GITLAB_TOKEN="your_gitlab_personal_access_token"` | ||
| * For GitLab (if using a self-hosted instance): `GITLAB_URL="https://your.gitlab.instance.com"` | ||
|
|
||
| * **LLM Credentials**: | ||
| * **OpenAI**: `OPENAI_API_KEY="sk-your_openai_api_key"` | ||
| * **Azure OpenAI**: Set `AZURE_OPENAI="true"` (or any non-empty string) **and** provide: | ||
| * `AZURE_OPENAI_API_KEY="your_azure_api_key"` | ||
| * `AZURE_OPENAI_API_BASE="https://your_azure_endpoint.openai.azure.com/"` | ||
| * `AZURE_OPENAI_DEPLOYMENT_ID="your_gpt_35_turbo_deployment_name"` (Used for code summaries/reviews) | ||
| * `AZURE_OPENAI_GPT4_DEPLOYMENT_ID="your_gpt_4_deployment_name"` (Used for PR summary) | ||
| * *(Optional)* `AZURE_OPENAI_API_VERSION="YYYY-MM-DD"` (Defaults to a recent preview version if not set) | ||
| * **DeepSeek Models**: Set the following for DeepSeek models: | ||
| * `DEEPSEEK_API_KEY="your_deepseek_api_key"` | ||
| * *(Optional)* `DEEPSEEK_MODEL="deepseek-chat"` (Default model, options include: "deepseek-chat", "deepseek-coder", etc.) | ||
| * *(Optional)* `DEEPSEEK_API_BASE="https://api.deepseek.com"` (Default API endpoint) | ||
| * For **DeepSeek R1 model** specifically: | ||
| * Set `DEEPSEEK_MODEL="deepseek-r1"` | ||
| * *(Optional)* `DEEPSEEK_R1_API_BASE="https://your-r1-endpoint"` (If different from standard DeepSeek endpoint) | ||
|
|
||
| **Example `.env` file:** | ||
|
|
||
| ```dotenv | ||
| # Platform | ||
| GITHUB_TOKEN="ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | ||
|
|
||
| # LLM (OpenAI example) | ||
| OPENAI_API_KEY="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | ||
|
|
||
| # LLM (Azure OpenAI example) | ||
| # AZURE_OPENAI="true" | ||
| # AZURE_OPENAI_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | ||
| # AZURE_OPENAI_API_BASE="https://your-instance.openai.azure.com/" | ||
| # AZURE_OPENAI_DEPLOYMENT_ID="gpt-35-turbo-16k" | ||
| # AZURE_OPENAI_GPT4_DEPLOYMENT_ID="gpt-4-turbo" | ||
|
|
||
| # LLM (DeepSeek example) | ||
| # DEEPSEEK_API_KEY="your_deepseek_api_key" | ||
| # DEEPSEEK_MODEL="deepseek-chat" | ||
| # DEEPSEEK_API_BASE="https://api.deepseek.com" | ||
|
|
||
| # LLM (DeepSeek R1 example) | ||
| # DEEPSEEK_API_KEY="your_deepseek_api_key" | ||
| # DEEPSEEK_MODEL="deepseek-r1" | ||
| # DEEPSEEK_R1_API_BASE="https://your-r1-endpoint" | ||
|
|
||
| # LLM (MindConnect R1 example) | ||
| # MINDCONNECT_API_KEY="your_mindconnect_api_key" | ||
|
|
||
| # Model selection (optional) | ||
| CODE_SUMMARY_MODEL="gpt-3.5" | ||
| PR_SUMMARY_MODEL="gpt-4" | ||
| CODE_REVIEW_MODEL="deepseek" # Can use "deepseek" or "deepseek-r1" here | ||
|
|
||
| # Email notification (optional) | ||
| EMAIL_ENABLED="true" | ||
| NOTIFICATION_EMAILS="your_email@example.com,another_email@example.com" | ||
| SMTP_SERVER="smtp.gmail.com" | ||
| SMTP_PORT="587" | ||
| SMTP_USERNAME="your_email@gmail.com" | ||
| SMTP_PASSWORD="your_app_password" # For Gmail, you must use an App Password, see docs/email_setup.md | ||
| ``` | ||
|
|
||
| 3. Review each code file changes in the pull request | ||
| ## Running the Example (Quickstart) | ||
|
|
||
| ```python | ||
| review_chain = CodeReviewChain.from_llm(llm=llm35, verbose=True) | ||
| The `README.md` in the project root (and `codedog/__init__.py`) contains a quickstart Python script demonstrating the core workflow. | ||
|
|
||
| reviews = review_chain({"pull_request": retriever.pull_request}, include_run_info=True) | ||
| 1. **Save the Quickstart Code**: Copy the Python code from the quickstart section into a file, e.g., `run_codedog.py`. | ||
|
|
||
| print(reviews) | ||
| ``` | ||
| 2. **Update Placeholders**: Modify the script with: | ||
| * Your actual GitHub/GitLab token. | ||
| * Your OpenAI/Azure API key and relevant details. | ||
| * The target repository (e.g., `"codedog-ai/codedog"` or your fork/project). | ||
| * The target Pull Request / Merge Request number/iid. | ||
|
|
||
| 4. Format review result | ||
| 3. **Load Environment Variables**: If using a `.env` file, ensure it's loaded. You might need to add `from dotenv import load_dotenv; load_dotenv()` at the beginning of your script. | ||
|
|
||
| Format review result to a markdown report. | ||
| 4. **Run the Script**: Execute the script within the Poetry environment: | ||
| ```bash | ||
| poetry run python run_codedog.py | ||
| ``` | ||
|
|
||
| ```python | ||
| from codedog.actors.reporters.pull_request import PullRequestReporter | ||
| This will: | ||
| * Initialize the appropriate retriever (GitHub/GitLab). | ||
| * Fetch the PR/MR data. | ||
| * Use the configured LLMs to generate code summaries and a PR summary. | ||
| * Use the configured LLM to generate code review suggestions. | ||
| * Print a formatted Markdown report to the console. | ||
|
|
||
| reporter = PullRequestReporter( | ||
| pr_summary=summary["pr_summary"], | ||
| code_summaries=summary["code_summaries"], | ||
| pull_request=retriever.pull_request, | ||
| code_reviews=reviews["code_reviews"], | ||
| ) | ||
| ## Running Tests | ||
|
|
||
| md_report = reporter.report() | ||
| To ensure the package is working correctly after setup or changes: | ||
|
|
||
| print(md_report) | ||
| ```bash | ||
| poetry run pytest | ||
| ``` | ||
|
|
||
| ## Deployment | ||
|
|
||
| We have a simple server demo to deploy codedog as a service with fastapi and handle Github webhook. | ||
| Basicly you can also use it with workflow or Github Application. | ||
|
|
||
| see `examples/server.py` | ||
|
|
||
| Note that codedog don't have fastapi and unicorn as dependency, you need to install them manually. | ||
|
|
||
| ## Configuration | ||
| ## Development | ||
|
|
||
| Codedog currently load config from environment variables. | ||
| * **Code Style**: Uses `black` for formatting and `flake8` for linting. | ||
| ```bash | ||
| poetry run black . | ||
| poetry run flake8 . | ||
| ``` | ||
| * **Dependencies**: Managed via `poetry`. Use `poetry add <package>` to add new dependencies. | ||
|
|
||
| settings: | ||
| ## Contributing | ||
|
|
||
| | Config Name | Required | Default | Description | | ||
| | ------------------------------ | -------- | ----------------- | --------------------------------------- | | ||
| | OPENAI_API_KEY | No | | Api Key for calling openai gpt api | | ||
| | AZURE_OPENAI | No | | Use azure openai if not blank | | ||
| | AZURE_OPENAI_API_KEY | No | | Azure openai api key | | ||
| | AZURE_OPENAI_API_BASE | No | | Azure openai api base | | ||
| | AZURE_OPENAI_DEPLOYMENT_ID | No | | Azure openai deployment id for gpt 3.5 | | ||
| | AZURE_OPENAI_GPT4_DEPLOYMENT_ID| No | | Azure openai deployment id for gpt 4 | | ||
| Contributions are welcome! Please refer to the project's contribution guidelines (if available) or open an issue/PR on the repository. | ||
|
|
||
| # How to release | ||
| ## License | ||
|
|
||
|  | ||
| This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # CodeDog项目更新说明 | ||
|
|
||
| ## 更新内容 | ||
|
|
||
| ### 1. 改进评分系统 | ||
|
|
||
| 我们对代码评估系统进行了以下改进: | ||
|
|
||
| - **评分系统升级**:从5分制升级到更详细的10分制评分系统 | ||
| - **评分维度更新**:使用更全面的评估维度 | ||
| - 可读性 (Readability) | ||
| - 效率与性能 (Efficiency & Performance) | ||
| - 安全性 (Security) | ||
| - 结构与设计 (Structure & Design) | ||
| - 错误处理 (Error Handling) | ||
| - 文档与注释 (Documentation & Comments) | ||
| - 代码风格 (Code Style) | ||
| - **详细评分标准**:为每个评分范围(1-3分、4-6分、7-10分)提供了明确的标准 | ||
| - **报告格式优化**:改进了评分报告的格式,使其更加清晰明了 | ||
|
|
||
| ### 2. 修复DeepSeek API调用问题 | ||
|
|
||
| 修复了DeepSeek API调用问题,特别是"deepseek-reasoner不支持连续用户消息"的错误: | ||
| - 将原来的两个连续HumanMessage合并为一个消息 | ||
| - 确保消息格式符合DeepSeek API要求 | ||
|
|
||
| ### 3. 改进电子邮件通知系统 | ||
|
|
||
| - 增强了错误处理,提供更详细的故障排除信息 | ||
| - 添加了Gmail应用密码使用的详细说明 | ||
| - 更新了.env文件中的SMTP配置注释,使其更加明确 | ||
| - 新增了详细的电子邮件设置指南 (docs/email_setup.md) | ||
| - 开发了高级诊断工具 (test_email.py),帮助用户测试和排查邮件配置问题 | ||
| - 改进了Gmail SMTP认证错误的诊断信息,提供明确的步骤解决问题 | ||
|
|
||
| ## 运行项目 | ||
|
|
||
| ### 环境设置 | ||
|
|
||
| 1. 确保已正确配置.env文件,特别是: | ||
| - 平台令牌(GitHub或GitLab) | ||
| - LLM API密钥(OpenAI、DeepSeek等) | ||
| - SMTP服务器设置(如果启用邮件通知) | ||
|
|
||
| 2. 如果使用Gmail发送邮件通知,需要: | ||
| - 启用Google账户的两步验证 | ||
| - 生成应用专用密码(https://myaccount.google.com/apppasswords) | ||
| - 在.env文件中使用应用密码 | ||
|
|
||
| ### 运行命令 | ||
|
|
||
| 1. **评估开发者代码**: | ||
| ```bash | ||
| python run_codedog.py eval "开发者名称" --start-date YYYY-MM-DD --end-date YYYY-MM-DD | ||
| ``` | ||
|
|
||
| 2. **审查PR**: | ||
| ```bash | ||
| python run_codedog.py pr "仓库名称" PR编号 | ||
| ``` | ||
|
|
||
| 3. **设置Git钩子**: | ||
| ```bash | ||
| python run_codedog.py setup-hooks | ||
| ``` | ||
|
|
||
| ### 注意事项 | ||
|
|
||
| - 对于较大的代码差异,可能会遇到上下文长度限制。在这种情况下,考虑使用`gpt-4-32k`或其他有更大上下文窗口的模型。 | ||
| - DeepSeek模型有特定的消息格式要求,请确保按照上述修复进行使用。 | ||
|
|
||
| ## 进一步改进方向 | ||
|
|
||
| 1. 实现更好的文本分块和处理,以处理大型代码差异 | ||
| 2. 针对不同文件类型的更专业评分标准 | ||
| 3. 进一步改进报告呈现,添加可视化图表 | ||
| 4. 与CI/CD系统的更深入集成 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Fix markdown list indentation inconsistencies.
The unordered lists in the configuration section have inconsistent indentation, which affects the rendering of the markdown document. The static analysis identified this issue with multiple list items.
The list indentation should be consistent throughout the document. Consider standardizing to 2 spaces for main list items and 4 spaces for nested items.
🏁 Script executed:
Length of output: 2155
Fix Markdown List Indentation in README.md
The configuration section’s unordered lists are inconsistently indented, which may cause rendering issues. Please standardize the indentation so that main list items use 2 spaces after the asterisk and nested items use 4 spaces. For example, update the affected section as follows:
This consistent formatting will improve markdown rendering across different viewers.
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
65-65: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
66-66: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
67-67: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
70-70: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
71-71: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
72-72: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
73-73: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
74-74: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
75-75: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
76-76: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
77-77: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
78-78: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
79-79: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
80-80: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
81-81: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
82-82: Unordered list indentation
Expected: 6; Actual: 12
(MD007, ul-indent)
83-83: Unordered list indentation
Expected: 6; Actual: 12
(MD007, ul-indent)