From 0e3417b4ab7fe4a49cfe098dd5adf5f1012ce3c2 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 21 Feb 2024 08:55:59 +0200 Subject: [PATCH] webhook --- docs/CI_FEEDBACK.md | 2 +- pr_agent/servers/gitlab_webhook.py | 19 ++++++++++++++++++- pr_agent/settings/configuration.toml | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/CI_FEEDBACK.md b/docs/CI_FEEDBACK.md index 4658ee67..7e14df78 100644 --- a/docs/CI_FEEDBACK.md +++ b/docs/CI_FEEDBACK.md @@ -28,4 +28,4 @@ where `{repo_name}` is the name of the repository, `{run_number}` is the run num - `enable_auto_checks_feedback` - if set to true, the tool will automatically provide feedback when a check is failed. Default is true. - `excluded_checks_list` - a list of checks to exclude from the feedback, for example: ["check1", "check2"]. Default is an empty list. - `persistent_comment` - if set to true, the tool will overwrite a previous checks comment with the new feedback. Default is true. - +- `enable_help_text=true` - if set to true, the tool will provide a help message when a user comments "/checks" on a PR. Default is true. diff --git a/pr_agent/servers/gitlab_webhook.py b/pr_agent/servers/gitlab_webhook.py index 165cd0a3..6be3ae45 100644 --- a/pr_agent/servers/gitlab_webhook.py +++ b/pr_agent/servers/gitlab_webhook.py @@ -11,7 +11,9 @@ from starlette_context import context from starlette_context.middleware import RawContextMiddleware from pr_agent.agent.pr_agent import PRAgent +from pr_agent.algo.utils import update_settings_from_args from pr_agent.config_loader import get_settings, global_settings +from pr_agent.git_providers.utils import apply_repo_settings from pr_agent.log import LoggingFormat, get_logger, setup_logger from pr_agent.secret_providers import get_secret_provider @@ -28,6 +30,20 @@ def handle_request(background_tasks: BackgroundTasks, url: str, body: str, log_c with get_logger().contextualize(**log_context): background_tasks.add_task(PRAgent().handle_request, url, body) +async def _perform_commands_gitlab(commands_conf: str, agent: PRAgent, body: dict, api_url: str, log_context: dict): + apply_repo_settings(api_url) + commands = get_settings().get(f"azure_devops_server.{commands_conf}") + for command in commands: + split_command = command.split(" ") + command = split_command[0] + args = split_command[1:] + other_args = update_settings_from_args(args) + new_command = ' '.join([command] + other_args) + if body: + get_logger().info(body) + get_logger().info(f"Performing command: {new_command}") + with get_logger().contextualize(**log_context): + await agent.handle_request(api_url, new_command) @router.post("/webhook") async def gitlab_webhook(background_tasks: BackgroundTasks, request: Request): @@ -58,7 +74,8 @@ async def gitlab_webhook(background_tasks: BackgroundTasks, request: Request): if data.get('object_kind') == 'merge_request' and data['object_attributes'].get('action') in ['open', 'reopen']: get_logger().info(f"A merge request has been opened: {data['object_attributes'].get('title')}") url = data['object_attributes'].get('url') - handle_request(background_tasks, url, "/review", log_context) + await _perform_commands_gitlab("pr_commands", PRAgent(), {}, url, log_context) + # handle_request(background_tasks, url, "/review", log_context) elif data.get('object_kind') == 'note' and data['event_type'] == 'note': if 'merge_request' in data: mr = data['merge_request'] diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 61df5417..744213da 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -113,7 +113,7 @@ enable_help_text=true enable_auto_checks_feedback=true excluded_checks_list=["lint"] # list of checks to exclude, for example: ["check1", "check2"] persistent_comment=true - +enable_help_text=true [pr_config] # /config #