Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TunahanGuler committed Jan 10, 2025
1 parent fa8f2f6 commit 65bfad4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from base_collectors import SourceCollector
from collector_utilities.functions import add_query
from collector_utilities.type import URL
from model import SourceResponses


class BitbucketBase(SourceCollector, ABC):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from datetime import datetime
from typing import cast

from collector_utilities.exceptions import NotFoundError
from base_collectors import BranchType, InactiveBranchesSourceCollector
from collector_utilities.date_time import parse_datetime
from collector_utilities.exceptions import NotFoundError
from collector_utilities.type import URL
from dateutil.tz import tzutc
from model import SourceResponses

from .base import BitbucketProjectBase


class BitbucketBranchInfoError(NotFoundError):
"""Bitbucket branch info is missing."""

Expand Down Expand Up @@ -44,17 +45,20 @@ async def _branches(self, responses: SourceResponses) -> list[Branch]:
branches = []
for response in responses:
json = await response.json()
metadata = "com.atlassian.bitbucket.server.bitbucket-branch:latest-commit-metadata"
branches.extend([
BitbucketBranchType(
name=branch["displayId"],
default=branch["isDefault"],
last_commit=datetime.fromtimestamp(branch["metadata"]["com.atlassian.bitbucket.server.bitbucket-branch:latest-commit-metadata"]["committerTimestamp"] / 1e3),
last_commit=datetime.fromtimestamp(branch["metadata"][metadata]["committerTimestamp"] / 1e3,
tz=tzutc),
id=branch["id"]
)
for branch in json["values"]
])
if len(branches) == 0:
raise BitbucketBranchInfoError(f"projects/{self._parameter('owner')}/repos/{self._parameter('repository')}")
project = f"projects/{self._parameter('owner')}/repos/{self._parameter('repository')}"
raise BitbucketBranchInfoError(project)
return branches

def _is_default_branch(self, branch: Branch) -> bool:
Expand All @@ -71,7 +75,7 @@ def _commit_datetime(self, branch: Branch) -> datetime:

def _branch_landing_url(self, branch: Branch) -> URL:
"""Override to get the landing URL from the branch."""
instance_url=super()._parameter('url')
instance_url=super()._parameter("url")
project = f"projects/{self._parameter('owner')}/repos/{self._parameter('repository')}/browse?at="
branch_id = branch.get('id').lstrip('/')
return cast(URL, f"{instance_url}/{project}{branch_id or ""}")
branch_id = branch.get("id").lstrip("/")
return cast(URL, f"{instance_url}/{project}{branch_id or ""}")
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Unit tests for the Bitbucket inactive branches collector."""

from datetime import datetime
from dateutil.tz import tzutc
from unittest.mock import AsyncMock

from dateutil.tz import tzutc

from .base import BitbucketTestCase


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@

BITBUCKET = Source(
name="Bitbucket",
description="Bitbucket is a Git-based source code hosting and collaboration tool, built for teams.",
description="Bitbucket is a version control platform by Atlassian that supports Git, "
"enabling developers to collaborate on code with features like pull requests, CI/CD, and seamless integration with tools like Jira and Trello.",
url=HttpUrl("https://bitbucket.org/product/guides/getting-started/overview#a-brief-overview-of-bitbucket/"),
documentation={},
documentation={
"generic": """```{note}
The pagination for the Bitbucket collector has not yet been implemented, and the current limit for retrieving branches for the inactive branches metric using the API is set to 100.
Pagination will be implemented in a future update.
```""",
},
parameters={
"url": URL(
name="Bitbucket instance URL",
Expand Down

0 comments on commit 65bfad4

Please sign in to comment.