Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-to-build.txt ]; then pip install -r requirements-to-build.txt; fi
python -m pip install poetry
poetry install
- name: Build package
run: |
poetry build
continue-on-error: false
# Linting is done in the run_linters.sh script

- name: Prep tests
Expand All @@ -49,9 +53,10 @@ jobs:
- name: Run linters
working-directory: .
run: |
python -m pip install ruff pylint flake8
chmod +x conf/run_linters.sh
conf/run_linters.sh
#- name: Cache SonarQube packages
# - name: Cache SonarQube packages
# uses: actions/cache@v4
# with:
# path: ./.sonar
Expand Down
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
"sonarlint.focusOnNewCode": true,
"pylint.args": [
"[\"--rcfile=conf/pylintrc\"]"
]
],
"python.testing.pytestArgs": [
"test"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ deletes tokens created since more than a certain number of days
- [Release notes](https://github.com/okorach/sonar-tools/releases)

# Requirements and Installation
- `sonar-tools` requires python 3.8 or higher
- `sonar-tools` requires python 3.9 or higher
- Installation is based on [pip](https://pypi.org/project/pip/).
- Online installation.
- Run: `python3 -m pip install sonar-tools` (or `python3 -m pip upgrade sonar-tools`)
Expand Down
23 changes: 9 additions & 14 deletions cli/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
"""
"""Audits a SonarQube platform"""

Audits a SonarQube platform
from __future__ import annotations

"""
import sys
import json
import csv
from typing import TextIO
from typing import TextIO, Optional
from threading import Thread
from queue import Queue
from requests import RequestException
Expand Down Expand Up @@ -57,7 +55,7 @@ def _audit_sif(sysinfo: str, audit_settings: types.ConfigSettings) -> tuple[str,
"""Audits a SIF and return found problems"""
log.info("Auditing SIF file '%s'", sysinfo)
try:
with open(sysinfo, "r", encoding="utf-8") as f:
with open(sysinfo, encoding="utf-8") as f:
sysinfo = json.loads(f.read())
except json.decoder.JSONDecodeError:
log.critical("File %s does not seem to be a legit JSON file", sysinfo)
Expand All @@ -73,7 +71,7 @@ def _audit_sif(sysinfo: str, audit_settings: types.ConfigSettings) -> tuple[str,


def write_csv(queue: Queue[list[problem.Problem]], fd: TextIO, settings: types.ConfigSettings) -> None:
"""Writes the CSV file of audit problems"""
"""Thread callback to write audit problems in a CSV file"""
server_id = settings.get("SERVER_ID", None)
with_url = settings.get("WITH_URL", False)
csvwriter = csv.writer(fd, delimiter=settings.get("CSV_DELIMITER", ","))
Expand All @@ -92,9 +90,7 @@ def write_csv(queue: Queue[list[problem.Problem]], fd: TextIO, settings: types.C


def write_json(queue: Queue[list[problem.Problem]], fd: TextIO, settings: types.ConfigSettings) -> None:
"""
Thread to write problems in a JSON file
"""
"""Thread callback to write problems in a JSON file"""
server_id = settings.get("SERVER_ID", None)
with_url = settings.get("WITH_URL", False)
comma = ""
Expand All @@ -113,7 +109,7 @@ def write_json(queue: Queue[list[problem.Problem]], fd: TextIO, settings: types.


def _audit_sq(
sq: platform.Platform, settings: types.ConfigSettings, what_to_audit: list[str] = None, key_list: types.KeyList = None
sq: platform.Platform, settings: types.ConfigSettings, what_to_audit: Optional[list[str]] = None, key_list: types.KeyList = None
) -> list[problem.Problem]:
"""Audits a SonarQube/Cloud platform"""
everything = what_to_audit is None
Expand Down Expand Up @@ -178,9 +174,8 @@ def __parser_args(desc: str) -> object:

def __check_keys_exist(key_regexp: list[str], sq: platform.Platform, what: list[str]) -> None:
"""Checks if project keys exist"""
if key_regexp and "projects" in what:
if len(component_helper.get_components(sq, "projects", key_regexp)) == 0:
raise options.ArgumentsError(f"No projects found with key matching regexp '{key_regexp}'")
if key_regexp and "projects" in what and len(component_helper.get_components(sq, "projects", key_regexp)) == 0:
raise options.ArgumentsError(f"No projects found with key matching regexp '{key_regexp}'")


def main() -> None:
Expand Down
3 changes: 2 additions & 1 deletion cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
"""
Exports SonarQube platform configuration as JSON
Exports SonarQube platform configuration as JSON
"""

from typing import TextIO
from threading import Thread
from queue import Queue
Expand Down
6 changes: 3 additions & 3 deletions cli/cust_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
"""
This script manipulates custom measures. You may:
This script manipulates custom measures. You may:

Update a custom measure value:
Usage: cust_measures.py -t <SQ_TOKEN> -u <SQ_URL> -k <projectKey> -m <metricKey> --updateValue <value>
Update a custom measure value:
Usage: cust_measures.py -t <SQ_TOKEN> -u <SQ_URL> -k <projectKey> -m <metricKey> --updateValue <value>
"""

import sys
Expand Down
4 changes: 2 additions & 2 deletions cli/findings_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
"""
This script exports findings as CSV, JSON, or SARIF
This script exports findings as CSV, JSON, or SARIF

Usage: sonar-findings-export.py -t <SQ_TOKEN> -u <SQ_URL> [<filters>]
Usage: sonar-findings-export.py -t <SQ_TOKEN> -u <SQ_URL> [<filters>]

"""

Expand Down
12 changes: 6 additions & 6 deletions cli/findings_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
"""
This script propagates the manual issue changes (FP, WF, Change
of severity, of issue type, comments) from:
- One project to another (normally on different platforms but not necessarily).
The 2 platform don't need to be identical in version, edition or plugins
- One branch of a project to another branch of the same project (normally LLBs)
This script propagates the manual issue changes (FP, WF, Change
of severity, of issue type, comments) from:
- One project to another (normally on different platforms but not necessarily).
The 2 platform don't need to be identical in version, edition or plugins
- One branch of a project to another branch of the same project (normally LLBs)

Only issues with a 100% match are synchronized. When there's a doubt, nothing is done
Only issues with a 100% match are synchronized. When there's a doubt, nothing is done
"""

import datetime
Expand Down
9 changes: 5 additions & 4 deletions cli/housekeeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
#
"""

Removes obsolete data from SonarQube platform
Currently:
- projects, branches, PR not analyzed since a given number of days
- Tokens not renewed since a given number of days
Removes obsolete data from SonarQube platform
Currently:
- projects, branches, PR not analyzed since a given number of days
- Tokens not renewed since a given number of days

"""

import sys

from requests import RequestException
Expand Down
3 changes: 2 additions & 1 deletion cli/loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
"""
Exports LoC per projects
Exports LoC per projects
"""

import sys
import csv
import datetime
Expand Down
9 changes: 5 additions & 4 deletions cli/measures_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
"""
Exports some measures of all projects
- Either all measures (-m _all)
- Or the main measures (-m _main)
- Or a custom selection of measures (-m <measure1,measure2,measure3...>)
Exports some measures of all projects
- Either all measures (-m _all)
- Or the main measures (-m _main)
- Or a custom selection of measures (-m <measure1,measure2,measure3...>)
"""

import sys
import csv
from requests import RequestException
Expand Down
2 changes: 1 addition & 1 deletion cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#
"""

Cmd line options
Cmd line options

"""

Expand Down
3 changes: 1 addition & 2 deletions cli/projects_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
#
"""

Exports/Imports all projects of a SonarQube Server platform
Exports/Imports all projects of a SonarQube Server platform

"""

import sys
import json

from requests import RequestException
Expand Down
3 changes: 2 additions & 1 deletion cli/projects_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
#
"""

Exports all projects of a SonarQube platform
Exports all projects of a SonarQube platform

"""

import sys
from unittest.mock import patch

Expand Down
3 changes: 2 additions & 1 deletion cli/projects_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
#
"""

Imports a list of projects to a SonarQube platform
Imports a list of projects to a SonarQube platform

"""

import sys
from unittest.mock import patch

Expand Down
3 changes: 2 additions & 1 deletion cli/rules_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
"""
Exports rules
Exports rules
"""

import sys
import csv

Expand Down
3 changes: 2 additions & 1 deletion cli/sonar_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

"""Main entry point for sonar-tools"""

from sonar import version
from sonar import version, utilities, errcodes


def main() -> None:
Expand All @@ -48,6 +48,7 @@ def main() -> None:
See tools built-in -h help and https://github.com/okorach/sonar-tools for more documentation
"""
)
utilities.final_exit(errcodes.OK)


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion cli/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
#
"""

Audits a SUPPORT ticket SIF
Audits a SUPPORT ticket SIF

"""

from http import HTTPStatus
import sys
import os
Expand Down
20 changes: 10 additions & 10 deletions conf/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#

ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
CONFDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SONAR_TOOLS_RELEASE="$ROOTDIR/sonar/version.py"
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
CONF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

build_docs=0
build_docker=0

while [ $# -ne 0 ]; do
case $1 in
. "${CONF_DIR}/env.sh"

while [[ $# -ne 0 ]]; do
case "${1}" in
docs|doc)
build_docs=1
;;
Expand All @@ -40,18 +41,17 @@ done
echo "======= FORMATTING CODE ========="
ruff format
echo "======= BUILDING PACKAGE ========="
rm -rf "$ROOTDIR/build/lib/sonar" "$ROOTDIR/build/lib/cli" "$ROOTDIR"/build/scripts*/sonar-tools "$ROOTDIR"/dist/sonar_tools*
rm -rf "${ROOT_DIR}/build/lib/sonar" "${ROOT_DIR}/build/lib/cli" "${ROOT_DIR}"/build/scripts*/sonar-tools "${ROOT_DIR}"/dist/sonar_tools*
# python -m build
poetry build

if [ "$build_docs" == "1" ]; then
if [[ "${build_docs}" = "1" ]]; then
echo "======= BUILDING DOCS ========="
rm -rf doc/api/build
sphinx-build -b html doc/api/source doc/api/build
fi

if [ "$build_docker" == "1" ]; then
if [[ "${build_docker}" = "1" ]]; then
echo "======= BUILDING DOCKER IMAGE WITH SNAPSHOT ========="
version=$(grep PACKAGE_VERSION "$SONAR_TOOLS_RELEASE" | cut -d "=" -f 2 | cut -d '"' -f 2)
docker build -t "olivierkorach/sonar-tools:$version-snapshot" -t olivierkorach/sonar-tools:latest -f "$CONFDIR/snapshot.Dockerfile" "$ROOTDIR" --load
docker build -t "olivierkorach/sonar-tools:${VERSION}-snapshot" -t olivierkorach/sonar-tools:latest -f "${CONF_DIR}/snapshot.Dockerfile" "${ROOT_DIR}" --load
fi
Loading