Use jinja2 to render the whole thing
This commit is contained in:
parent
0201261b41
commit
a6516e7422
1 changed files with 29 additions and 25 deletions
|
@ -9,11 +9,13 @@ from functools import lru_cache
|
|||
import logging
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
from typing import Union, Dict, Any, List, Tuple
|
||||
from urllib.parse import quote
|
||||
|
||||
import git
|
||||
from git.repo import Repo
|
||||
from jinja2 import BaseLoader, Environment
|
||||
import requests
|
||||
import sarge
|
||||
|
||||
|
@ -23,10 +25,30 @@ OBS_URL = "https://api.opensuse.org/trigger/runservice"
|
|||
MATRIX_COMMANDER = "/home/mocker/local-venv/bin/matrix-commander.py"
|
||||
REPO_TEMPLATE = "https://invent.kde.org/{}"
|
||||
|
||||
MESSAGE_TEMPLATE = f"""
|
||||
MESSAGE_TEMPLATE = """
|
||||
## OBS package update report
|
||||
|
||||
Updated at {date.today().strftime('%Y-%m-%d')}
|
||||
Updated at {{ date.today().strftime('%Y-%m-%d') }}
|
||||
|
||||
{% for repository, update in repositories.items() %}
|
||||
|
||||
### {{ repository }}
|
||||
|
||||
Updated {{ update | len }} packages.
|
||||
|
||||
{% for package, remote, state in update %}
|
||||
{% if state != "error" %}
|
||||
* {{ package }} [{{ state[0:8] }}(https://commits.kde.org/{{ remote }}/{{ state }}
|
||||
{% else %}
|
||||
{ errors.append(package) }
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
## Packages with errors
|
||||
|
||||
{% for error in errors %}
|
||||
* {{ error }}
|
||||
{% endfor %}
|
||||
|
||||
"""
|
||||
|
||||
|
@ -156,34 +178,16 @@ class RepoUpdater:
|
|||
|
||||
def notify_matrix(update_data: Dict[str, List[Tuple[str, str]]]) -> None:
|
||||
|
||||
structure = [MESSAGE_TEMPLATE]
|
||||
template = Environment(loader=BaseLoader).from_string(MESSAGE_TEMPLATE)
|
||||
|
||||
structure.append("Updated packages:\n")
|
||||
errors = list()
|
||||
|
||||
for repo, update in update_data.items():
|
||||
heading = f"### {repo}\n"
|
||||
structure.append(heading)
|
||||
structure.append(f"Updated {len(update)} packages.\n")
|
||||
|
||||
for package, remote, state in update:
|
||||
|
||||
if state != "error":
|
||||
row = (f"* {package} - [{state[0:8]}]"
|
||||
f"(https://commits.kde.org/{remote}/{state})")
|
||||
structure.append(row)
|
||||
else:
|
||||
errors.append(package)
|
||||
|
||||
structure.append("\n#### Packages with errors")
|
||||
for errored in errors:
|
||||
structure.append(f"* {errored}")
|
||||
|
||||
message = "\n".join(structure)
|
||||
import pdb
|
||||
pdb.set_trace()
|
||||
message = template.render(repositories=update_data, errors=errors)
|
||||
|
||||
cmd = [MATRIX_COMMANDER, "--markdown", "-m", message]
|
||||
logging.debug("Sending Matrix notification")
|
||||
sarge.run(cmd)
|
||||
sarge.run(cmd, stdout=subprocess.DEVNULL)
|
||||
|
||||
|
||||
def commit_changes(cache_file: str, repo_home: str) -> None:
|
||||
|
|
Loading…
Add table
Reference in a new issue