diff --git a/README.md b/README.md index c7561b0e..dd8dd3aa 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Wrapper for managing custom repository inspired by [repo-scripts](https://github * Multi-architecture support. * VCS packages support. * Sign support with gpg (repository, package, per package settings). -* Synchronization to remote services (rsync, s3 and github) and report generation (html). +* Synchronization to remote services (rsync, s3 and github) and report generation (email, html, telegram). * Dependency manager. * Ability to patch AUR packages and even create package from local PKGBUILDs. * Repository status interface with optional authorization and control options: diff --git a/docs/configuration.md b/docs/configuration.md index e5575a9e..d3af5ed0 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -124,6 +124,7 @@ Section name must be either `telegram` (plus optional architecture name, e.g. `t * `homepage` - link to homepage, string, optional. * `link_path` - prefix for HTML links, string, required. * `template_path` - path to Jinja2 template, string, required. +* `template_type` - `parse_mode` to be passed to telegram API, one of `MarkdownV2`, `HTML`, `Markdown`, string, optional, default `HTML`. ## `upload` group diff --git a/package/share/ahriman/settings/ahriman.ini b/package/share/ahriman/settings/ahriman.ini index aa0991d8..4805f947 100644 --- a/package/share/ahriman/settings/ahriman.ini +++ b/package/share/ahriman/settings/ahriman.ini @@ -46,7 +46,7 @@ ssl = disabled template_path = /usr/share/ahriman/templates/repo-index.jinja2 [telegram] -template_path = /usr/share/ahriman/templates/telegram.jinja2 +template_path = /usr/share/ahriman/templates/telegram-index.jinja2 [upload] target = diff --git a/package/share/ahriman/templates/telegram-index.jinja2 b/package/share/ahriman/templates/telegram-index.jinja2 index 5c378745..052e30e1 100644 --- a/package/share/ahriman/templates/telegram-index.jinja2 +++ b/package/share/ahriman/templates/telegram-index.jinja2 @@ -1,10 +1,5 @@ -{#simplified version of full report, now in markdown#} -## {{ repository }} update - +{#simplified version of full report#} +{{ repository }} update {% for package in packages %} - * [{{ package.name }}]({{ link_path }}/{{ package.filename }}) {{ package.version }} at {{ package.build_date }} -{% endfor %} - -{% if homepage is not none %} -[Repository]({{ homepage }}) -{% endif %} +{{ package.name }} {{ package.version }} at {{ package.build_date }} +{% endfor %} \ No newline at end of file diff --git a/setup.py b/setup.py index 6d5620fa..a8e428e8 100644 --- a/setup.py +++ b/setup.py @@ -67,6 +67,7 @@ setup( "package/share/ahriman/templates/build-status.jinja2", "package/share/ahriman/templates/email-index.jinja2", "package/share/ahriman/templates/repo-index.jinja2", + "package/share/ahriman/templates/telegram-index.jinja2", ]), ("share/ahriman/templates/build-status", [ "package/share/ahriman/templates/build-status/login-modal.jinja2", diff --git a/src/ahriman/core/report/telegram.py b/src/ahriman/core/report/telegram.py index 5db71ae3..ff301d6e 100644 --- a/src/ahriman/core/report/telegram.py +++ b/src/ahriman/core/report/telegram.py @@ -38,6 +38,7 @@ class Telegram(Report, JinjaTemplate): :ivar api_key: bot api key :ivar chat_id: chat id to post message, either string with @ or integer :ivar template_path: path to template for built packages + :ivar template_type: template message type to be used in parse mode, one of MarkdownV2, HTML, Markdown """ TELEGRAM_API_URL = "https://api.telegram.org" @@ -56,6 +57,7 @@ class Telegram(Report, JinjaTemplate): self.api_key = configuration.get(section, "api_key") self.chat_id = configuration.get(section, "chat_id") self.template_path = configuration.getpath(section, "template_path") + self.template_type = configuration.get(section, "template_type", fallback="HTML") def _send(self, text: str) -> None: """ @@ -65,7 +67,7 @@ class Telegram(Report, JinjaTemplate): try: response = requests.post( f"{self.TELEGRAM_API_URL}/bot{self.api_key}/sendMessage", - data={"chat_id": self.chat_id, "text": text}) + data={"chat_id": self.chat_id, "text": text, "parse_mode": self.template_type}) response.raise_for_status() except requests.HTTPError as e: self.logger.exception("could not perform request: %s", exception_response_text(e)) diff --git a/tests/ahriman/core/build_tools/test_sources.py b/tests/ahriman/core/build_tools/test_sources.py index 49924475..b7f559f2 100644 --- a/tests/ahriman/core/build_tools/test_sources.py +++ b/tests/ahriman/core/build_tools/test_sources.py @@ -87,7 +87,7 @@ def test_fetch_new(mocker: MockerFixture) -> None: local = Path("local") Sources.fetch(local, "remote") check_output_mock.assert_has_calls([ - mock.call("git", "clone", "remote", str(local), exception=None, logger=pytest.helpers.anyvar(int)), + mock.call("git", "clone", "remote", str(local), exception=None, cwd=local, logger=pytest.helpers.anyvar(int)), mock.call("git", "checkout", "--force", Sources._branch, exception=None, cwd=local, logger=pytest.helpers.anyvar(int)), mock.call("git", "reset", "--hard", f"origin/{Sources._branch}", diff --git a/tests/ahriman/core/report/test_telegram.py b/tests/ahriman/core/report/test_telegram.py index 1e0c8259..92645595 100644 --- a/tests/ahriman/core/report/test_telegram.py +++ b/tests/ahriman/core/report/test_telegram.py @@ -20,7 +20,7 @@ def test_send(configuration: Configuration, mocker: MockerFixture) -> None: report._send("a text") request_mock.assert_called_once_with( pytest.helpers.anyvar(str, strict=True), - data={"chat_id": pytest.helpers.anyvar(str, strict=True), "text": "a text"}) + data={"chat_id": pytest.helpers.anyvar(str, strict=True), "text": "a text", "parse_mode": "HTML"}) def test_send_failed(configuration: Configuration, mocker: MockerFixture) -> None: