diff --git a/integrations/sonarqube/CHANGELOG.md b/integrations/sonarqube/CHANGELOG.md index e1e90f1a94..d0a1991da2 100644 --- a/integrations/sonarqube/CHANGELOG.md +++ b/integrations/sonarqube/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 +## 0.1.86 (2024-08-26) + + +### Bug Fixes + +- Fixed SonarQube client instantiation issue by using a singleton pattern to ensure a single shared instance, resolving bug where the client is unable to find the self.metrics + + ## 0.1.85 (2024-08-26) diff --git a/integrations/sonarqube/client.py b/integrations/sonarqube/client.py index c46e864836..c6ee098380 100644 --- a/integrations/sonarqube/client.py +++ b/integrations/sonarqube/client.py @@ -43,6 +43,7 @@ def __init__( self.is_onpremise = is_onpremise self.http_client = http_async_client self.http_client.headers.update(self.api_auth_params["headers"]) + self.metrics: list[str] = [] @property def api_auth_params(self) -> dict[str, Any]: diff --git a/integrations/sonarqube/main.py b/integrations/sonarqube/main.py index 49d5504ad5..457cbe405e 100644 --- a/integrations/sonarqube/main.py +++ b/integrations/sonarqube/main.py @@ -18,18 +18,19 @@ def init_sonar_client() -> SonarQubeClient: ) +sonar_client = init_sonar_client() + + @ocean.on_resync(ObjectKind.PROJECTS) async def on_project_resync(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE: logger.info(f"Listing Sonarqube resource: {kind}") - sonar_client = init_sonar_client() async for project_list in sonar_client.get_all_projects(): yield project_list @ocean.on_resync(ObjectKind.ISSUES) async def on_issues_resync(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE: - sonar_client = init_sonar_client() async for issues_list in sonar_client.get_all_issues(): yield issues_list @@ -37,7 +38,6 @@ async def on_issues_resync(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE: @ocean.on_resync(ObjectKind.ANALYSIS) @ocean.on_resync(ObjectKind.SASS_ANALYSIS) async def on_saas_analysis_resync(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE: - sonar_client = init_sonar_client() if not ocean.integration_config["sonar_is_on_premise"]: async for analyses_list in sonar_client.get_all_sonarcloud_analyses(): yield analyses_list @@ -45,7 +45,6 @@ async def on_saas_analysis_resync(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE: @ocean.on_resync(ObjectKind.ONPREM_ANALYSIS) async def on_onprem_analysis_resync(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE: - sonar_client = init_sonar_client() if ocean.integration_config["sonar_is_on_premise"]: async for analyses_list in sonar_client.get_all_sonarqube_analyses(): yield analyses_list @@ -56,7 +55,6 @@ async def handle_sonarqube_webhook(webhook_data: dict[str, Any]) -> None: logger.info( f"Processing Sonarqube webhook for event type: {webhook_data.get('project', {}).get('key')}" ) - sonar_client = init_sonar_client() project = await sonar_client.get_single_component( webhook_data.get("project", {}) @@ -89,7 +87,6 @@ async def on_start() -> None: "Organization ID is required for SonarCloud. Please specify a valid sonarOrganizationId" ) - sonar_client = init_sonar_client() sonar_client.sanity_check() if ocean.event_listener_type == "ONCE": diff --git a/integrations/sonarqube/pyproject.toml b/integrations/sonarqube/pyproject.toml index bca1c00462..33635617db 100644 --- a/integrations/sonarqube/pyproject.toml +++ b/integrations/sonarqube/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "sonarqube" -version = "0.1.85" +version = "0.1.86" description = "SonarQube projects and code quality analysis integration" authors = ["Port Team "]