Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TunahanGuler committed Jan 21, 2025
1 parent 1e4e878 commit 8630a32
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 36 deletions.
4 changes: 0 additions & 4 deletions components/collector/src/source_collectors/bitbucket/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
class BitbucketBase(SourceCollector, ABC):
"""Base class for Bitbucket collectors."""

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()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Bitbucket merge requests collector."""

import pdb
from typing import cast

from collector_utilities.functions import match_string_or_regular_expression
Expand All @@ -9,16 +9,16 @@
from .base import BitbucketProjectBase

class BitbucketMergeRequests(BitbucketProjectBase):
"""Collector for pull requests in Bitbucket."""
"""Collector for merge requests in Bitbucket."""

PAGE_SIZE = 100 # Page size for Bitbucket pagination

async def _api_url(self) -> URL:
"""Override to return the pull requests API."""
"""Override to return the merge requests API."""
return await self._bitbucket_api_url("pull-requests")

async def _landing_url(self, responses: SourceResponses) -> URL:
"""Extend to add the project pull requests."""
"""Extend to add the project merge requests."""
project = f"projects/{self._parameter('owner')}/repos/{self._parameter('repository')}"
return URL(f"{await super()._landing_url(responses)}/{project}/pull-requests")

Expand All @@ -32,7 +32,7 @@ async def _get_source_responses(self, *urls: URL) -> SourceResponses:
return responses

async def _parse_entities(self, responses: SourceResponses) -> Entities:
"""Override to parse the pull requests from the responses."""
"""Override to parse the merge requests from the responses."""
merge_requests = []
for response in responses:
merge_requests.extend((await response.json())["values"])
Expand Down Expand Up @@ -79,4 +79,4 @@ def _downvotes(merge_request) -> int:
@staticmethod
def _upvotes(merge_request) -> int:
"""Return the number of upvotes the merge request has."""
return len([r for r in merge_request.get("reviewers", []) if r.get("vote", True)])
return len([r for r in merge_request.get("reviewers", []) if r.get("approved", True)])
40 changes: 14 additions & 26 deletions components/shared_code/src/shared_data_model/sources/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
StringParameter,
MergeRequestState,
MultipleChoiceParameter,
TargetBranchesToInclude
TargetBranchesToInclude,
Upvotes,
)

ALL_GITLAB_METRICS = [
ALL_BITBUCKET_METRICS = [
"inactive_branches",
"merge_requests",
]
Expand All @@ -42,26 +43,26 @@
help="URL of the Bitbucket instance, with port if necessary, but without path. For example, "
"'https://bitbucket.org'.",
validate_on=["private_token"],
metrics=ALL_GITLAB_METRICS,
metrics=ALL_BITBUCKET_METRICS,
),
"owner": StringParameter(
name="Owner (name of owner of the repository)",
short_name="owner",
mandatory=True,
help_url=HttpUrl("https://support.atlassian.com/bitbucket-cloud/docs/create-a-project/"),
metrics=ALL_GITLAB_METRICS,
metrics=ALL_BITBUCKET_METRICS,
),
"repository": StringParameter(
name="Repository (name of the repository)",
short_name="repository",
help_url=HttpUrl("https://support.atlassian.com/bitbucket-cloud/docs/create-a-git-repository/"),
mandatory=True,
metrics=ALL_GITLAB_METRICS,
metrics=ALL_BITBUCKET_METRICS,
),
"private_token": PrivateToken(
name="Private token (with read_api scope)",
help_url=HttpUrl("https://support.atlassian.com/bitbucket-cloud/docs/create-a-repository-access-token/"),
metrics=ALL_GITLAB_METRICS,
metrics=ALL_BITBUCKET_METRICS,
),
"branches_to_ignore": BranchesToIgnore(help_url=BITBUCKET_BRANCH_HELP_URL),
"branch_merge_status": BranchMergeStatus(),
Expand All @@ -73,21 +74,10 @@
),
"merge_request_state": MergeRequestState(
name="Pull request state",
values=["Open", "Merged", "Closed"],
api_values={"Open": "OPEN", "Merged": "MERGED", "Closed": "CLOSED"},
),
"review_decision": MultipleChoiceParameter(
name="Review decision",
values=["Approved", "Changes requested", "Review required", "Unknown"],
api_values={
"Approved": "APPROVED",
"Changes requested": "CHANGES_REQUESTED",
"Review required": "REVIEW_REQUIRED",
"Unknown": "?",
},
placeholder="all review decisions",
metrics=["merge_requests"],
values=["open", "merged", "declined", "superseded"],
api_values={"open": "OPEN", "merged": "MERGED", "declined": "DECLINED", "superseded": "SUPERSEDED"},
),
"upvotes": Upvotes(),
"target_branches_to_include": TargetBranchesToInclude(help_url=BITBUCKET_BRANCH_HELP_URL),
},
entities={
Expand All @@ -108,14 +98,12 @@
name="merge request",
attributes=[
EntityAttribute(name="Merge request", key="title", url="url"),
EntityAttribute(name="Target branch"),
EntityAttribute(name="Target branch", key="target_branch"),
EntityAttribute(name="State"),
EntityAttribute(name="ReviewDecision"),
EntityAttribute(name="Upvotes", type=EntityAttributeType.INTEGER),
EntityAttribute(name="Downvotes", type=EntityAttributeType.INTEGER),
EntityAttribute(name="Created", type=EntityAttributeType.DATETIME),
EntityAttribute(name="Updated", type=EntityAttributeType.DATETIME),
EntityAttribute(name="Merged", type=EntityAttributeType.DATETIME),
EntityAttribute(name="Comments", type=EntityAttributeType.INTEGER),
EntityAttribute(name="Thumbs up", type=EntityAttributeType.INTEGER),
EntityAttribute(name="Closed", type=EntityAttributeType.DATETIME),
],
),
},
Expand Down

0 comments on commit 8630a32

Please sign in to comment.