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

[Feature Request] Support pull requests in personal spaces in bitbucket server without requiring any URL hacks #1148

Open
JimiHFord opened this issue Aug 15, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@JimiHFord
Copy link

JimiHFord commented Aug 15, 2024

If you use a repository hosted in a personal space in Bitbucket Server (e.g. https://bitbucket.company-server.url/users/username/repos/my-repo/pull-requests/1, you'll get:

ValueError: The provided URL 'https://bitbucket.company-server.url/users/username/repos/my-repo/pull-requests/1' does not appear to be a Bitbucket PR URL

A workaround/hack our team found was to modify the url from this:

https://bitbucket.company-server.url/users/username/repos/my-repo/pull-requests/1

to this:

https://bitbucket.company-server.url/projects/~username/repos/my-repo/pull-requests/1

(i.e. Change users to projects and add a ~ in front of the username)

This works, but ideally the first URL should work too (i.e. https://bitbucket.company-server.url/users/username/repos/my-repo/pull-requests/1).

Relevant sections of code:

  • def _parse_bitbucket_server(url: str) -> str:
    # pr url format: f"{bitbucket_server}/projects/{project_name}/repos/{repository_name}/pull-requests/{pr_id}"
    parsed_url = urlparse(url)
    server_path = parsed_url.path.split("/projects/")
    if len(server_path) > 1:
    server_path = server_path[0].strip("/")
    return f"{parsed_url.scheme}://{parsed_url.netloc}/{server_path}".strip("/")
    return f"{parsed_url.scheme}://{parsed_url.netloc}"
  • def _parse_pr_url(pr_url: str) -> Tuple[str, str, int]:
    # pr url format: f"{bitbucket_server}/projects/{project_name}/repos/{repository_name}/pull-requests/{pr_id}"
    parsed_url = urlparse(pr_url)
    path_parts = parsed_url.path.strip("/").split("/")
    try:
    projects_index = path_parts.index("projects")
    except ValueError as e:
    raise ValueError(f"The provided URL '{pr_url}' does not appear to be a Bitbucket PR URL")
    path_parts = path_parts[projects_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]
    repo_slug = path_parts[3]
    try:
    pr_number = int(path_parts[5])
    except ValueError as e:
    raise ValueError(f"Unable to convert PR number '{path_parts[5]}' to integer") from e
    return workspace_slug, repo_slug, pr_number
@mrT23
Copy link
Collaborator

mrT23 commented Aug 16, 2024

We are open to pull-request from the community to address this, which would add support for 'personal spaces', and also retain the current support

@mrT23 mrT23 added the answered label Aug 16, 2024
@mrT23 mrT23 added enhancement New feature or request and removed answered labels Sep 1, 2024
vishwamartur added a commit to vishwamartur/pr-agent that referenced this issue Dec 21, 2024
Related to Codium-ai#1148

Update `_parse_pr_url` method in `pr_agent/git_providers/bitbucket_server_provider.py` to handle URLs with `/users/`.

* Add logic to check for both `/projects/` and `/users/` in the URL path and process them accordingly.
* Modify the method to raise a `ValueError` if neither `/projects/` nor `/users/` is found in the URL.
* Update the `workspace_slug` to include a `~` prefix if the URL contains `/users/`.

Add test case for URL with `/users/` in `tests/unittest/test_bitbucket_provider.py`.

* Ensure the new test case verifies the correct parsing of URLs with `/users/`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants