mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-09-29 18:16:43 +00:00
fix: add icons to update notification details
This commit is contained in:
@@ -2221,6 +2221,7 @@ FIELD_EMOJI = {
|
||||
'kernel_count': '\u2699\uFE0F',
|
||||
'important_list': '\U0001F4CB', # clipboard
|
||||
'current_version': '\U0001F4E6', # package \u2014 installed version
|
||||
'new_version': '\U0001F195', # NEW button \u2014 offered version
|
||||
'latest_version': '\U0001F195', # NEW button \u2014 upstream version
|
||||
'kernel': '\u2699\uFE0F', # gear \u2014 running kernel
|
||||
'menu_label': '\U0001F4D6', # open book \u2014 menu navigation hint
|
||||
@@ -2394,12 +2395,41 @@ def enrich_with_emojis(event_type: str, title: str, body: str,
|
||||
# Build enriched body: prepend field emojis to recognizable lines
|
||||
lines = preprocessed.split('\n')
|
||||
enriched_lines = []
|
||||
app_update_is_single = (
|
||||
not isinstance(data.get('updates'), list) or len(data['updates']) < 2
|
||||
)
|
||||
app_update_lead_added = False
|
||||
app_update_version = None
|
||||
if event_type == 'app_update_available' and app_update_is_single:
|
||||
app_update_version = f"{data.get('installed', '')} → {data.get('latest', '')}".strip()
|
||||
|
||||
for line in lines:
|
||||
stripped = line.strip()
|
||||
if not stripped:
|
||||
enriched_lines.append(line)
|
||||
continue
|
||||
|
||||
# App-update notifications deliberately use a compact, prose-like
|
||||
# template rather than field labels. Keep their two structured lines
|
||||
# as readable as other update notifications without depending on a
|
||||
# translated phrase to recognize them.
|
||||
if event_type == 'app_update_available' and app_update_is_single:
|
||||
if not app_update_lead_added:
|
||||
enriched_lines.append(f'📦 {stripped}')
|
||||
app_update_lead_added = True
|
||||
continue
|
||||
if app_update_version and stripped == app_update_version:
|
||||
enriched_lines.append(f'🔄 {stripped}')
|
||||
continue
|
||||
|
||||
# The Proxmox VE detector emits the manager version as a concise,
|
||||
# structured technical detail outside the localized template fields.
|
||||
# Mark only that known detail; arbitrary detector text remains intact.
|
||||
if event_type == 'pve_update' and re.match(
|
||||
r'^pve-manager\s+\S+\s+(?:→|->)\s+\S+$', stripped,
|
||||
):
|
||||
enriched_lines.append(f'🔧 {stripped}')
|
||||
continue
|
||||
|
||||
# First, check health-specific patterns
|
||||
health_enriched = False
|
||||
|
||||
@@ -221,6 +221,47 @@ class RuntimeCatalogTests(unittest.TestCase):
|
||||
self.assertIn("📦 Kontajner repopulse-labs-test (CT 210) má 1 aktualizácií Docker:", enriched_body)
|
||||
self.assertIn("🐳 • Docker Engine: 29.8.0 → 29.8.1", enriched_body)
|
||||
|
||||
def test_app_and_proxmox_update_body_icons_cover_versions(self):
|
||||
app_data = {
|
||||
"hostname": "HomeLAB_1", "app_name": "Uptime Kuma", "vmid": "108",
|
||||
"ct_name": "uptime-kuma", "installed": "2.5.4", "latest": "2.5.5",
|
||||
"severity": "INFO", "_notification_language": "sk",
|
||||
}
|
||||
app = notification_templates.render_template(
|
||||
"app_update_available", app_data, language="sk",
|
||||
)
|
||||
_title, app_body = notification_templates.enrich_with_emojis(
|
||||
"app_update_available", app["title"], app["body"], app_data,
|
||||
)
|
||||
self.assertIn("📦 Aplikácia Uptime Kuma na CT 108 (uptime-kuma) má novú verziu:", app_body)
|
||||
self.assertIn("🔄 2.5.4 → 2.5.5", app_body)
|
||||
|
||||
pve_data = {
|
||||
"hostname": "HomeLAB_1", "current_version": "9.2.18",
|
||||
"new_version": "9.2.20", "details": "pve-manager 9.2.18 → 9.2.20",
|
||||
"severity": "INFO", "_notification_language": "sk",
|
||||
}
|
||||
pve = notification_templates.render_template("pve_update", pve_data, language="sk")
|
||||
_title, pve_body = notification_templates.enrich_with_emojis(
|
||||
"pve_update", pve["title"], pve["body"], pve_data,
|
||||
)
|
||||
self.assertIn("📦 Aktuálna: 9.2.18", pve_body)
|
||||
self.assertIn("🆕 Nová: 9.2.20", pve_body)
|
||||
self.assertIn("🔧 pve-manager 9.2.18 → 9.2.20", pve_body)
|
||||
|
||||
for language in self.RUNTIME_LANGUAGES:
|
||||
locale_data = {**pve_data, "_notification_language": language}
|
||||
locale = notification_templates.render_template(
|
||||
"pve_update", locale_data, language=language,
|
||||
)
|
||||
_title, locale_body = notification_templates.enrich_with_emojis(
|
||||
"pve_update", locale["title"], locale["body"], locale_data,
|
||||
)
|
||||
label = notification_templates._localized_template_labels(
|
||||
"pve_update", language,
|
||||
)["new_version"][0]
|
||||
self.assertIn(f"🆕 {label}: 9.2.20", locale_body, language)
|
||||
|
||||
def test_missing_slovak_key_falls_back_to_english(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
|
||||
Reference in New Issue
Block a user