Skip to content

Commit

Permalink
reporters: report jobs separately (#721)
Browse files Browse the repository at this point in the history
Adapted from #305.
  • Loading branch information
ryneeverett committed Dec 18, 2022
1 parent 2faaae7 commit 5385365
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@ The format mostly follows [Keep a Changelog](http://keepachangelog.com/en/1.0.0/
- `browser` job: Add support for specifying `useragent` (#700, by Francesco Versaci)
- Document how to ignore whitespace changes (PR#707, by Paulo Magalhaes)
- `shell` reporter: Call a script or program when chanegs are detected (fixes #650)
- New `separate` configuration option for reporters to split reports into one-per-job (contributed by Ryne Everett)

### Changed

Expand Down
4 changes: 4 additions & 0 deletions docs/source/configuration.rst
Expand Up @@ -88,6 +88,7 @@ output in color, as well as HTML e-mail using ``sendmail``:
line_length: 75
html:
diff: unified
separate: true
email:
enabled: true
method: sendmail
Expand All @@ -109,6 +110,9 @@ apply to all reporters that derive from that reporter (for example,
the ``stdout`` reporter uses ``text``, while the ``email`` reporter
with ``html: true`` set uses ``html``).

Setting ``separate: true`` will cause the reporter to send a report for
each job rather than a combined report for all jobs.

.. _job_defaults:

Job Defaults
Expand Down
28 changes: 23 additions & 5 deletions lib/urlwatch/reporters.py
Expand Up @@ -108,6 +108,10 @@ def convert(self, othercls):

return othercls(self.report, config, self.job_states, self.duration)

@classmethod
def get_base_config(cls, report):
return report.config['report'][cls.mro()[-3].__kind__]

@classmethod
def reporter_documentation(cls):
result = []
Expand All @@ -134,7 +138,12 @@ def submit_all(cls, report, job_states, duration):
if cfg['enabled']:
any_enabled = True
logger.info('Submitting with %s (%r)', name, subclass)
subclass(report, cfg, job_states, duration).submit()
base_config = subclass.get_base_config(report)
if base_config.get('separate', False):
for job_state in job_states:
subclass(report, cfg, [job_state], duration).submit()
else:
subclass(report, cfg, job_states, duration).submit()

if not any_enabled:
logger.warning('No reporters enabled.')
Expand All @@ -156,11 +165,14 @@ def format(self, *args, **kwargs):


class HtmlReporter(ReporterBase):

__kind__ = 'html'

def submit(self):
yield from (str(part) for part in self._parts())

def _parts(self):
cfg = self.report.config['report']['html']
cfg = self.get_base_config(self.report)

yield SafeHtml("""<!DOCTYPE html>
<html><head>
Expand Down Expand Up @@ -262,8 +274,11 @@ def _format_content(self, job_state, difftype):


class TextReporter(ReporterBase):

__kind__ = 'text'

def submit(self):
cfg = self.report.config['report']['text']
cfg = self.get_base_config(self.report)
line_length = cfg['line_length']
show_details = cfg['details']
show_footer = cfg['footer']
Expand Down Expand Up @@ -370,7 +385,7 @@ def _get_print(self):
def submit(self):
print = self._get_print()

cfg = self.report.config['report']['text']
cfg = self.get_base_config(self.report)
line_length = cfg['line_length']

separators = (line_length * '=', line_length * '-', '-- ') if line_length else ()
Expand Down Expand Up @@ -763,8 +778,11 @@ def submit_to_discord(self, webhook_url, text):


class MarkdownReporter(ReporterBase):

__kind__ = 'markdown'

def submit(self, max_length=None):
cfg = self.report.config['report']['markdown']
cfg = self.get_base_config(self.report)
show_details = cfg['details']
show_footer = cfg['footer']

Expand Down
3 changes: 3 additions & 0 deletions lib/urlwatch/storage.py
Expand Up @@ -75,16 +75,19 @@
'details': True,
'footer': True,
'minimal': False,
'separate': False,
},

'markdown': {
'details': True,
'footer': True,
'minimal': False,
'separate': False,
},

'html': {
'diff': 'unified', # "unified" or "table"
'separate': False,
},

'stdout': {
Expand Down

0 comments on commit 5385365

Please sign in to comment.