Skip to content

Commit c2743c8

Browse files
author
xin.xu1
committed
optimize info
1 parent aaa9eee commit c2743c8

File tree

11 files changed

+55
-48
lines changed

11 files changed

+55
-48
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ app/mrmax.py
44
db/*
55
!db/.gitkeep
66
/venv/
7+
__pycache__/
8+
.DS_Store
79

810
/config/config_local.py
911

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@
175175
#### Docker 运行
176176

177177
```bash
178-
docker run -d -v ./config:/workspace/config -p 8080:80 --name codereview xuxin1/llmcodereview:latest
178+
git clone [email protected]:mimo-x/Code-Review-GPT-Gitlab.git
179+
cd Code-Review-GPT-Gitlab
180+
181+
docker run -d --network bridge --add-host=host.docker.internal:host-gateway -v ./config:/workspace/config -p 8080:80 --name codereview xuxin1/llmcodereview:latest
179182
```
180183

181184
#### 源代码运行 💻

config/config.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,24 @@
1010
"model": 'deepseek-chat',
1111
"provider": "deepseek",
1212
}
13-
# # GPT API 配置示例
14-
# # model list
15-
# model_gpt_35_turbo = "gpt-3.5-turbo"
16-
# model_gpt_4o = "gpt-4o"
17-
#
13+
14+
# demo-proxy-gpt
1815
# api_config = {
1916
# "api_key": "your openai key",
2017
# "api_base": "https://api.openai.com/v1",
21-
# "model": model_gpt_4o,
18+
# "model": "gpt_4o",
2219
# "provider": "openai",
2320
# }
2421

25-
# ollama 配置示例
22+
# demo-ollama
2623
# api_config = {
2724
# "api_base": "http://localhost:11434",
2825
# "model": "llama3.2",
2926
# "provider": "ollama",
3027
# }
3128

3229
# Prompt
33-
gpt_message = """
30+
GPT_MESSAGE = """
3431
你是一位资深编程专家,gitlab的分支代码变更将以git diff 字符串的形式提供,请你帮忙review本段代码。然后你review内容的返回内容必须严格遵守下面的格式,包括标题内容。模板中的变量内容解释:
3532
变量5为: 代码中的优点。变量1:给review打分,分数区间为0~100分。变量2:code review发现的问题点。变量3:具体的修改建议。变量4:是你给出的修改后的代码。
3633
必须要求:1. 以精炼的语言、严厉的语气指出存在的问题。2. 你的反馈内容必须使用严谨的markdown格式 3. 不要携带变量内容解释信息。4. 有清晰的标题结构。有清晰的标题结构。有清晰的标题结构。
@@ -57,16 +54,24 @@
5754

5855
# ------------------Gitlab info--------------------------
5956
# Gitlab url
60-
gitlab_server_url = "https://gitlab.com"
57+
GITLAB_SERVER_URL = "https://gitlab.com"
6158

6259
# Gitlab private token
63-
gitlab_private_token = "gitlab private token"
60+
GITLAB_PRIVATE_TOKEN = "gitlab private token"
6461

6562
# Gitlab modifies the maximum number of files
66-
maximum_files = 50
63+
MAX_FILES = 50
6764

6865

6966
# ------------- Message notification --------------------
7067
# dingding notification (un necessary)
71-
dingding_bot_webhook = "https://oapi.dingtalk.com/robot/send?access_token=*****************************************"
72-
dingding_secret = "S********************************950f"
68+
DINGDING_BOT_WEBHOOK = "https://oapi.dingtalk.com/robot/send?access_token=*****************************************"
69+
DINGDING_SECRET = "S********************************950f"
70+
71+
72+
# ------------- code review settings --------------------
73+
# expect file types
74+
EXCLUDE_FILE_TYPES = ['.py', '.java', '.class', '.vue', ".go",".c",".cpp"]
75+
76+
# ignore file types
77+
IGNORE_FILE_TYPES = ["mod.go"]

doc/config.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ api_config = {
7575

7676

7777
## Gitlab配置
78-
- `gitlab_server_url`: Gitlab服务器地址
79-
- `gitlab_private_token`: Gitlab私有令牌
78+
- `GITLAB_SERVER_URL`: Gitlab服务器地址
79+
- `GITLAB_PRIVATE_TOKEN`: Gitlab私有令牌
8080
- `maximum_files`: Gitlab Merge Request最大文件数
8181

8282
## 消息通知配置

doc/review.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ class CustomReviewHandle(ReviewHandle):
349349
content = filter_diff_content(change['diff'])
350350
messages = [
351351
{"role": "system",
352-
"content": gpt_message
352+
"content": GPT_MESSAGE
353353
},
354354
{"role": "user",
355355
"content": f"请review这部分代码变更{content}",

gitlab_integration/gitlab_fetcher.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ def get_changes(self, force=False):
2828
if self._changes_cache and not force:
2929
return self._changes_cache
3030
# URL for the GitLab API endpoint
31-
url = f"{gitlab_server_url}/api/v4/projects/{self.project_id}/merge_requests/{self.iid}/changes"
31+
url = f"{GITLAB_SERVER_URL}/api/v4/projects/{self.project_id}/merge_requests/{self.iid}/changes"
3232

3333
# Headers for the request
3434
headers = {
35-
"PRIVATE-TOKEN": gitlab_private_token
35+
"PRIVATE-TOKEN": GITLAB_PRIVATE_TOKEN
3636
}
3737

3838
# Make the GET request
@@ -58,11 +58,11 @@ def get_file_content(self, file_path, branch_name='main', force=False):
5858
if file_path in self._file_content_cache and not force:
5959
return self._file_content_cache[file_path]
6060
# URL for the GitLab API endpoint
61-
url = f"{gitlab_server_url}/api/v4/projects/{self.project_id}/repository/files/{file_path}/raw?ref={branch_name}"
61+
url = f"{GITLAB_SERVER_URL}/api/v4/projects/{self.project_id}/repository/files/{file_path}/raw?ref={branch_name}"
6262

6363
# Headers for the request
6464
headers = {
65-
"PRIVATE-TOKEN": gitlab_private_token
65+
"PRIVATE-TOKEN": GITLAB_PRIVATE_TOKEN
6666
}
6767

6868
# Make the GET request
@@ -84,11 +84,11 @@ def get_info(self, force=False):
8484
if self._info_cache and not force:
8585
return self._info_cache
8686
# URL for the GitLab API endpoint
87-
url = f"{gitlab_server_url}/api/v4/projects/{self.project_id}/merge_requests/{self.iid}"
87+
url = f"{GITLAB_SERVER_URL}/api/v4/projects/{self.project_id}/merge_requests/{self.iid}"
8888

8989
# Headers for the request
9090
headers = {
91-
"PRIVATE-TOKEN": gitlab_private_token
91+
"PRIVATE-TOKEN": GITLAB_PRIVATE_TOKEN
9292
}
9393

9494
# Make the GET request
@@ -115,11 +115,11 @@ def get_info(self):
115115
:return: Project information
116116
"""
117117
# URL for the GitLab API endpoint
118-
url = f"{gitlab_server_url}/api/v4/projects/{self.project_id}"
118+
url = f"{GITLAB_SERVER_URL}/api/v4/projects/{self.project_id}"
119119

120120
# Headers for the request
121121
headers = {
122-
"PRIVATE-TOKEN": gitlab_private_token
122+
"PRIVATE-TOKEN": GITLAB_PRIVATE_TOKEN
123123
}
124124

125125
# Make the GET request
@@ -195,7 +195,7 @@ def find_files_by_keyword(self, keyword, branch_name="main"):
195195
# 构建带有身份验证信息的 URL
196196
def _build_authenticated_url(self, repo_url):
197197
# 如果 URL 使用 https
198-
token = gitlab_private_token
198+
token = GITLAB_PRIVATE_TOKEN
199199
if repo_url.startswith("https://"):
200200
return f"https://oauth2:{token}@{repo_url[8:]}"
201201
# 如果 URL 使用 http

response_module/response_target/msg_response/dingtalk_response.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def send_dingtalk_message_by_sign(self, message_text):
3636
"""
3737
timestamp = str(round(time.time() * 1000))
3838
sign = self.__get_sign(timestamp)
39-
webhookurl = f"{dingding_bot_webhook}&timestamp={timestamp}&sign={sign}"
39+
webhookurl = f"{DINGDING_BOT_WEBHOOK}&timestamp={timestamp}&sign={sign}"
4040
# 构建请求头
4141
headers = {
4242
"Content-Type": "application/json",
@@ -75,7 +75,7 @@ def send_dingtalk_message_by_key_word(self, project_url):
7575
7676
"""
7777
# 设置钉钉机器人的 Webhook URL
78-
webhook_url = dingding_bot_webhook
78+
webhook_url = DINGDING_BOT_WEBHOOK
7979

8080
# 要发送的消息内容
8181
message = f"新工程接入\nurl:{project_url}"
@@ -97,7 +97,7 @@ def __get_sign(self, timestamp):
9797
:return: 签名
9898
'''
9999

100-
secret = dingding_secret
100+
secret = DINGDING_SECRET
101101
secret_enc = secret.encode('utf-8')
102102
string_to_sign = '{}\n{}'.format(timestamp, secret)
103103
string_to_sign_enc = string_to_sign.encode('utf-8')

response_module/response_target/msg_response/gitlab_response.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ def send(self, message):
2222
@retry(stop_max_attempt_number=3, wait_fixed=2000)
2323
def send_merge(self, message):
2424
headers = {
25-
"Private-Token": gitlab_private_token,
25+
"Private-Token": GITLAB_PRIVATE_TOKEN,
2626
"Content-Type": "application/json"
2727
}
2828
project_id = self.project_id
2929
merge_request_id = self.merge_request_id
30-
url = f"{gitlab_server_url}/api/v4/projects/{project_id}/merge_requests/{merge_request_id}/notes"
30+
url = f"{GITLAB_SERVER_URL}/api/v4/projects/{project_id}/merge_requests/{merge_request_id}/notes"
3131
data = {
3232
"body": message
3333
}

review_engine/handler/default_handler.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import threading
33

44
from retrying import retry
5-
6-
from config.config import gpt_message
5+
from config.config import GPT_MESSAGE, EXCLUDE_FILE_TYPES, IGNORE_FILE_TYPES, MAX_FILES
76
from review_engine.abstract_handler import ReviewHandle
87
from utils.gitlab_parser import filter_diff_content
98
from utils.logger import log
@@ -22,8 +21,8 @@ def process_change(change):
2221

2322
futures = []
2423
for change in changes:
25-
if any(change["new_path"].endswith(ext) for ext in ['.py', '.java', '.class', '.vue', ".go"]) and not any(
26-
change["new_path"].endswith(ext) for ext in ["mod.go"]):
24+
if any(change["new_path"].endswith(ext) for ext in EXCLUDE_FILE_TYPES) and not any(
25+
change["new_path"].endswith(ext) for ext in IGNORE_FILE_TYPES):
2726
futures.append(executor.submit(process_change, change))
2827
else:
2928
log.info(f"{change['new_path']} 非目标检测文件!")
@@ -38,7 +37,7 @@ def generate_review_note(change, model):
3837
content = filter_diff_content(change['diff'])
3938
messages = [
4039
{"role": "system",
41-
"content": gpt_message
40+
"content": GPT_MESSAGE
4241
},
4342
{"role": "user",
4443
"content": f"请review这部分代码变更{content}",
@@ -66,8 +65,7 @@ def merge_handle(self, gitlabMergeRequestFetcher, gitlabRepoManager, hook_info,
6665
self.default_handle(changes, merge_info, hook_info, reply, model)
6766

6867
def default_handle(self, changes, merge_info, hook_info, reply, model):
69-
maximum_files = 50
70-
if changes and len(changes) <= maximum_files:
68+
if changes and len(changes) <= MAX_FILES:
7169
# Code Review 信息
7270
review_info = chat_review(changes, generate_review_note, model)
7371
if review_info:
@@ -110,7 +108,7 @@ def default_handle(self, changes, merge_info, hook_info, reply, model):
110108
})
111109

112110

113-
elif changes and len(changes) > maximum_files:
111+
elif changes and len(changes) > MAX_FILES:
114112
reply.add_reply({
115113
'title': '__MAIN_REVIEW__',
116114
'content': (

utils/args_check.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ def check_config():
99
results = []
1010
try:
1111
import config.config as config
12-
if check_exist(config, ["llm_api_impl", "api_config", "gpt_message",
13-
"gitlab_server_url", "gitlab_private_token", "dingding_bot_webhook", "dingding_secret"]):
12+
if check_exist(config, ["llm_api_impl", "api_config", "GPT_MESSAGE",
13+
"GITLAB_SERVER_URL", "GITLAB_PRIVATE_TOKEN", "DINGDING_BOT_WEBHOOK", "DINGDING_SECRET"]):
1414
results.append(["Configuration parameter existence", "Passed", "", "✅ Required parameters are available."])
1515
else:
1616
results.append(["Configuration parameter existence", "Failed", "Required parameters are missing", "❌ Required parameters are missing"])
@@ -75,14 +75,14 @@ def check_gitlab_config(config):
7575
"""
7676
result = {'passed': True, 'errors': []}
7777
try:
78-
response = requests.get(config.gitlab_server_url)
78+
response = requests.get(config.GITLAB_SERVER_URL)
7979
if response.status_code != 200:
80-
error_msg = f"Gitlab server URL {config.gitlab_server_url} is not available"
80+
error_msg = f"Gitlab server URL {config.GITLAB_SERVER_URL} is not available"
8181
result['errors'].append(error_msg)
8282
result['passed'] = False
8383

84-
response = requests.get(f"{config.gitlab_server_url}/api/v4/projects",
85-
headers={"PRIVATE-TOKEN": config.gitlab_private_token})
84+
response = requests.get(f"{config.GITLAB_SERVER_URL}/api/v4/projects",
85+
headers={"PRIVATE-TOKEN": config.GITLAB_PRIVATE_TOKEN})
8686
if response.status_code != 200:
8787
error_msg = "Gitlab private token is invalid"
8888
result['errors'].append(error_msg)

0 commit comments

Comments
 (0)