From ba7399884688452762d5d2d873f6ae82ab026a50 Mon Sep 17 00:00:00 2001
From: Guilhem Bonnefille <guilhem.bonnefille@c-s.fr>
Date: Thu, 9 Jun 2022 11:37:15 +0000
Subject: [PATCH] feat(lint): add a report for SonarQube

SonarQube is able to ingest pylint reports:
https://docs.sonarqube.org/latest/analysis/external-issues/
Add a dedicated pylint run to generate this report.
---
 README.md                      | 1 +
 templates/gitlab-ci-python.yml | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/README.md b/README.md
index 065c057..115703a 100644
--- a/README.md
+++ b/README.md
@@ -73,6 +73,7 @@ It is bound to the `build` stage, and uses the following variables:
 This job produces the following artifacts, kept for one day:
 
 * Code quality json report in code climate format.
+* Pylint report for SonarQube (if `SONAR_URL` is defined).
 
 ### Test jobs
 
diff --git a/templates/gitlab-ci-python.yml b/templates/gitlab-ci-python.yml
index a63957e..bc75751 100644
--- a/templates/gitlab-ci-python.yml
+++ b/templates/gitlab-ci-python.yml
@@ -599,6 +599,12 @@ py-lint:
         # success: generate empty codeclimate report (required by GitLab :( )
         echo "[]" > reports/pylint-codeclimate.json
       fi
+    - |
+      if [ -n "$SONAR_URL" ]
+      then
+        # SonarQube is configured, export analysis report
+        _run pylint --ignore=.cache --output-format=parseable  ${PYLINT_ARGS} ${PYLINT_FILES:-$(find -type f -name "*.py")} > reports/pylint.txt
+      fi
   artifacts:
     name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
     expire_in: 1 day
-- 
GitLab