leapp/0001-add-external-links-to-the-leapp-report.txt.patch
Petr Stodulka e8307f6fb0 RHEL 8.10: CTC2 candidate - 0
- Add external links to the text version of the generated report file
- Resolves: RHEL-21451
2024-01-12 21:06:40 +01:00

78 lines
3.6 KiB
Diff

From ea71f9b27a7c969d8023099cf151564dd8e5aae3 Mon Sep 17 00:00:00 2001
From: PeterMocary <petermocary@gmail.com>
Date: Wed, 6 Sep 2023 15:31:17 +0200
Subject: [PATCH 1/5] add external links to the leapp-report.txt
---
leapp/utils/report.py | 40 +++++++++++++++++++++++++++++-----------
1 file changed, 29 insertions(+), 11 deletions(-)
diff --git a/leapp/utils/report.py b/leapp/utils/report.py
index 2db0e55..bbf8f28 100644
--- a/leapp/utils/report.py
+++ b/leapp/utils/report.py
@@ -8,6 +8,7 @@ import six
from leapp.reporting import (
_DEPRECATION_FLAGS,
_UPCOMING_DEPRECATION_FLAGS,
+ ExternalLink,
Groups,
Remediation,
Severity,
@@ -115,6 +116,31 @@ def importance(message):
return SEVERITY_LEVELS.get(message['severity'], 99)
+def _report_detail_to_string(report_detail):
+ detail = u''
+ external_links = report_detail[ExternalLink.name] if ExternalLink.name in report_detail.keys() else None
+ remediation = Remediation.from_dict(report_detail)
+
+ if external_links:
+ external_links_text = u'Related links:'
+ for link in external_links:
+ external_links_text += u'\n - {}: {}'.format(link['title'], link['url'])
+ detail += external_links_text
+
+ if remediation:
+ # NOTE(ivasilev) Decoding is necessary in case of python2 as remediation is an encoded string,
+ # while io.open expects "true text" input. For python3 repr will return proper py3 str, no
+ # decoding will be needed.
+ # This hassle and clumsiness makes me sad, so suggestions are welcome.
+ remediation_text = '\nRemediation: {}\n'.format(remediation)
+ if isinstance(remediation_text, six.binary_type):
+ # This will be true for py2 where repr returns an encoded string
+ remediation_text = remediation_text.decode('utf-8')
+ detail += remediation_text
+
+ return detail
+
+
def generate_report_file(messages_to_report, context, path, report_schema='1.1.0'):
# NOTE(ivasilev) Int conversion should not break as only specific formats of report_schema versions are allowed
report_schema_tuple = tuple(int(x) for x in report_schema.split('.'))
@@ -130,17 +156,9 @@ def generate_report_file(messages_to_report, context, path, report_schema='1.1.0
f.write(u'Risk Factor: {} {}\n'.format(message['severity'], flag))
f.write(u'Title: {}\n'.format(message['title']))
f.write(u'Summary: {}\n'.format(message['summary']))
- remediation = Remediation.from_dict(message.get('detail', {}))
- if remediation:
- # NOTE(ivasilev) Decoding is necessary in case of python2 as remediation is an encoded string,
- # while io.open expects "true text" input. For python3 repr will return proper py3 str, no
- # decoding will be needed.
- # This hassle and clumsiness makes me sad, so suggestions are welcome.
- remediation_text = 'Remediation: {}\n'.format(remediation)
- if isinstance(remediation_text, six.binary_type):
- # This will be true for py2 where repr returns an encoded string
- remediation_text = remediation_text.decode('utf-8')
- f.write(remediation_text)
+ report_detail = message.get('detail', {})
+ detail = _report_detail_to_string(report_detail)
+ f.write(detail)
if report_schema_tuple > (1, 0, 0):
# report-schema 1.0.0 doesn't have a stable report key
f.write(u'Key: {}\n'.format(message['key']))
--
2.43.0