Skip to content

Commit

Permalink
added authorization and changed api url
Browse files Browse the repository at this point in the history
  • Loading branch information
TunahanGuler committed Dec 23, 2024
1 parent 1679c0c commit 487ae2e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions components/collector/src/source_collectors/bitbucket/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def _basic_auth_credentials(self) -> tuple[str, str] | None:
"""Override to return None, as the private token is passed as header."""
return None

def _headers(self) -> dict[str, str]:
"""Extend to add the private token, if any, to the headers."""
headers = super()._headers()
if private_token := self._parameter("private_token"):
headers["Authorization"] = "Bearer " + str(private_token)
return headers

async def _next_urls(self, responses: SourceResponses) -> list[URL]:
"""Return the next (pagination) links from the responses."""
return [URL(next_url) for response in responses if (next_url := response.links.get("next", {}).get("url"))]
Expand All @@ -37,6 +44,6 @@ class BitbucketProjectBase(BitbucketBase, ABC):
async def _bitbucket_api_url(self, api: str) -> URL:
"""Return a Bitbucket API url for a project, if present in the parameters."""
url = await super()._api_url()
project = self._parameter("project", quote=True)
api_url = URL(f"{url}/api/v4/projects/{project}" + (f"/{api}" if api else ""))
return add_query(api_url, "per_page=100")
project = self._parameter("project")
api_url = URL(f"{url}/rest/api/1.0/projects/{project}" + (f"/{api}" if api else ""))
return add_query(api_url, "pagelen=100")
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BitbucketInactiveBranches[Branch: BitbucketBranchType](BitbucketProjectBas

async def _api_url(self) -> URL:
"""Override to return the branches API."""
return await self._bitbucket_api_url("repository/branches")
return await self._bitbucket_api_url("branches")

async def _landing_url(self, responses: SourceResponses) -> URL:
"""Extend to add the project branches."""
Expand Down

0 comments on commit 487ae2e

Please sign in to comment.