From e8ce8942be093b8e5e5293600f2810bd335b9e99 Mon Sep 17 00:00:00 2001 From: Romain Le Jeune Date: Wed, 9 Aug 2023 11:39:08 +0000 Subject: [PATCH] feat(GODT-2788): Add preview to bug report validation. --- .gitlab-ci.yml | 9 +++++++++ Makefile | 3 +++ utils/validate_bug_report_file.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4ddf9720..e415c174 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -118,6 +118,15 @@ lint: tags: - medium +bug-report-preview: + stage: test + extends: + - .rules-branch-and-MR-manual + script: + - make lint-bug-report-preview + tags: + - medium + .script-test: stage: test extends: diff --git a/Makefile b/Makefile index 067add8a..15b69e4a 100644 --- a/Makefile +++ b/Makefile @@ -310,6 +310,9 @@ lint-golang: lint-bug-report: python3 utils/validate_bug_report_file.py --file "internal/frontend/bridge-gui/bridge-gui/qml/Resources/bug_report_flow.json" +lint-bug-report-preview: + python3 utils/validate_bug_report_file.py --file "internal/frontend/bridge-gui/bridge-gui/qml/Resources/bug_report_flow.json" --preview + gobinsec: gobinsec-cache.yml build gobinsec -wait -cache -config utils/gobinsec_conf.yml ${EXE_TARGET} ${DEPLOY_DIR}/${TARGET_OS}/${LAUNCHER_EXE} diff --git a/utils/validate_bug_report_file.py b/utils/validate_bug_report_file.py index d2b89a3f..f5dd3088 100755 --- a/utils/validate_bug_report_file.py +++ b/utils/validate_bug_report_file.py @@ -181,10 +181,37 @@ class BugReportJson: unique_list.append(question) return True + def preview(self): + for category in self.categories: + self.preview_category(category) + + def preview_category(self, category): + print(" > %s" % category["name"]) + if "hint" in category and category["hint"]: + print("(%s)" % category["hint"]) + for question in category["questions"]: + self.preview_question(self.questions[question]) + print("\n\r") + return 0 + + def preview_question(self, question): + # ["id", "text", "tips", "type", "mandatory", "maxChar", "answerList"] + mandatory = ("mandatory" in question and question["mandatory"]) + mandatory_sym = " *" + if not mandatory: + mandatory_sym = "" + print("\t - %s%s" % (question["text"], mandatory_sym)) + if "tips" in question and question["tips"]: + print("\t (%s)" % question["tips"]) + if "answerList" in question: + for answer in question["answerList"]: + print("\t\t - %s" % answer) + return 0 def parse_args(): parser = argparse.ArgumentParser(description='Validate Bug Report File.') parser.add_argument('--file', required=True, help='JSON file to validate.') + parser.add_argument('--preview', action='store_true', help='Output a preview of the parsed file.') return parser.parse_args() @@ -196,6 +223,8 @@ def main(): print("Validation FAILED for %s. Error: %s" %(report.filepath, report.error)) exit(1) print("Validation SUCCEED for %s." % report.filepath) + if args.preview: + report.preview() exit(0)