Skip to content

Commit 9b85b93

Browse files
committed
Lowercase impacts sw qualities
1 parent 982a415 commit 9b85b93

File tree

5 files changed

+151
-13
lines changed

5 files changed

+151
-13
lines changed

conf/build.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ CONF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2121

2222
build_docs=0
2323
build_docker=0
24+
offline=0
2425

2526
. "${CONF_DIR}/env.sh"
2627

@@ -32,6 +33,9 @@ while [[ $# -ne 0 ]]; do
3233
docker)
3334
build_docker=1
3435
;;
36+
offline)
37+
offline=1
38+
;;
3539
*)
3640
;;
3741
esac
@@ -41,9 +45,13 @@ done
4145
echo "======= FORMATTING CODE ========="
4246
ruff format
4347
echo "======= BUILDING PACKAGE ========="
44-
rm -rf "${ROOT_DIR}/build/lib/sonar" "${ROOT_DIR}/build/lib/cli" "${ROOT_DIR}"/build/scripts*/sonar-tools "${ROOT_DIR}"/dist/sonar_tools*
45-
# python -m build
46-
poetry build
48+
if [[ "${offline}" = "1" ]]; then
49+
python setup.py bdist_wheel
50+
# python -m build
51+
else
52+
rm -rf "${ROOT_DIR}/build/lib/sonar" "${ROOT_DIR}/build/lib/cli" "${ROOT_DIR}"/build/scripts*/sonar-tools "${ROOT_DIR}"/dist/sonar_tools*
53+
poetry build
54+
fi
4755

4856
if [[ "${build_docs}" = "1" ]]; then
4957
echo "======= BUILDING DOCS ========="
File renamed without changes.

setup.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#
2+
# sonar-tools
3+
# Copyright (C) 2019-2025 Olivier Korach
4+
# mailto:olivier.korach AT gmail DOT com
5+
#
6+
# This program is free software; you can redistribute it and/or
7+
# modify it under the terms of the GNU Lesser General Public
8+
# License as published by the Free Software Foundation; either
9+
# version 3 of the License, or (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
# Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with this program; if not, write to the Free Software Foundation,
18+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
#
20+
21+
"""
22+
23+
Package setup
24+
25+
"""
26+
27+
import setuptools
28+
from sonar import version
29+
30+
31+
with open("README.md", "r", encoding="utf-8") as fh:
32+
long_description = fh.read()
33+
setuptools.setup(
34+
name="sonar-tools",
35+
version=version.PACKAGE_VERSION,
36+
scripts=["sonar-tools"],
37+
author="Olivier Korach",
38+
author_email="[email protected]",
39+
description="A collection of utility scripts for SonarQube Server or Cloud",
40+
long_description=long_description,
41+
long_description_content_type="text/markdown",
42+
url="https://github.com/okorach/sonar-tools",
43+
project_urls={
44+
"Bug Tracker": "https://github.com/okorach/sonar-tools/issues",
45+
"Documentation": "https://github.com/okorach/sonar-tools/README.md",
46+
"Source Code": "https://github.com/okorach/sonar-tools",
47+
},
48+
packages=setuptools.find_packages(),
49+
package_data={"sonar": ["LICENSE", "audit/rules.json", "config.json", "audit/sonar-audit.properties"]},
50+
install_requires=[
51+
"argparse",
52+
"datetime",
53+
"python-dateutil",
54+
"requests",
55+
"jprops",
56+
"levenshtein",
57+
"PyYAML ",
58+
],
59+
classifiers=[
60+
"Programming Language :: Python :: 3",
61+
"License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)",
62+
"Operating System :: OS Independent",
63+
],
64+
entry_points={
65+
"console_scripts": [
66+
"sonar-audit = cli.audit:main",
67+
"sonar-projects-export = cli.projects_export:main",
68+
"sonar-projects-import = cli.projects_import:main",
69+
"sonar-projects = cli.projects_cli:main",
70+
"sonar-measures-export = cli.measures_export:main",
71+
"sonar-housekeeper = cli.housekeeper:main",
72+
"sonar-issues-sync = cli.findings_sync:main",
73+
"sonar-findings-sync = cli.findings_sync:main",
74+
"sonar-custom-measures = cli.cust_measures:main",
75+
"sonar-issues-export = cli.findings_export:main",
76+
"sonar-findings-export = cli.findings_export:main",
77+
"sonar-loc = cli.loc:main",
78+
"sonar-config = cli.config:main",
79+
"support-audit = cli.support:main",
80+
"sonar-rules = cli.rules_cli:main",
81+
]
82+
},
83+
python_requires=">=3.8",
84+
)

sonar-tools

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python3
2+
#
3+
# sonar-tools
4+
# Copyright (C) 2019-2025 Olivier Korach
5+
# mailto:olivier.korach AT gmail DOT com
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU Lesser General Public
9+
# License as published by the Free Software Foundation; either
10+
# version 3 of the License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
# Lesser General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Lesser General Public License
18+
# along with this program; if not, write to the Free Software Foundation,
19+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20+
#
21+
22+
"""Main entry point for sonar-tools"""
23+
24+
from sonar import version
25+
26+
print(f'''
27+
sonar-tools version {version.PACKAGE_VERSION}
28+
(c) Olivier Korach 2019-2025
29+
Collections of utilities for SonarQube Server and Cloud:
30+
- sonar-audit: Audits a SonarQube Server or Cloud platform for bad practices, performance, configuration problems
31+
- sonar-housekeeper: Deletes projects that have not been analyzed since a given number of days
32+
- sonar-loc: Produces a list of projects with their LoC count as computed by SonarQube Server or Cloud
33+
commercial licenses (ie taking the largest branch or PR)
34+
- sonar-measures-export: Exports measures/metrics of one, several or all projects of the platform in CSV or JSON
35+
(Can also export measures history)
36+
- sonar-findings-export: Exports findings (potentially filtered) from the platform in CSV or JSON
37+
(also available as sonar-issues-export for backward compatibility, but deprecated)
38+
- sonar-findings-sync: Synchronizes issues between 2 branches of a same project, a whole project
39+
branches of 2 different projects (potentially on different platforms).
40+
(also available as sonar-issues-sync for backward compatibility, but deprecated)
41+
- sonar-projects: Exports / Imports projects to/from zip file (Import works for EE and higher)
42+
- sonar-config: Exports and imports an entire (or subsets of a) SonarQube Server or Cloud platform configuration as code (JSON)
43+
- sonar-rules: Exports Sonar rules
44+
See tools built-in -h help and https://github.com/okorach/sonar-tools for more documentation
45+
''')

sonar/rules.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,18 +349,19 @@ def impacts(self, quality_profile_id: Optional[str] = None, substitute_with_defa
349349
self.refresh()
350350
found_qp = next((qp for qp in self.sq_json.get("actives", []) if quality_profile_id and qp["qProfile"] == quality_profile_id), None)
351351
if not found_qp:
352-
return self._impacts if len(self._impacts) > 0 else {TYPE_TO_QUALITY[self.type]: self.severity}
353-
if self.endpoint.is_mqr_mode():
354-
qp_impacts = {imp["softwareQuality"]: imp["severity"] for imp in found_qp["impacts"]}
355-
default_impacts = self._impacts
352+
qp_impacts = self._impacts if len(self._impacts) > 0 else {TYPE_TO_QUALITY[self.type]: self.severity}
356353
else:
357-
qp_impacts = {TYPE_TO_QUALITY[self.type]: self.severity}
358-
default_impacts = {TYPE_TO_QUALITY[self.type]: self.severity}
354+
if self.endpoint.is_mqr_mode():
355+
qp_impacts = {imp["softwareQuality"]: imp["severity"] for imp in found_qp["impacts"]}
356+
default_impacts = self._impacts
357+
else:
358+
qp_impacts = {TYPE_TO_QUALITY[self.type]: self.severity}
359+
default_impacts = {TYPE_TO_QUALITY[self.type]: self.severity}
359360

360-
if substitute_with_default:
361-
return {k: c.DEFAULT if qp_impacts[k] == default_impacts.get(k, qp_impacts[k]) else v for k, v in qp_impacts.items()}
362-
else:
363-
return qp_impacts
361+
if substitute_with_default:
362+
qp_impacts = {k: c.DEFAULT if qp_impacts[k] == default_impacts.get(k, qp_impacts[k]) else v for k, v in qp_impacts.items()}
363+
364+
return {k.lower(): v for k, v in qp_impacts.items()}
364365

365366
def __get_quality_profile_data(self, quality_profile_id: str) -> Optional[dict[str, str]]:
366367
if not quality_profile_id:

0 commit comments

Comments
 (0)