-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Git provider
Azure
System Info
deployment type: CLI with Azure DevOps Repo
Bug details
I ran into issues when trying to use pr-agent with an Azure DevOps repo that contains a space in its url e.g. https://dev.azure.com/orgname/Dev%20Project/_git/repo_name/pullrequest/1234
I installed pr-agent using uv and configured following these instructions and ran it using cli.run_command with DefaultAzureCredential.
When I ran cli.run_command(pr_url, command), I received this error:
RuntimeError: asyncio.run() cannot be called from a running event loop
However, when I bypassed the CLI and called the AzureDevopsProvider directly using the same settings and PR URL, a different error appeared:
AzureDevOpsClientRequestError: Operation returned a 404 status code
After some testing, I found this happens when the Azure DevOps project name contains a space. Using the azure-devops library manually, I created a client and tested the get_pull_request_by_id method and managed to get it working only when the project is passed with a space rather than the %20 i.e. 'Dev Project' rather than 'Dev%20Project'.
Workaround
As a workaround, I cloned the repo locally and updated the _parse_pr_url static method to remove the %20 in the project and repository names using the unquote function from urllib. After applying this change, I was able to connect successfully and run the review command against the pull request and post the result as a comment.
Additional note
Just as a side note, when looking at other issues I noticed that the issue #740 raised a similar issue, but the fix was applied to the server webhook file but doesn’t cover this case in the AzureDevopsProvider class.