From ffaf5d5271aa65462f65397ebcaecbc27b6e1303 Mon Sep 17 00:00:00 2001 From: Paolo Mainardi Date: Thu, 22 Aug 2024 15:43:43 +0200 Subject: [PATCH 1/4] feat: Handle the gitlab MR draft status closes #1160 --- pr_agent/servers/gitlab_webhook.py | 12 ++++++++++++ pr_agent/settings/configuration.toml | 1 + 2 files changed, 13 insertions(+) diff --git a/pr_agent/servers/gitlab_webhook.py b/pr_agent/servers/gitlab_webhook.py index 4a814e9f2..df8f9baf1 100644 --- a/pr_agent/servers/gitlab_webhook.py +++ b/pr_agent/servers/gitlab_webhook.py @@ -124,14 +124,26 @@ async def inner(data: dict): return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) log_context["sender"] = sender + should_skip_draft = get_settings().get("GITLAB.SKIP_DRAFT_MR", False) if data.get('object_kind') == 'merge_request' and data['object_attributes'].get('action') in ['open', 'reopen']: url = data['object_attributes'].get('url') + draft = data['object_attributes'].get('draft') get_logger().info(f"New merge request: {url}") + + if draft and should_skip_draft: + get_logger().info(f"Skipping draft MR: {url}") + 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: mr = data['merge_request'] url = mr.get('url') + draft = mr.get('draft') + if draft and should_skip_draft: + get_logger().info(f"Skipping draft MR: {url}") + return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) + get_logger().info(f"A comment has been added to a merge request: {url}") body = data.get('object_attributes', {}).get('note') if data.get('object_attributes', {}).get('type') == 'DiffNote' and '/ask' in body: # /ask_line diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index b128aca08..89d8dd11e 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -230,6 +230,7 @@ push_commands = [ "/describe", "/review --pr_reviewer.num_code_suggestions=0", ] +skip_draft_mr = false [bitbucket_app] pr_commands = [ From 61837c69a3224ab3658ad6f601e5d088cb00f1fc Mon Sep 17 00:00:00 2001 From: Paolo Mainardi Date: Thu, 22 Aug 2024 21:13:54 +0200 Subject: [PATCH 2/4] Update gitlab_webhook.py --- pr_agent/servers/gitlab_webhook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_agent/servers/gitlab_webhook.py b/pr_agent/servers/gitlab_webhook.py index df8f9baf1..5bed83f37 100644 --- a/pr_agent/servers/gitlab_webhook.py +++ b/pr_agent/servers/gitlab_webhook.py @@ -124,7 +124,7 @@ async def inner(data: dict): return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) log_context["sender"] = sender - should_skip_draft = get_settings().get("GITLAB.SKIP_DRAFT_MR", False) + should_skip_draft = get_settings().get("GITLAB.SKIP_DRAFT_MR", True) if data.get('object_kind') == 'merge_request' and data['object_attributes'].get('action') in ['open', 'reopen']: url = data['object_attributes'].get('url') draft = data['object_attributes'].get('draft') From 8793f8d9b02e69a5191ef62c2fdb528314dd651f Mon Sep 17 00:00:00 2001 From: Paolo Mainardi Date: Thu, 22 Aug 2024 21:14:49 +0200 Subject: [PATCH 3/4] Update gitlab_webhook.py --- pr_agent/servers/gitlab_webhook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_agent/servers/gitlab_webhook.py b/pr_agent/servers/gitlab_webhook.py index 5bed83f37..df8f9baf1 100644 --- a/pr_agent/servers/gitlab_webhook.py +++ b/pr_agent/servers/gitlab_webhook.py @@ -124,7 +124,7 @@ async def inner(data: dict): return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) log_context["sender"] = sender - should_skip_draft = get_settings().get("GITLAB.SKIP_DRAFT_MR", True) + should_skip_draft = get_settings().get("GITLAB.SKIP_DRAFT_MR", False) if data.get('object_kind') == 'merge_request' and data['object_attributes'].get('action') in ['open', 'reopen']: url = data['object_attributes'].get('url') draft = data['object_attributes'].get('draft') From 3778cc2745e50990f306fb6ef5721686b47db7b4 Mon Sep 17 00:00:00 2001 From: Paolo Mainardi Date: Thu, 22 Aug 2024 21:59:01 +0200 Subject: [PATCH 4/4] feat: skip draft by default --- pr_agent/servers/gitlab_webhook.py | 5 ++--- pr_agent/settings/configuration.toml | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pr_agent/servers/gitlab_webhook.py b/pr_agent/servers/gitlab_webhook.py index df8f9baf1..143e45e4e 100644 --- a/pr_agent/servers/gitlab_webhook.py +++ b/pr_agent/servers/gitlab_webhook.py @@ -124,13 +124,12 @@ async def inner(data: dict): return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) log_context["sender"] = sender - should_skip_draft = get_settings().get("GITLAB.SKIP_DRAFT_MR", False) if data.get('object_kind') == 'merge_request' and data['object_attributes'].get('action') in ['open', 'reopen']: url = data['object_attributes'].get('url') draft = data['object_attributes'].get('draft') get_logger().info(f"New merge request: {url}") - if draft and should_skip_draft: + if draft: get_logger().info(f"Skipping draft MR: {url}") return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) @@ -140,7 +139,7 @@ async def inner(data: dict): mr = data['merge_request'] url = mr.get('url') draft = mr.get('draft') - if draft and should_skip_draft: + if draft: get_logger().info(f"Skipping draft MR: {url}") return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 89d8dd11e..b128aca08 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -230,7 +230,6 @@ push_commands = [ "/describe", "/review --pr_reviewer.num_code_suggestions=0", ] -skip_draft_mr = false [bitbucket_app] pr_commands = [