diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..0415576 --- /dev/null +++ b/README.MD @@ -0,0 +1,133 @@ +# pr_manager + +## 项目简介 +该项目基于 Django 构建,主要实现一个 webhook 服务器,用于处理来自 Git 服务器的 webhook 事件,并根据项目配置自动执行相应的指令,如代码审核(code review)、代码描述(describe)、代码改进等。项目所有配置均可通过 Django admin 后台动态管理,包括 AI 服务器、Git 服务器及各项指令的配置,为项目提供灵活的扩展能力。 + +## 功能特性 +- **Webhook 事件处理**:接收并解析 Git 服务器触发的 webhook 请求。 +- **自动化指令执行**:根据配置自动触发代码审核、描述及代码改进等操作。 +- **动态配置管理**:通过 Django admin 后台实时管理 AI 服务器、Git 服务器和项目配置。 +- **模块化设计**:核心 webhook 处理逻辑集中在 pr 应用的 views.py 中,便于扩展与维护。 +- **多服务集成**:支持与多种 Git 服务和 AI 服务对接,满足不同业务场景需求。 + +## 目录结构 +项目主要目录说明如下: +``` +pr_manager/ +├── manage.py +├── Pipfile +├── Pipfile.lock +├── docker-compose.yaml +├── Dockerfile +├── start.sh +├── README.MD +├── apps/ +│ ├── pr/ +│ │ ├── views.py # 处理 webhook 事件的视图类 +│ │ ├── urls.py +│ │ ├── models.py +│ │ └── admin.py +│ ├── public/ +│ │ ├── views.py +│ │ └── admin.py +│ └── utils/ +│ └── pr_agent/ +│ ├── cli.py +│ ├── config_loader.py +│ ├── agent/ +│ │ └── pr_agent.py +│ ├── algo/ # 涉及代码处理逻辑 +│ ├── git_providers/ # 各 Git 服务实现 +│ ├── servers/ # 不同服务器对应实现 +│ └── settings/ # 项目与指令配置 +├── pr_manager/ +│ ├── settings.py +│ ├── urls.py +│ ├── wsgi.py +│ └── asgi.py +└── templates/ +``` +(部分目录与文件略) + +## 快速开始 + +### 开发环境设置 +1. 确保已安装 Python 3.12 及以上版本。 +2. 使用 pipenv 或 virtualenv 创建虚拟环境。例如: + ``` + pipenv install + ``` +3. 运行数据库迁移: + ``` + python manage.py migrate + ``` +4. 创建超级管理员账号: + ``` + python manage.py createsuperuser + ``` + +### 启动项目 +启动 Django 开发服务器: +``` +python manage.py runserver +``` +启动后,通过浏览器访问 [http://127.0.0.1:8000/](http://127.0.0.1:8000/) 即可查看项目效果。 + +### 生产部署 +- 使用 Docker 部署,参照根目录中的 Dockerfile 与 docker-compose.yaml 文件。 +- 生产环境可通过 `.env` 文件配置相关环境变量。 +- 建议配置反向代理与 SSL 证书以保障安全性。 + +## Webhook 工作原理 +1. 当 Git 服务器进行代码推送时,会触发 webhook 请求。 +2. Django 中 pr 应用下的 views.py 接收到请求并解析事件数据。 +3. 根据动态配置,判断是否需要执行代码审核、代码描述或代码改进等指令。 +4. 执行结果会通过日志记录和 Django admin 后台进行展示。 + +## PR管理系统配置说明 + +![主页菜单](static/主页.png) + +所有配置均通过 Django admin 后台管理,主要包括: +- **AI 服务器**:配置 AI 服务接入信息。 + +![AI 服务器](static/AI配置.png) + +- **Git 服务器**:配置与各 Git 服务的连接及 webhook 信息。 + +![Git 服务器](static/Git服务配置.png) + +![项目配置](static/项目配置.png) + +- **指令设置**:配置在 webhook 触发时需要执行的各项指令(例如代码审核、描述与改进)。 + +配置更新后,系统会实时生效,无需重启服务。 + +## Gitlab配置示例 + +- **用户AccessToken**: 配置Gitlab用户的AccessToken,用于获取用户信息。 + +![用户AccessToken](static/gitlab_access.png) + +- **项目Secret**: 配置Gitlab项目的Secret,用于验证请求的合法性。 + +![项目Secret](static/项目Secret.png) + +- **Webhook配置**: 配置Gitlab项目的Webhook,用于处理Gitlab的推送事件。 + +![Webhook配置](static/Webhook配置.png) + + +## 默认账号及 Git 服务器支持 + +- 默认管理员账号:eapil +- 默认密码:Eapil!@345 + +当前支持的 Git 服务器包括: +- gitea +- gitlab +- github + +## 日志与调试 +- 日志记录采用 Django 内置日志系统,可根据 settings.py 进行配置。 +- 开发环境下开启 Debug 模式,以便在浏览器中查看详细错误信息。 diff --git a/static/AI配置.png b/static/AI配置.png new file mode 100644 index 0000000..dbc81bf Binary files /dev/null and b/static/AI配置.png differ diff --git a/static/Git服务配置.png b/static/Git服务配置.png new file mode 100644 index 0000000..b690a47 Binary files /dev/null and b/static/Git服务配置.png differ diff --git a/static/Webhook配置.png b/static/Webhook配置.png new file mode 100644 index 0000000..ef5f599 Binary files /dev/null and b/static/Webhook配置.png differ diff --git a/static/gitlab_access.png b/static/gitlab_access.png new file mode 100644 index 0000000..2dc4a95 Binary files /dev/null and b/static/gitlab_access.png differ diff --git a/static/主页.png b/static/主页.png new file mode 100644 index 0000000..5514c9f Binary files /dev/null and b/static/主页.png differ diff --git a/static/项目Secret.png b/static/项目Secret.png new file mode 100644 index 0000000..10835fc Binary files /dev/null and b/static/项目Secret.png differ diff --git a/static/项目配置.png b/static/项目配置.png new file mode 100644 index 0000000..51fdd7c Binary files /dev/null and b/static/项目配置.png differ