Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pull requests in personal spaces in Bitbucket Server #1406

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions pr_agent/git_providers/bitbucket_server_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,17 +402,30 @@ def _parse_pr_url(pr_url: str) -> Tuple[str, str, int]:

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(
f"The provided URL '{pr_url}' does not appear to be a Bitbucket PR URL"
)

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])
Expand Down
7 changes: 7 additions & 0 deletions tests/unittest/test_bitbucket_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ def test_parse_pr_url(self):
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',
Expand Down