Merge pull request #1980 from boston008/bitbucket_provider_support_username_password

feat: enhance BitbucketServerProvider authentication with username and password fallback
This commit is contained in:
ofir-frd 2025-08-15 15:20:00 +03:00 committed by GitHub
commit 10a7a0fbef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -38,10 +38,39 @@ class BitbucketServerProvider(GitProvider):
self.diff_files = None self.diff_files = None
self.bitbucket_pull_request_api_url = pr_url self.bitbucket_pull_request_api_url = pr_url
self.bearer_token = get_settings().get("BITBUCKET_SERVER.BEARER_TOKEN", None) self.bearer_token = get_settings().get("BITBUCKET_SERVER.BEARER_TOKEN", None)
self.bitbucket_server_url = self._parse_bitbucket_server(url=pr_url) # Get username and password from settings
self.bitbucket_client = bitbucket_client or Bitbucket(url=self.bitbucket_server_url, username = get_settings().get("BITBUCKET_SERVER.USERNAME", None)
token=get_settings().get("BITBUCKET_SERVER.BEARER_TOKEN", password = get_settings().get("BITBUCKET_SERVER.PASSWORD", None)
None)) # If bitbucket_client is provided, try to extract the server URL from its configuration
if bitbucket_client:
self.bitbucket_client = bitbucket_client
try:
# Get the base URL from the existing client
self.bitbucket_server_url = bitbucket_client.url
except AttributeError:
# If we can't get the URL from the client, try parsing it from PR URL
self.bitbucket_server_url = self._parse_bitbucket_server(url=pr_url) if pr_url else None
else:
# Parse server URL from PR URL
self.bitbucket_server_url = self._parse_bitbucket_server(url=pr_url) if pr_url else None
# Validate the server URL unless we have a pre-configured client
if not bitbucket_client and not self.bitbucket_server_url:
raise ValueError("Invalid or missing Bitbucket Server URL parsed from PR URL.")
# If no client provided, create one with the appropriate authentication
if not bitbucket_client:
if self.bearer_token:
self.bitbucket_client = Bitbucket(
url=self.bitbucket_server_url,
token=self.bearer_token
)
else:
self.bitbucket_client = Bitbucket(
url=self.bitbucket_server_url,
username=username,
password=password
)
try: try:
self.bitbucket_api_version = parse_version(self.bitbucket_client.get("rest/api/1.0/application-properties").get('version')) self.bitbucket_api_version = parse_version(self.bitbucket_client.get("rest/api/1.0/application-properties").get('version'))
except Exception: except Exception: