From 40543fb188825ab30eb5b7a6f512ff825f0df30f Mon Sep 17 00:00:00 2001 From: Major Hayden Date: Mon, 21 Oct 2024 07:55:52 -0500 Subject: [PATCH] Add affects_rhel() check --- tests/test_errata.py | 28 ++++++++++++++++++++++++++++ textprep/errata.py | 7 +++++++ 2 files changed, 35 insertions(+) diff --git a/tests/test_errata.py b/tests/test_errata.py index 98ab236..c62c0a3 100644 --- a/tests/test_errata.py +++ b/tests/test_errata.py @@ -4,6 +4,7 @@ from langchain_core.documents import Document from textprep.errata import ( + affects_rhel, clean_bugzillas, clean_description, clean_solution, @@ -170,3 +171,30 @@ def test_parse_functional(errata_doc_path): - BZ 2044863 found at https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=2044863""" assert result == expected + + +def test_affects_rhel(tmp_path): + content = """+++ +portal_product_names=["Red Hat Enterprise Linux Server - Extended Life Cycle Support","Red Hat Enterprise Linux for x86_64 - Update Services for SAP Solutions","Red Hat Enterprise Linux for x86_64 - Extended Update Support","Red Hat Enterprise Linux Desktop","Red Hat Enterprise Linux Server - AUS","Red Hat Enterprise Linux EUS Compute Node","Red Hat Enterprise Linux Server - TUS","Red Hat Enterprise Linux Server","Red Hat Enterprise Linux Workstation","Red Hat Enterprise Linux Server from RHUI","Red Hat Enterprise Linux for Scientific Computing"] ++++ + +# Heading + +Content. +""" + d = tmp_path / "sub" + d.mkdir() + p = d / "errata.md" + p.write_text(content, encoding="utf-8") + assert affects_rhel(p) + + content = """+++ +portal_product_names=["Red Hat OpenShift Enterprise Infrastructure","Red Hat OpenShift Enterprise Application Node","Red Hat OpenShift Enterprise JBoss EAP add-on","Red Hat OpenShift Enterprise Client Tools"] ++++ + +# Heading + +Content. +""" + p.write_text(content, encoding="utf-8") + assert not affects_rhel(p) diff --git a/textprep/errata.py b/textprep/errata.py index 92d597d..3fb2ea7 100644 --- a/textprep/errata.py +++ b/textprep/errata.py @@ -103,6 +103,13 @@ def get_affected_products(product_keys: list, product_detail: list) -> str: return "This errata affects the following products:\n\n" + product_text +def affects_rhel(path: str) -> bool: + """Check if the errata affects RHEL.""" + errata_doc = load_errata(path) + affected_products = errata_doc["frontmatter"]["portal_product_names"] + return any("Red Hat Enterprise Linux" in x for x in affected_products) + + def parse(path: str) -> str: """Parse an errata document into a clean format.""" errata_doc = load_errata(path)