From 73624148a53d52c14a9e782826cc8fcdae4799f7 Mon Sep 17 00:00:00 2001 From: Dan Anstis Date: Fri, 8 Mar 2024 04:39:57 +0000 Subject: [PATCH] Fix URL encoding in Azure DevOps webhook handler --- pr_agent/servers/azuredevops_server_webhook.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pr_agent/servers/azuredevops_server_webhook.py b/pr_agent/servers/azuredevops_server_webhook.py index a7ba8659..2b926886 100644 --- a/pr_agent/servers/azuredevops_server_webhook.py +++ b/pr_agent/servers/azuredevops_server_webhook.py @@ -6,6 +6,8 @@ import json import os import re import secrets +from urllib.parse import unquote + import uvicorn from fastapi import APIRouter, Depends, FastAPI, HTTPException from fastapi.security import HTTPBasic, HTTPBasicCredentials @@ -81,7 +83,7 @@ async def handle_webhook(background_tasks: BackgroundTasks, request: Request): actions = [] if data["eventType"] == "git.pullrequest.created": # API V1 (latest) - pr_url = data["resource"]["_links"]["web"]["href"].replace("_apis/git/repositories", "_git") + pr_url = unquote(data["resource"]["_links"]["web"]["href"].replace("_apis/git/repositories", "_git")) log_context["event"] = data["eventType"] log_context["api_url"] = pr_url await _perform_commands_azure("pr_commands", PRAgent(), pr_url, log_context) @@ -90,7 +92,7 @@ async def handle_webhook(background_tasks: BackgroundTasks, request: Request): if available_commands_rgx.match(data["resource"]["comment"]["content"]): if(data["resourceVersion"] == "2.0"): repo = data["resource"]["pullRequest"]["repository"]["webUrl"] - pr_url = f'{repo}/pullrequest/{data["resource"]["pullRequest"]["pullRequestId"]}' + pr_url = unquote(f'{repo}/pullrequest/{data["resource"]["pullRequest"]["pullRequestId"]}') actions = [data["resource"]["comment"]["content"]] else: # API V1 not supported as it does not contain the PR URL