mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-02 03:40:38 +08:00
Merge pull request #1216 from Codium-ai/tr/azure_parsing
fix: improve Azure DevOps PR URL parsing and add unit tests
This commit is contained in:
@ -542,18 +542,20 @@ class AzureDevopsProvider(GitProvider):
|
|||||||
parsed_url = urlparse(pr_url)
|
parsed_url = urlparse(pr_url)
|
||||||
|
|
||||||
path_parts = parsed_url.path.strip("/").split("/")
|
path_parts = parsed_url.path.strip("/").split("/")
|
||||||
|
if "pullrequest" not in path_parts:
|
||||||
if len(path_parts) < 6 or path_parts[4] != "pullrequest":
|
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"The provided URL does not appear to be a Azure DevOps PR URL"
|
"The provided URL does not appear to be a Azure DevOps PR URL"
|
||||||
)
|
)
|
||||||
|
if len(path_parts) == 6: # "https://dev.azure.com/organization/project/_git/repo/pullrequest/1"
|
||||||
workspace_slug = path_parts[1]
|
workspace_slug = path_parts[1]
|
||||||
repo_slug = path_parts[3]
|
repo_slug = path_parts[3]
|
||||||
try:
|
|
||||||
pr_number = int(path_parts[5])
|
pr_number = int(path_parts[5])
|
||||||
except ValueError as e:
|
elif len(path_parts) == 5: # 'https://organization.visualstudio.com/project/_git/repo/pullrequest/1'
|
||||||
raise ValueError("Unable to convert PR number to integer") from e
|
workspace_slug = path_parts[0]
|
||||||
|
repo_slug = path_parts[2]
|
||||||
|
pr_number = int(path_parts[4])
|
||||||
|
else:
|
||||||
|
raise ValueError("The provided URL does not appear to be a Azure DevOps PR URL")
|
||||||
|
|
||||||
return workspace_slug, repo_slug, pr_number
|
return workspace_slug, repo_slug, pr_number
|
||||||
|
|
||||||
|
15
tests/unittest/test_azure_devops_parsing.py
Normal file
15
tests/unittest/test_azure_devops_parsing.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
from pr_agent.git_providers import AzureDevopsProvider
|
||||||
|
|
||||||
|
|
||||||
|
class TestAzureDevOpsParsing():
|
||||||
|
def test_regular_address(self):
|
||||||
|
pr_url = "https://dev.azure.com/organization/project/_git/repo/pullrequest/1"
|
||||||
|
|
||||||
|
# workspace_slug, repo_slug, pr_number
|
||||||
|
assert AzureDevopsProvider._parse_pr_url(pr_url) == ("project", "repo", 1)
|
||||||
|
|
||||||
|
def test_visualstudio_address(self):
|
||||||
|
pr_url = "https://organization.visualstudio.com/project/_git/repo/pullrequest/1"
|
||||||
|
|
||||||
|
# workspace_slug, repo_slug, pr_number
|
||||||
|
assert AzureDevopsProvider._parse_pr_url(pr_url) == ("project", "repo", 1)
|
Reference in New Issue
Block a user