Skip to content

gitlab mr 状态可配置 #52

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`: 钉钉机器人密钥
- `dingtalk_secret`: 钉钉机器人密钥
14 changes: 9 additions & 5 deletions gitlab_integration/gitlab_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
return False