mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 07:17:17 +00:00
add ability to skip email report generation for empty update list
This commit is contained in:
parent
4d4ddffa8f
commit
01887ec44b
@ -56,6 +56,7 @@ Group name must refer to architecture, e.g. it should be `email:x86_64` for x86_
|
||||
* `homepage` - link to homepage, string, optional.
|
||||
* `host` - SMTP host for sending emails, string, required.
|
||||
* `link_path` - prefix for HTML links, string, required.
|
||||
* `no_empty_report` - skip report generation for empty packages list, boolean, optional, default `yes`.
|
||||
* `password` - SMTP password to authenticate, string, optional.
|
||||
* `port` - SMTP port for sending emails, int, required.
|
||||
* `receivers` - SMTP receiver addresses, space separated list of strings, required.
|
||||
|
@ -26,6 +26,7 @@ target =
|
||||
target =
|
||||
|
||||
[email]
|
||||
no_empty_report = yes
|
||||
template_path = /usr/share/ahriman/repo-index.jinja2
|
||||
ssl = disabled
|
||||
|
||||
|
@ -36,6 +36,7 @@ class Email(Report, JinjaTemplate):
|
||||
"""
|
||||
email report generator
|
||||
:ivar host: SMTP host to connect
|
||||
:ivar no_empty_report: skip empty report generation
|
||||
:ivar password: password to authenticate via SMTP
|
||||
:ivar port: SMTP port to connect
|
||||
:ivar receivers: list of receivers emails
|
||||
@ -55,6 +56,7 @@ class Email(Report, JinjaTemplate):
|
||||
|
||||
# base smtp settings
|
||||
self.host = configuration.get("email", "host")
|
||||
self.no_empty_report = configuration.getboolean("email", "no_empty_report", fallback=True)
|
||||
self.password = configuration.get("email", "password", fallback=None)
|
||||
self.port = configuration.getint("email", "port")
|
||||
self.receivers = configuration.getlist("email", "receivers")
|
||||
@ -96,6 +98,8 @@ class Email(Report, JinjaTemplate):
|
||||
:param packages: list of packages to generate report
|
||||
:param built_packages: list of packages which has just been built
|
||||
"""
|
||||
if self.no_empty_report and not built_packages:
|
||||
return
|
||||
text = self.make_html(built_packages, False)
|
||||
attachments = {"index.html": self.make_html(packages, True)}
|
||||
self._send(text, attachments)
|
||||
|
@ -103,3 +103,27 @@ def test_generate_with_built(configuration: Configuration, package_ahriman: Pack
|
||||
report = Email("x86_64", configuration)
|
||||
report.generate([package_ahriman], [package_ahriman])
|
||||
send_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_generate_no_empty(configuration: Configuration, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must not generate report with built packages if no_empty_report is set
|
||||
"""
|
||||
configuration.set("email", "no_empty_report", "yes")
|
||||
send_mock = mocker.patch("ahriman.core.report.email.Email._send")
|
||||
|
||||
report = Email("x86_64", configuration)
|
||||
report.generate([package_ahriman], [])
|
||||
send_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_generate_no_empty_with_built(configuration: Configuration, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must generate report with built packages if no_empty_report is set
|
||||
"""
|
||||
configuration.set("email", "no_empty_report", "yes")
|
||||
send_mock = mocker.patch("ahriman.core.report.email.Email._send")
|
||||
|
||||
report = Email("x86_64", configuration)
|
||||
report.generate([package_ahriman], [package_ahriman])
|
||||
send_mock.assert_called_once()
|
||||
|
@ -28,6 +28,7 @@ target =
|
||||
[email]
|
||||
host = 0.0.0.0
|
||||
link_path =
|
||||
no_empty_report = no
|
||||
port = 587
|
||||
receivers = mail@example.com
|
||||
sender = mail@example.com
|
||||
|
Loading…
Reference in New Issue
Block a user