Source code for sw_metadata_bot.check_parsing
"""Shared parsing helpers for RSMetacheck check identifiers."""
RSMETACHECK_CATALOG_MARKER = "rsmetacheck/catalog"
[docs]
def get_check_catalog_id(check: dict) -> str:
"""Return full RSMetacheck catalog ID URL for a check when available.
Preferred source is the new schema key ``assessesIndicator.@id`` when it
points to the RSMetacheck catalog. For backward compatibility, this falls
back to the legacy ``pitfall`` key.
"""
indicator_id = str(check.get("assessesIndicator", {}).get("@id", ""))
if indicator_id and RSMETACHECK_CATALOG_MARKER in indicator_id:
return indicator_id
return str(check.get("pitfall", ""))
[docs]
def get_short_check_code(check: dict) -> str:
"""Return short check code such as P001 or W004."""
full_id = get_check_catalog_id(check)
return full_id.split("#")[-1] if full_id else ""
[docs]
def is_check_reported(check: dict) -> bool:
"""Return True only when a check is explicitly reported by metacheck.
Verbose metacheck output marks each evaluated check with an ``output`` key.
Only values representing true are considered reported findings.
"""
output = check.get("output")
return str(output).lower() == "true"