Skip to content

Commit 4a412d3

Browse files
[Integration][SonarQube] Bug | 404 response when querying SonarQube issues (#1105)
# Description What - Fixed a bug where SonarQube instances lower than 10.2 report a 404 error when retrieving issues Why - This is because the issues list API on SonarQube was introduced in 10.2 and also as an internal API How - Checking for the integration version and choosing the right API based on the integration version ## Type of change Please leave one option from the following and delete the rest: - [x] Bug fix (non-breaking change which fixes an issue) <h4> All tests should be run against the port production environment(using a testing org). </h4> ### Core testing checklist - [ ] Integration able to create all default resources from scratch - [ ] Resync finishes successfully - [ ] Resync able to create entities - [ ] Resync able to update entities - [ ] Resync able to detect and delete entities - [ ] Scheduled resync able to abort existing resync and start a new one - [ ] Tested with at least 2 integrations from scratch - [ ] Tested with Kafka and Polling event listeners - [ ] Tested deletion of entities that don't pass the selector ### Integration testing checklist - [x] Integration able to create all default resources from scratch - [x] Resync able to create entities - [x] Resync able to update entities - [x] Resync able to detect and delete entities - [x] Resync finishes successfully - [ ] If new resource kind is added or updated in the integration, add example raw data, mapping and expected result to the `examples` folder in the integration directory. - [ ] If resource kind is updated, run the integration with the example data and check if the expected result is achieved - [ ] If new resource kind is added or updated, validate that live-events for that resource are working as expected - [ ] Docs PR link [here](#) ### Preflight checklist - [ ] Handled rate limiting - [ ] Handled pagination - [ ] Implemented the code in async - [ ] Support Multi account ## Screenshots ![image](https://github.com/user-attachments/assets/9162bb91-71ec-4da1-9dad-b93fb14c75a0) ## API Documentation [SonarQube issues list API](https://next.sonarqube.com/sonarqube/web_api/api/issues/list?internal=true) --------- Co-authored-by: PagesCoffy <isaac.p.coffie@gmail.com>
1 parent 83d1ff1 commit 4a412d3

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

integrations/sonarqube/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
<!-- towncrier release notes start -->
99

10+
## 0.1.105 (2024-10-29)
11+
12+
13+
### Bug Fixes
14+
15+
- Fixed bug where issues/list API is not available for older SonarQube instance versions
16+
17+
1018
## 0.1.104 (2024-10-23)
1119

1220

integrations/sonarqube/client.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class Endpoints:
3838
WEBHOOKS = "webhooks"
3939
MEASURES = "measures/component"
4040
BRANCHES = "project_branches/list"
41-
ONPREM_ISSUES = "issues/list"
42-
SAAS_ISSUES = "issues/search"
41+
ISSUES_SEARCH = "issues/search"
4342
ANALYSIS = "activity_feed/list"
4443
PORTFOLIO_DETAILS = "views/show"
4544
PORTFOLIOS = "views/list"
@@ -160,7 +159,7 @@ async def send_paginated_api_request(
160159
if (
161160
e.response.status_code == 400
162161
and query_params.get("ps", 0) > PAGE_SIZE
163-
and endpoint in [Endpoints.ONPREM_ISSUES, Endpoints.SAAS_ISSUES]
162+
and endpoint == Endpoints.ISSUES_SEARCH
164163
):
165164
logger.error(
166165
"The request exceeded the maximum number of issues that can be returned (10,000) from SonarQube API. Consider using apiFilters in the config mapping to narrow the scope of your search. Returning accumulated issues and skipping further results."
@@ -336,20 +335,17 @@ async def get_issues_by_component(
336335
"""
337336
component_issues = []
338337
component_key = component.get("key")
339-
endpoint_path = ""
340338

341339
if self.is_onpremise:
342-
query_params = {"project": component_key}
343-
endpoint_path = Endpoints.ONPREM_ISSUES
340+
query_params = {"components": component_key}
344341
else:
345342
query_params = {"componentKeys": component_key}
346-
endpoint_path = Endpoints.SAAS_ISSUES
347343

348344
if api_query_params:
349345
query_params.update(api_query_params)
350346

351347
response = await self.send_paginated_api_request(
352-
endpoint=endpoint_path,
348+
endpoint=Endpoints.ISSUES_SEARCH,
353349
data_key="issues",
354350
query_params=query_params,
355351
)

integrations/sonarqube/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "sonarqube"
3-
version = "0.1.104"
3+
version = "0.1.105"
44
description = "SonarQube projects and code quality analysis integration"
55
authors = ["Port Team <support@getport.io>"]
66

0 commit comments

Comments
 (0)