Merge pull request #1406 from vishwamartur/support-personal-spaces

Support pull requests in personal spaces in Bitbucket Server
This commit is contained in:
Tal
2025-01-01 09:26:29 +02:00
committed by GitHub
2 changed files with 22 additions and 2 deletions

View File

@ -402,10 +402,21 @@ class BitbucketServerProvider(GitProvider):
try:
projects_index = path_parts.index("projects")
except ValueError as e:
except ValueError:
projects_index = -1
try:
users_index = path_parts.index("users")
except ValueError:
users_index = -1
if projects_index == -1 and users_index == -1:
raise ValueError(f"The provided URL '{pr_url}' does not appear to be a Bitbucket PR URL")
path_parts = path_parts[projects_index:]
if projects_index != -1:
path_parts = path_parts[projects_index:]
else:
path_parts = path_parts[users_index:]
if len(path_parts) < 6 or path_parts[2] != "repos" or path_parts[4] != "pull-requests":
raise ValueError(
@ -413,6 +424,8 @@ class BitbucketServerProvider(GitProvider):
)
workspace_slug = path_parts[1]
if users_index != -1:
workspace_slug = f"~{workspace_slug}"
repo_slug = path_parts[3]
try:
pr_number = int(path_parts[5])

View File

@ -24,6 +24,13 @@ class TestBitbucketServerProvider:
assert repo_slug == "my-repo"
assert pr_number == 1
def test_parse_pr_url_with_users(self):
url = "https://bitbucket.company-server.url/users/username/repos/my-repo/pull-requests/1"
workspace_slug, repo_slug, pr_number = BitbucketServerProvider._parse_pr_url(url)
assert workspace_slug == "~username"
assert repo_slug == "my-repo"
assert pr_number == 1
def mock_get_content_of_file(self, project_key, repository_slug, filename, at=None, markup=None):
content_map = {
'9c1cffdd9f276074bfb6fb3b70fbee62d298b058': 'file\nwith\nsome\nlines\nto\nemulate\na\nreal\nfile\n',