generate_report.sh: Unmangle LTS jobs

LTS jobs have "lts2.8" infix, and that gets mangled by Jenkins plugin to
"lts2_8". It's a bit too late to change naming convention, and we unmangle
names anyway, so just add another adhoc rule for the case above.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Change-Id: I95b9bc6d2ead3a3fe346ebfc8ba784916215f18c
(cherry picked from commit bfa80ed4d260cd350b9bcaa9e20aa47f2b522b90)
diff --git a/job/tf-ci-gateway/generate_report.sh b/job/tf-ci-gateway/generate_report.sh
index 730c503..4f9d8b7 100755
--- a/job/tf-ci-gateway/generate_report.sh
+++ b/job/tf-ci-gateway/generate_report.sh
@@ -7,6 +7,19 @@
 
 set -ex
 
+# Jenkins Parameterized Trigger Plugin mangles job names as passed via
+# environment variables, replacing most non-alphanumeric chars with
+# underscore. The mangling is generally non-reversible, but we apply
+# "heuristics" based on our naming conventions.
+function unmangle_job_name() {
+    # Two numbers seperated by undescore was likely a version number originally,
+    # e.g. lts2.8 -> lts2_8.
+    s=$(python3 -c 'import sys, re; print(re.sub(r"(\d+)_(\d+)", r"\1.\2", sys.argv[1]))' "$1")
+    # Otherwise, we use hyphens as seperators.
+    s=$(echo $s | tr "_" "-")
+    echo $s
+}
+
 # Generate test report
 if [ "$CI_ROOT" ]; then
 	# Gather Coverity scan summary if it was performed as part of this job
@@ -21,9 +34,7 @@
 		worker_job="${worker_job:-tf-worker}"
 		lava_job="${lava_job:-tf-build-for-lava}"
 	else
-		# ${TRIGGERED_JOB_NAMES} has hyphens replaced with underscores.
-		# As we know that we use hyphen convention, translate it back.
-		triggered_job=$(echo ${TRIGGERED_JOB_NAMES} | tr "_" "-")
+		triggered_job=$(unmangle_job_name "${TRIGGERED_JOB_NAMES}")
 		worker_job="${worker_job:-${triggered_job}}"
 		lava_job="${lava_job:-${triggered_job}}"
 	fi