mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-04 04:40:38 +08:00
add support for auto events
This commit is contained in:
@ -47,17 +47,23 @@ async def handle_webhook(background_tasks: BackgroundTasks, request: Request):
|
|||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
content=json.dumps({"message": "unauthorized"}),
|
content=json.dumps({"message": "unauthorized"}),
|
||||||
)
|
)
|
||||||
|
actions = []
|
||||||
if data["eventType"] == "git.pullrequest.created":
|
if data["eventType"] == "git.pullrequest.created":
|
||||||
body = "review"
|
|
||||||
# API V1 (latest)
|
# API V1 (latest)
|
||||||
pr_url = data["resource"]["_links"]["web"]["href"].replace("_apis/git/repositories", "_git")
|
pr_url = data["resource"]["_links"]["web"]["href"].replace("_apis/git/repositories", "_git")
|
||||||
|
if get_settings().get("github_action_config").get("auto_review") == True:
|
||||||
|
actions.append("review")
|
||||||
|
if get_settings().get("github_action_config").get("auto_improve") == True:
|
||||||
|
actions.append("improve")
|
||||||
|
if get_settings().get("github_action_config").get("describe") == True:
|
||||||
|
actions.append("describe")
|
||||||
|
|
||||||
elif data["eventType"] == "ms.vss-code.git-pullrequest-comment-event":
|
elif data["eventType"] == "ms.vss-code.git-pullrequest-comment-event":
|
||||||
if available_commands_rgx.match(data["resource"]["comment"]["content"]):
|
if available_commands_rgx.match(data["resource"]["comment"]["content"]):
|
||||||
if(data["resourceVersion"] == "2.0"):
|
if(data["resourceVersion"] == "2.0"):
|
||||||
repo = data["resource"]["pullRequest"]["repository"]["webUrl"]
|
repo = data["resource"]["pullRequest"]["repository"]["webUrl"]
|
||||||
pr_url = f'{repo}/pullrequest/{data["resource"]["pullRequest"]["pullRequestId"]}'
|
pr_url = f'{repo}/pullrequest/{data["resource"]["pullRequest"]["pullRequestId"]}'
|
||||||
body = data["resource"]["comment"]["content"]
|
actions = [data["resource"]["comment"]["content"]]
|
||||||
else:
|
else:
|
||||||
# API V1 not supported as it does not contain the PR URL
|
# API V1 not supported as it does not contain the PR URL
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
@ -77,17 +83,18 @@ async def handle_webhook(background_tasks: BackgroundTasks, request: Request):
|
|||||||
log_context["event"] = data["eventType"]
|
log_context["event"] = data["eventType"]
|
||||||
log_context["api_url"] = pr_url
|
log_context["api_url"] = pr_url
|
||||||
|
|
||||||
try:
|
for action in actions:
|
||||||
handle_request(background_tasks, pr_url, body, log_context)
|
try:
|
||||||
return JSONResponse(
|
handle_request(background_tasks, pr_url, action, log_context)
|
||||||
status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})
|
except Exception as e:
|
||||||
)
|
get_logger().error("Azure DevOps Trigger failed. Error:" + str(e))
|
||||||
except Exception as e:
|
return JSONResponse(
|
||||||
get_logger().error("Azure DevOps Trigger failed. Error:" + str(e))
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
return JSONResponse(
|
content=json.dumps({"message": "Internal server error"}),
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
)
|
||||||
content=json.dumps({"message": "Internal server error"}),
|
return JSONResponse(
|
||||||
)
|
status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "webhook triggerd successfully"})
|
||||||
|
)
|
||||||
|
|
||||||
# currently only basic auth is supported with azure webhooks
|
# currently only basic auth is supported with azure webhooks
|
||||||
# for this reason, https must be enabled to ensure the credentials are not sent in clear text
|
# for this reason, https must be enabled to ensure the credentials are not sent in clear text
|
||||||
|
Reference in New Issue
Block a user