Fix missing self.bearer_token for bitbucket related providers

This commit is contained in:
Eyal Sharon
2025-03-24 10:21:23 +02:00
parent 1bd65934df
commit e14fc7e02d
2 changed files with 8 additions and 5 deletions

View File

@ -30,12 +30,15 @@ class BitbucketProvider(GitProvider):
):
s = requests.Session()
try:
bearer = context.get("bitbucket_bearer_token", None)
self.bearer_token = bearer = context.get("bitbucket_bearer_token", None)
if not bearer and get_settings().get("BITBUCKET.BEARER_TOKEN", None):
self.bearer_token = bearer = get_settings().get("BITBUCKET.BEARER_TOKEN", None)
s.headers["Authorization"] = f"Bearer {bearer}"
except Exception:
self.bearer_token = get_settings().get("BITBUCKET.BEARER_TOKEN", None)
s.headers[
"Authorization"
] = f'Bearer {get_settings().get("BITBUCKET.BEARER_TOKEN", None)}'
] = f'Bearer {self.bearer_token}'
s.headers["Content-Type"] = "application/json"
self.headers = s.headers
self.bitbucket_client = Cloud(session=s)
@ -488,7 +491,7 @@ class BitbucketProvider(GitProvider):
return True
@staticmethod
def _parse_pr_url(pr_url: str) -> Tuple[str, int]:
def _parse_pr_url(pr_url: str) -> Tuple[str, int, int]:
parsed_url = urlparse(pr_url)
if "bitbucket.org" not in parsed_url.netloc:

View File

@ -36,7 +36,7 @@ class BitbucketServerProvider(GitProvider):
self.incremental = incremental
self.diff_files = None
self.bitbucket_pull_request_api_url = pr_url
self.bearer_token = get_settings().get("BITBUCKET_SERVER.BEARER_TOKEN", None)
self.bitbucket_server_url = self._parse_bitbucket_server(url=pr_url)
self.bitbucket_client = bitbucket_client or Bitbucket(url=self.bitbucket_server_url,
token=get_settings().get("BITBUCKET_SERVER.BEARER_TOKEN",
@ -67,7 +67,7 @@ class BitbucketServerProvider(GitProvider):
desired_branch = self.get_pr_branch()
workspace_name = self.workspace_slug
project_name = self.repo_slug
else:
elif '.git' in repo_git_url and 'scm/' in repo_git_url:
repo_path = repo_git_url.split('.git')[0].split('scm/')[-1]
if repo_path.count('/') == 1: # Has to have the form <workspace>/<repo>
workspace_name, project_name = repo_path.split('/')