diff --git a/pr_agent/servers/bitbucket_server_webhook.py b/pr_agent/servers/bitbucket_server_webhook.py index a38644f0..e84cd04c 100644 --- a/pr_agent/servers/bitbucket_server_webhook.py +++ b/pr_agent/servers/bitbucket_server_webhook.py @@ -154,7 +154,8 @@ async def handle_webhook(background_tasks: BackgroundTasks, request: Request): commands_to_run = [] - if data["eventKey"] == "pr:opened": + if (data["eventKey"] == "pr:opened" + or (data["eventKey"] == "repo:refs_changed" and data.get("pullRequest", {}).get("id", -1) != -1)): # push event; -1 for push unassigned to a PR: #Check auto commands for creation/updating apply_repo_settings(pr_url) if not should_process_pr_logic(data): get_logger().info(f"PR ignored due to config settings", **log_context) @@ -163,9 +164,21 @@ async def handle_webhook(background_tasks: BackgroundTasks, request: Request): ) if get_settings().config.disable_auto_feedback: # auto commands for PR, and auto feedback is disabled get_logger().info(f"Auto feedback is disabled, skipping auto commands for PR {pr_url}", **log_context) - return + return JSONResponse( + status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "PR ignored due to auto feedback not enabled"}) + ) get_settings().set("config.is_auto_command", True) - commands_to_run.extend(_get_commands_list_from_settings('BITBUCKET_SERVER.PR_COMMANDS')) + if data["eventKey"] == "pr:opened": + commands_to_run.extend(_get_commands_list_from_settings('BITBUCKET_SERVER.PR_COMMANDS')) + else: #Has to be: data["eventKey"] == "pr:from_ref_updated" + if not get_settings().get("BITBUCKET_SERVER.HANDLE_PUSH_TRIGGER"): + get_logger().info(f"Push trigger is disabled, skipping push commands for PR {pr_url}", **log_context) + return JSONResponse( + status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "PR ignored due to push trigger not enabled"}) + ) + + get_settings().set("config.is_new_pr", False) + commands_to_run.extend(_get_commands_list_from_settings('BITBUCKET_SERVER.PUSH_COMMANDS')) elif data["eventKey"] == "pr:comment:added": commands_to_run.append(data["comment"]["text"]) else: