Skip to content

Commit eab2396

Browse files
authored
Merge pull request #11 from Robbings/dev
BREAKING CHANGE: 架构全新升级,并支持自定义代码审查器及消息通知器
2 parents e3ea99e + dabc320 commit eab2396

37 files changed

+1362
-626
lines changed

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,39 @@
2323

2424
> 一个利用大模型帮助我们在 Gitlab 上进行 Code Review 提升研发效能的项目 💪🏻 (( 包括但不限于 GPT 🎁))
2525
26-
2726
**这个项目有什么特点? ✨**
2827

2928
🐶 针对于 <span style="background-image: linear-gradient(to right, #ff9900, #ff66cc);-webkit-background-clip: text;color: transparent;font-weight: bold;">Gitlab 定制</span>
3029

3130
🐱 结合了<span style="background-image: linear-gradient(to right, #ff9900, #ff66cc);-webkit-background-clip: text;color: transparent;font-weight: bold;">GPT</span>的能力 🚀
3231

33-
🦊 正在尝试接入私有化 LLM <span style="background-image: linear-gradient(to right, #ff9900, #ff66cc);-webkit-background-clip: text;color: transparent;font-weight: bold;">代码安全问题</span>
32+
🦊 能够接入私有化 LLM <span style="background-image: linear-gradient(to right, #ff9900, #ff66cc);-webkit-background-clip: text;color: transparent;font-weight: bold;">代码安全问题</span>
3433

3534
🦁 我们将一直关注效能研发 <span style="background-image: linear-gradient(to right, #ff9900, #ff66cc);-webkit-background-clip: text;color: transparent;font-weight: bold;">最新的Coder Review动态</span> 融入这个项目
3635

3736

3837
# [项目架构 🚗](https://vze9i86ezn.feishu.cn/docx/BuFidAogAoH1ecxQstscBUdhnfb?openbrd=1&doc_app_id=501&blockId=YneudO6sRoXPFIxkohtcgbwenye&blockType=whiteboard&blockToken=Yd3CwIPdphgGmFbWcRfcx9aNnrf#YneudO6sRoXPFIxkohtcgbwenye)
3938

39+
### 🚀 **全新架构升级:更强大、更灵活、更高效!** 🌈
40+
4041
<p align="center">
4142
<img src="doc/img/project_framework.png" style="width:500px;"/>
4243
</p>
4344

45+
🌟 **丰富的模型接入** 支持轻松接入<span style="background-image: linear-gradient(to right, #ff9900, #ff66cc);-webkit-background-clip: text;color: transparent;font-weight: bold;">更多的模型</span> ,无论是经典模型还是最新的AI模型,都能轻松集成!
46+
47+
🔧 **高度定制化** 开发者可以<span style="background-image: linear-gradient(to right, #ff9900, #ff66cc);-webkit-background-clip: text;color: transparent;font-weight: bold;">便捷地自定义处理逻辑和回复机制</span>,打造专属于你的解决方案!
48+
49+
🔗 **扩展性强** 模块化设计使得功能扩展更加方便,未来可以<span style="background-image: linear-gradient(to right, #ff9900, #ff66cc);-webkit-background-clip: text;color: transparent;font-weight: bold;">轻松添加新功能</span>,满足不断变化的需求!
50+
51+
🛠️ **高可维护性** 代码结构清晰,注释详细,便于维护和二次开发,减少开发者的负担!
52+
53+
**快来体验我们的新架构吧,享受前所未有的强大功能和极致体验!**
54+
55+
56+
57+
58+
4459

4560
# 功能预览 🌈
4661

@@ -133,7 +148,10 @@
133148
<td></td>
134149
</tr>
135150
</table>
151+
### 4. 自定义更多的通知方式和处理手段
136152

153+
1. 可通过实现自定义``Reply``类添加如邮箱,私有机器人等多种通知方式,具体教程参见[reply.md](doc/reply.md)
154+
2. 可通过自定义更多的``Review Handle``引入自定义的代码审查逻辑,具体教程参见[review.md](doc/review.md)
137155

138156

139157

@@ -168,7 +186,7 @@ python3 app.py
168186

169187

170188

171-
189+
172190
#### Docker
173191

174192
```bash
@@ -180,14 +198,14 @@ todo dockerfile
180198

181199
- ✅ 使用 GPT 进行Code Review
182200
- ✅ 实现多模型支持
183-
- [ ] 尝试接入私有化大模型解决代码安全问题
184201
- [ ] 可以配置更多的触发方式
185202
- ✅ Merge Request
186203
- [ ] commit
187204
- [ ] tag
188205
- [ ] 兼容飞书的消息通知
189206
- [ ] 兼容钉钉的消息通知
190207
- [ ] 结合静态代码分析来提供修改代码的风险等级
208+
- [ ] 通过pydantic实现大模型输出内容的格式化
191209

192210
# 交流 👨‍👨‍👦‍👦
193211
👏🏻 很高兴你能向我们提出一些问题和修改建议(issue,pr), 欢迎 star 项目 ⭐️
@@ -198,11 +216,12 @@ todo dockerfile
198216

199217
👨‍👨‍👦‍👦 如果有任何使用问题,欢迎来这里交流 👋🏻
200218
<p float="left">
201-
<img src="doc/img/wechat.png" width="400" />
219+
<img src="doc/img/wechat.jpg" width="400" />
202220
<img src="doc/img/xuxin.png" width="400" />
203221
</p>
204222

205223

224+
206225
# 参考文献 📚
207226
- [(字节)基于大模型 + 知识库的 Code Review 实践](https://mp.weixin.qq.com/s?__biz=Mzg2ODQ1OTExOA==&mid=2247504479&idx=1&sn=1ec09afbb5b5b9b2aaf151994be5fd27&chksm=cea9655ef9deec48b17cbab05ddd1ab04c86736d8b469eaac6f5a707ca110ce4186e8985ff41&mpshare=1&scene=1&srcid=1011C8l5RmCM2EL4Rpl3wdRy&sharer_shareinfo=96d0a83631aaa25db87709baa250085d&sharer_shareinfo_first=96d0a83631aaa25db87709baa250085d#rd)
208227
- [(美团)代码变更风险可视化系统建设与实践](https://tech.meituan.com/2023/09/22/construction-and-practice-of-code-change-risk-visualization-system.html)

app/gitlab_utils.py

Lines changed: 0 additions & 144 deletions
This file was deleted.

app/gitlab_webhook.py

Lines changed: 3 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,8 @@
1-
import json
2-
import threading
3-
from os import abort
41
from flask import Blueprint, request, jsonify
5-
# from config.config import WEBHOOK_VERIFY_TOKEN
6-
from service.chat_review import review_code, review_code_for_mr, review_code_for_add_commit
7-
from utils.logger import log
8-
from app.gitlab_utils import get_commit_list, get_merge_request_id, get_commit_change_file
9-
from utils.dingding import send_dingtalk_message_by_sign
2+
from gitlab_integration.webhook_listener import webhook_listener
103

114
git = Blueprint('git', __name__)
125

13-
14-
@git.route('/api')
15-
def question():
16-
return 'hello world'
17-
18-
19-
@git.route('/webhook', methods=['GET', 'POST'])
6+
@git.route('/webhook', methods=['POST'])
207
def webhook():
21-
if request.method == 'GET':
22-
# 获取gitlab的webhook的token
23-
webhook_token = request.headers.get('X-Gitlab-Token')
24-
25-
# gitlab的webhook的token验证
26-
# if webhook_token == WEBHOOK_VERIFY_TOKEN:
27-
return jsonify({'status': 'success'}), 200
28-
#else:
29-
# return jsonify({'status': 'bad token'}), 401
30-
31-
elif request.method == 'POST':
32-
"""
33-
webhook的主要逻辑,获取gitlab的推送信息
34-
"""
35-
# 获取gitlab的推送信息
36-
gitlab_payload = request.data.decode('utf-8')
37-
# 将gitlab的推送信息转换为字典
38-
gitlab_payload = json.loads(gitlab_payload)
39-
log.info(f"🌈 :{gitlab_payload}")
40-
# 获取项目的类型
41-
event_type = gitlab_payload.get('object_kind')
42-
43-
# 首次发起mr时候触发
44-
if event_type == 'merge_request' and gitlab_payload.get("object_attributes").get(
45-
"state") == "opened" and gitlab_payload.get("object_attributes").get("merge_status") == "preparing":
46-
# 验证通过,获取commit的信息
47-
log.info("首次merge_request ", gitlab_payload)
48-
# 获取项目id
49-
project_id = gitlab_payload.get('project')['id']
50-
# 获取merge request ID
51-
merge_request_id = gitlab_payload.get("object_attributes")["iid"]
52-
53-
thread = threading.Thread(target=review_code_for_mr, args=(project_id, merge_request_id, gitlab_payload))
54-
thread.start()
55-
56-
return jsonify({'status': 'success'}), 200
57-
elif event_type == 'push':
58-
# 获取merge request ID
59-
merge_request_id = get_merge_request_id(gitlab_payload.get('ref').split("/")[-1], gitlab_payload.get("project_id"))
60-
# 获取项目id
61-
project_id = gitlab_payload.get('project')['id']
62-
if not merge_request_id:
63-
send_dingtalk_message_by_sign(
64-
f"Project_Name:{gitlab_payload['project']['name']}\n备注:分支 {gitlab_payload.get('ref')} 没有处于open状态的 Merge Request 不进行 Code Review。")
65-
return jsonify({'status': f'非存在MR分支,{gitlab_payload}'}), 200
66-
67-
changed_files = get_commit_change_file(gitlab_payload)
68-
69-
thread = threading.Thread(target=review_code_for_add_commit,
70-
args=(project_id, merge_request_id, changed_files, gitlab_payload))
71-
thread.start()
72-
73-
return jsonify({'status': 'success'}), 200
74-
75-
else:
76-
log.error("不是merge")
77-
return jsonify({'status': '操作不为push'}), 200
78-
79-
return jsonify({'status': f'未匹配到规则,{gitlab_payload}'}), 200
80-
81-
else:
82-
abort(400)
8+
return webhook_listener.handle_webhook()

config/config.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
1-
# ------------------GPT info--------------------------
2-
# model list
3-
model_quester_anster = "text-davinci-003"
4-
model_gpt_35_turbo = "gpt-3.5-turbo"
5-
model_gpt_4o = "gpt-4o"
6-
model_programming_translate = "code-davinci-002"
7-
81
# api 接口封装类
9-
llm_api_impl = "llm_api.llm_api_default.LLMApiDefault"
2+
llm_api_impl = "large_model.api.default_api.DefaultApi"
103

11-
# api 配置方式参考 docs/llm_api.md
4+
# DeepSeek配置示例
5+
# api 配置方式参考 docs/config.md
126
# 默认使用认UnionLLM,参考:https://github.com/EvalsOne/UnionLLM/tree/main/docs
137
# UnionLLM兼容LiteLLM,参考LiteLLM文档:https://docs.litellm.ai/docs
148
api_config = {
15-
"api_key": "your openai key",
16-
"api_base": "https://api.openai.com/v1",
17-
"model": model_gpt_4o,
18-
"provider": "openai",
9+
"api_key": "your deepseek key",
10+
"model": 'deepseek-chat',
11+
"provider": "deepseek",
1912
}
13+
# # GPT API 配置示例
14+
# # model list
15+
# model_gpt_35_turbo = "gpt-3.5-turbo"
16+
# model_gpt_4o = "gpt-4o"
17+
#
18+
# api_config = {
19+
# "api_key": "your openai key",
20+
# "api_base": "https://api.openai.com/v1",
21+
# "model": model_gpt_4o,
22+
# "provider": "openai",
23+
# }
24+
25+
# ollama 配置示例
26+
# api_config = {
27+
# "api_base": "http://localhost:11434",
28+
# "model": "llama3.2",
29+
# "provider": "ollama",
30+
# }
2031

2132
# Prompt
2233
gpt_message = """
@@ -39,7 +50,7 @@
3950
#### 💻修改后的代码:
4051
```python
4152
{变量4}
42-
53+
```
4354
"""
4455

4556
# ------------------Gitlab info--------------------------
@@ -56,4 +67,4 @@
5667
# ------------- Message notification --------------------
5768
# dingding notification (un necessary)
5869
dingding_bot_webhook = "https://oapi.dingtalk.com/robot/send?access_token=*****************************************"
59-
dingding_secret = "S********************************950f"
70+
dingding_secret = "S********************************950f"

0 commit comments

Comments
 (0)