From 2716b22074e39c3d32483bb21c5b5ac7e7d951f7 Mon Sep 17 00:00:00 2001 From: licl Date: Sat, 19 Jul 2025 15:09:15 +0800 Subject: [PATCH] feat: gitlab mr status config --- config/config.py | 19 +++++++++++++++++++ doc/config.md | 3 ++- gitlab_integration/gitlab_fetcher.py | 14 +++++++++----- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/config/config.py b/config/config.py index bccf413..ad40b85 100644 --- a/config/config.py +++ b/config/config.py @@ -73,6 +73,25 @@ # Gitlab modifies the maximum number of files MAX_FILES = 50 +# Gitlab merger request status +# Different versions of GitLab have different attributes +# Refer to this issue,https://github.com/mimo-x/Code-Review-GPT-Gitlab/issues/26 +GITLAB_MERGE_REQUEST_STATUS = [ + { + "state": "opened", + "merge_status": "preparing" + }, + { + "state": "opened", + "merge_status": "unchecked" + }, + # 这个好像是合并后触发的状态,合并后还需要review吗? + # { + # "state": "merged", + # "merge_status": "can_be_merged" + # } +] + # ------------- Message notification -------------------- # dingding notification (un necessary) diff --git a/doc/config.md b/doc/config.md index 2d59741..90012d7 100644 --- a/doc/config.md +++ b/doc/config.md @@ -78,7 +78,8 @@ api_config = { - `GITLAB_SERVER_URL`: Gitlab服务器地址 - `GITLAB_PRIVATE_TOKEN`: Gitlab私有令牌 - `maximum_files`: Gitlab Merge Request最大文件数 +- `GITLAB_MERGE_REQUEST_STATUS`: Gitlab Merge Request状态,见[issue](https://github.com/mimo-x/Code-Review-GPT-Gitlab/issues/26) ## 消息通知配置 - `dingtalk_webhook`: 钉钉机器人Webhook -- `dingtalk_secret`: 钉钉机器人密钥 \ No newline at end of file +- `dingtalk_secret`: 钉钉机器人密钥 diff --git a/gitlab_integration/gitlab_fetcher.py b/gitlab_integration/gitlab_fetcher.py index d57c2e9..6d2a4e3 100644 --- a/gitlab_integration/gitlab_fetcher.py +++ b/gitlab_integration/gitlab_fetcher.py @@ -9,7 +9,7 @@ from config.config import * from utils.logger import log from utils.tools import run_command - +from config.config import GITLAB_MERGE_REQUEST_STATUS class GitlabMergeRequestFetcher: def __init__(self, project_id, merge_request_iid): @@ -210,9 +210,13 @@ def is_merge_request_opened(gitlab_payload) -> bool: 判断是否是merge request打开事件 """ try: - gitlab_merge_request_old = gitlab_payload.get("object_attributes").get("state") == "opened" and gitlab_payload.get("object_attributes").get("merge_status") == "preparing" - gitlab_merge_request_new = gitlab_payload.get("object_attributes").get("state") == "merged" and gitlab_payload.get("object_attributes").get("merge_status") == "can_be_merged" - return gitlab_merge_request_old or gitlab_merge_request_new + state = gitlab_payload.get("object_attributes").get("state") + merge_status = gitlab_payload.get("object_attributes").get("merge_status") + + for status_config in GITLAB_MERGE_REQUEST_STATUS: + if state == status_config["state"] and merge_status == status_config["merge_status"]: + return True + return False except Exception as e: log.error(f"判断是否是merge request打开事件失败: {e}") - return False \ No newline at end of file + return False