mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-04 04:40:38 +08:00
Azure devops: parse PR url starting from the end
This commit is contained in:
@ -543,22 +543,21 @@ class AzureDevopsProvider(GitProvider):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_pr_url(pr_url: str) -> Tuple[str, str, int]:
|
def _parse_pr_url(pr_url: str) -> Tuple[str, str, int]:
|
||||||
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:
|
num_parts = len(path_parts)
|
||||||
raise ValueError(
|
if num_parts < 5:
|
||||||
"The provided URL does not appear to be a Azure DevOps PR URL"
|
raise ValueError("The provided URL has insufficient path components for an Azure DevOps PR URL")
|
||||||
)
|
|
||||||
if len(path_parts) == 6: # "https://dev.azure.com/organization/project/_git/repo/pullrequest/1"
|
# Verify that the second-to-last path component is "pullrequest"
|
||||||
workspace_slug = path_parts[1]
|
if path_parts[num_parts - 2] != "pullrequest":
|
||||||
repo_slug = path_parts[3]
|
raise ValueError("The provided URL does not follow the expected Azure DevOps PR URL format")
|
||||||
pr_number = int(path_parts[5])
|
|
||||||
elif len(path_parts) == 5: # 'https://organization.visualstudio.com/project/_git/repo/pullrequest/1'
|
workspace_slug = path_parts[num_parts - 5]
|
||||||
workspace_slug = path_parts[0]
|
repo_slug = path_parts[num_parts - 3]
|
||||||
repo_slug = path_parts[2]
|
try:
|
||||||
pr_number = int(path_parts[4])
|
pr_number = int(path_parts[num_parts - 1])
|
||||||
else:
|
except ValueError as e:
|
||||||
raise ValueError("The provided URL does not appear to be a Azure DevOps PR URL")
|
raise ValueError("Cannot parse PR number in the provided URL") from e
|
||||||
|
|
||||||
return workspace_slug, repo_slug, pr_number
|
return workspace_slug, repo_slug, pr_number
|
||||||
|
|
||||||
|
@ -13,3 +13,10 @@ class TestAzureDevOpsParsing():
|
|||||||
|
|
||||||
# workspace_slug, repo_slug, pr_number
|
# workspace_slug, repo_slug, pr_number
|
||||||
assert AzureDevopsProvider._parse_pr_url(pr_url) == ("project", "repo", 1)
|
assert AzureDevopsProvider._parse_pr_url(pr_url) == ("project", "repo", 1)
|
||||||
|
|
||||||
|
def test_self_hosted_address(self):
|
||||||
|
pr_url = "http://server.be:8080/tfs/department/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