diff --git a/pr_agent/servers/gitlab_webhook.py b/pr_agent/servers/gitlab_webhook.py index 4556e8ac2..502e7aed5 100644 --- a/pr_agent/servers/gitlab_webhook.py +++ b/pr_agent/servers/gitlab_webhook.py @@ -168,9 +168,11 @@ async def inner(data: dict): sender = data.get("user", {}).get("username", "unknown") sender_id = data.get("user", {}).get("id", "unknown") + # ignore bot users if is_bot_user(data): return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) if data.get('event_type') != 'note': # not a comment + # ignore MRs based on title, labels, source and target branches if not should_process_pr_logic(data, data['object_attributes'].get('title')): return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) @@ -180,40 +182,10 @@ async def inner(data: dict): url = data['object_attributes'].get('url') draft = data['object_attributes'].get('draft') get_logger().info(f"New merge request: {url}") - if draft: get_logger().info(f"Skipping draft MR: {url}") return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) - # logic to ignore MRs for titles, labels and source, target branches. - ignore_mr_title = get_settings().get("CONFIG.IGNORE_PR_TITLE", []) - ignore_mr_labels = get_settings().get("CONFIG.IGNORE_PR_LABELS", []) - ignore_mr_source_branches = get_settings().get("CONFIG.IGNORE_PR_SOURCE_BRANCHES", []) - ignore_mr_target_branches = get_settings().get("CONFIG.IGNORE_PR_TARGET_BRANCHES", []) - if ignore_mr_source_branches: - source_branch = data['object_attributes'].get('source_branch') - if any(re.search(regex, source_branch) for regex in ignore_mr_source_branches): - get_logger().info(f"Ignoring MR with source branch '{source_branch}' due to gitlab.ignore_mr_source_branches settings") - return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) - - if ignore_mr_target_branches: - target_branch = data['object_attributes'].get('target_branch') - if any(re.search(regex, target_branch) for regex in ignore_mr_target_branches): - get_logger().info(f"Ignoring MR with target branch '{target_branch}' due to gitlab.ignore_mr_target_branches settings") - return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) - - if ignore_mr_labels: - labels = [label['title'] for label in data['object_attributes'].get('labels', [])] - if any(label in ignore_mr_labels for label in labels): - labels_str = ", ".join(labels) - get_logger().info(f"Ignoring MR with labels '{labels_str}' due to gitlab.ignore_mr_labels settings") - return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) - - if ignore_mr_title: - if any(re.search(regex, title) for regex in ignore_mr_title): - get_logger().info(f"Ignoring MR with title '{title}' due to gitlab.ignore_mr_title settings") - return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) - await _perform_commands_gitlab("pr_commands", PRAgent(), url, log_context) elif data.get('object_kind') == 'note' and data.get('event_type') == 'note': # comment on MR if 'merge_request' in data: