From d046c2a939fb8ac80f3e990d559a30fd5df47467 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 5 Jun 2024 11:25:10 +0300 Subject: [PATCH] gitlab push_commands will work --- pr_agent/servers/gitlab_webhook.py | 18 ++++++++++++------ pr_agent/settings/configuration.toml | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pr_agent/servers/gitlab_webhook.py b/pr_agent/servers/gitlab_webhook.py index 57e00f88..e81044b8 100644 --- a/pr_agent/servers/gitlab_webhook.py +++ b/pr_agent/servers/gitlab_webhook.py @@ -134,18 +134,24 @@ async def gitlab_webhook(background_tasks: BackgroundTasks, request: Request): await handle_request(url, body, log_context, sender_id) elif data.get('object_kind') == 'push' and data.get('event_name') == 'push': - commands_on_push = get_settings().get(f"gitlab.push_commands", {}) - handle_push_trigger = get_settings().get(f"gitlab.handle_push_trigger", False) - if not commands_on_push or not handle_push_trigger: - get_logger().info("Push event, but no push commands found or push trigger is disabled") - return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) try: project_id = data['project_id'] commit_sha = data['checkout_sha'] url = await get_mr_url_from_commit_sha(commit_sha, gitlab_token, project_id) if not url: get_logger().info(f"No MR found for commit: {commit_sha}") - return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) + return JSONResponse(status_code=status.HTTP_200_OK, + content=jsonable_encoder({"message": "success"})) + + # we need first to apply_repo_settings + apply_repo_settings(url) + commands_on_push = get_settings().get(f"gitlab.push_commands", {}) + handle_push_trigger = get_settings().get(f"gitlab.handle_push_trigger", False) + if not commands_on_push or not handle_push_trigger: + get_logger().info("Push event, but no push commands found or push trigger is disabled") + return JSONResponse(status_code=status.HTTP_200_OK, + content=jsonable_encoder({"message": "success"})) + get_logger().debug(f'A push event has been received: {url}') await _perform_commands_gitlab("push_commands", PRAgent(), url, log_context) except Exception as e: diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 86ab7a00..a3d6c6f9 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -180,7 +180,7 @@ pr_commands = [ "/improve", ] handle_push_trigger = false -commands = [ +push_commands = [ "/describe", "/review --pr_reviewer.num_code_suggestions=0", ]