mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-12-15 04:15:18 +00:00
Update bitbucket_server_provider.py
This commit is contained in:
parent
01f16f57ca
commit
e0a4be1397
1 changed files with 20 additions and 12 deletions
|
|
@ -41,28 +41,36 @@ class BitbucketServerProvider(GitProvider):
|
||||||
# Get username and password from settings
|
# Get username and password from settings
|
||||||
username = get_settings().get("BITBUCKET_SERVER.USERNAME", None)
|
username = get_settings().get("BITBUCKET_SERVER.USERNAME", None)
|
||||||
password = get_settings().get("BITBUCKET_SERVER.PASSWORD", None)
|
password = get_settings().get("BITBUCKET_SERVER.PASSWORD", None)
|
||||||
self.bitbucket_server_url = self._parse_bitbucket_server(url=pr_url)
|
# If bitbucket_client is provided, try to extract the server URL from its configuration
|
||||||
if not self.bitbucket_server_url:
|
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.")
|
raise ValueError("Invalid or missing Bitbucket Server URL parsed from PR URL.")
|
||||||
# If bearer token is provided, use it to authenticate, otherwise use username and password
|
|
||||||
try:
|
# If no client provided, create one with the appropriate authentication
|
||||||
|
if not bitbucket_client:
|
||||||
if self.bearer_token:
|
if self.bearer_token:
|
||||||
self.bitbucket_client = bitbucket_client or Bitbucket(
|
self.bitbucket_client = Bitbucket(
|
||||||
url=self.bitbucket_server_url,
|
url=self.bitbucket_server_url,
|
||||||
token=self.bearer_token
|
token=self.bearer_token
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if not username or not password:
|
self.bitbucket_client = Bitbucket(
|
||||||
raise ValueError("Bitbucket authentication requires either 'BITBUCKET_SERVER.BEARER_TOKEN' or both 'BITBUCKET_SERVER.USERNAME' and 'BITBUCKET_SERVER.PASSWORD'.")
|
|
||||||
|
|
||||||
self.bitbucket_client = bitbucket_client or Bitbucket(
|
|
||||||
url=self.bitbucket_server_url,
|
url=self.bitbucket_server_url,
|
||||||
username=username,
|
username=username,
|
||||||
password=password
|
password=password
|
||||||
)
|
)
|
||||||
except Exception as e:
|
|
||||||
get_logger().error(f"Failed to initialize Bitbucket client for {self.bitbucket_server_url}: {e}")
|
|
||||||
raise
|
|
||||||
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:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue