Skip to content

Commit

Permalink
[Integration][Sonarqube] - Fix sonarQube client has no attributes met…
Browse files Browse the repository at this point in the history
…rics (#952)
  • Loading branch information
PeyGis authored Aug 28, 2024
1 parent eca6353 commit feb449c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
8 changes: 8 additions & 0 deletions integrations/sonarqube/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- towncrier release notes start -->

## 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)


Expand Down
1 change: 1 addition & 0 deletions integrations/sonarqube/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
9 changes: 3 additions & 6 deletions integrations/sonarqube/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,33 @@ 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


@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


@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
Expand All @@ -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", {})
Expand Down Expand Up @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion integrations/sonarqube/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]

Expand Down

0 comments on commit feb449c

Please sign in to comment.