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 logging
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import subprocess
|
||||||
from typing import Union, Dict, Any, List, Tuple
|
from typing import Union, Dict, Any, List, Tuple
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
|
|
||||||
import git
|
import git
|
||||||
from git.repo import Repo
|
from git.repo import Repo
|
||||||
|
from jinja2 import BaseLoader, Environment
|
||||||
import requests
|
import requests
|
||||||
import sarge
|
import sarge
|
||||||
|
|
||||||
|
@ -23,10 +25,30 @@ OBS_URL = "https://api.opensuse.org/trigger/runservice"
|
||||||
MATRIX_COMMANDER = "/home/mocker/local-venv/bin/matrix-commander.py"
|
MATRIX_COMMANDER = "/home/mocker/local-venv/bin/matrix-commander.py"
|
||||||
REPO_TEMPLATE = "https://invent.kde.org/{}"
|
REPO_TEMPLATE = "https://invent.kde.org/{}"
|
||||||
|
|
||||||
MESSAGE_TEMPLATE = f"""
|
MESSAGE_TEMPLATE = """
|
||||||
## OBS package update report
|
## 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:
|
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()
|
errors = list()
|
||||||
|
import pdb
|
||||||
for repo, update in update_data.items():
|
pdb.set_trace()
|
||||||
heading = f"### {repo}\n"
|
message = template.render(repositories=update_data, errors=errors)
|
||||||
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)
|
|
||||||
|
|
||||||
cmd = [MATRIX_COMMANDER, "--markdown", "-m", message]
|
cmd = [MATRIX_COMMANDER, "--markdown", "-m", message]
|
||||||
logging.debug("Sending Matrix notification")
|
logging.debug("Sending Matrix notification")
|
||||||
sarge.run(cmd)
|
sarge.run(cmd, stdout=subprocess.DEVNULL)
|
||||||
|
|
||||||
|
|
||||||
def commit_changes(cache_file: str, repo_home: str) -> None:
|
def commit_changes(cache_file: str, repo_home: str) -> None:
|
||||||
|
|
Loading…
Add table
Reference in a new issue