Skip to content

Commit bfc8239

Browse files
authored
Bitbucket Server: Add push_commands support when PR is updated (#2090)
1 parent a2b5ae8 commit bfc8239

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

pr_agent/servers/bitbucket_server_webhook.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ async def handle_webhook(background_tasks: BackgroundTasks, request: Request):
154154

155155
commands_to_run = []
156156

157-
if data["eventKey"] == "pr:opened":
157+
if (data["eventKey"] == "pr:opened"
158+
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
158159
apply_repo_settings(pr_url)
159160
if not should_process_pr_logic(data):
160161
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):
163164
)
164165
if get_settings().config.disable_auto_feedback: # auto commands for PR, and auto feedback is disabled
165166
get_logger().info(f"Auto feedback is disabled, skipping auto commands for PR {pr_url}", **log_context)
166-
return
167+
return JSONResponse(
168+
status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "PR ignored due to auto feedback not enabled"})
169+
)
167170
get_settings().set("config.is_auto_command", True)
168-
commands_to_run.extend(_get_commands_list_from_settings('BITBUCKET_SERVER.PR_COMMANDS'))
171+
if data["eventKey"] == "pr:opened":
172+
commands_to_run.extend(_get_commands_list_from_settings('BITBUCKET_SERVER.PR_COMMANDS'))
173+
else: #Has to be: data["eventKey"] == "pr:from_ref_updated"
174+
if not get_settings().get("BITBUCKET_SERVER.HANDLE_PUSH_TRIGGER"):
175+
get_logger().info(f"Push trigger is disabled, skipping push commands for PR {pr_url}", **log_context)
176+
return JSONResponse(
177+
status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "PR ignored due to push trigger not enabled"})
178+
)
179+
180+
get_settings().set("config.is_new_pr", False)
181+
commands_to_run.extend(_get_commands_list_from_settings('BITBUCKET_SERVER.PUSH_COMMANDS'))
169182
elif data["eventKey"] == "pr:comment:added":
170183
commands_to_run.append(data["comment"]["text"])
171184
else:

0 commit comments

Comments
 (0)