diff --git a/config/reports/test-report.jinja2 b/config/reports/test-report.jinja2 index e897bbfc3..78c82a226 100644 --- a/config/reports/test-report.jinja2 +++ b/config/reports/test-report.jinja2 @@ -9,7 +9,12 @@ Tree: {{ root.revision.tree }} Branch: {{ root.revision.branch }} Describe: {{ root.revision.describe }} URL: {{ root.revision.url }} -SHA1: {{ root.revision.commit }} +Commit: {{ root.revision.commit }} +{%- if patch %} +Patch Title: {{ patch["title"] }} +Patch URL: {{ patch["url"] }} +Patch Hash: {{ patch["hash"] }} +{%- endif %} {%- if groups.items() %} {{ '%-15s %s %-8s %s %-8s %s %-8s'|format( diff --git a/src/base.py b/src/base.py index 7ad1edf6a..4e3c7119a 100644 --- a/src/base.py +++ b/src/base.py @@ -24,6 +24,7 @@ def __init__(self, configs, args, name): api_token = os.getenv('KCI_API_TOKEN') self._api = kernelci.api.get_api(self._api_config, api_token) self._api_helper = APIHelper(self._api) + self._args = args @property def log(self): @@ -65,7 +66,7 @@ def run(self, args=None): context = None try: - context = self._setup(args) + context = self._setup(args or self._args) status = self._run(context) except KeyboardInterrupt: self.log.info("Stopping.") diff --git a/src/test_report.py b/src/test_report.py index c38de2c84..8d1868c25 100755 --- a/src/test_report.py +++ b/src/test_report.py @@ -83,28 +83,42 @@ def _get_results_data(self, root_node): 'groups': groups, } + def _get_patch_data(self, root_node): + root_node_data = root_node.get('data') + if not root_node_data: + return {} + + if patchwork_metadata := root_node_data.get('patchwork'): + if patchwork_metadata["version"] == 1: + patch = patchwork_metadata['payload']['patches'][0] + return { + 'title': "foobar", + 'hash': patch['hash'], + 'url': patch['web_url'], + } + + return {} + def _get_report(self, root_node): template_env = jinja2.Environment( loader=jinja2.FileSystemLoader("./config/reports/") ) template = template_env.get_template("test-report.jinja2") revision = root_node['revision'] + + patch_metadata = self._get_patch_data(root_node) + base_subject= f"[STAGING] {revision['tree']}/{revision['branch']} {revision['describe']}" if root_node['result'] == 'incomplete': - subject = (f"\ -[STAGING] {revision['tree']}/{revision['branch']} {revision['describe']}: \ -Failed to create source tarball for {root_node['name']}") + subject = (f"{base_subject}: Failed to create source tarball for {root_node['name']}") content = template.render( - subject=subject, root=root_node, groups={} + subject=subject, root=root_node, groups={}, patch=patch_metadata, ) else: results = self._get_results_data(root_node) stats = results['stats'] - groups = results['groups'] - subject = (f"\ -[STAGING] {revision['tree']}/{revision['branch']} {revision['describe']}: \ -{stats['total']} runs {stats['failures']} failures") + subject = (f"{base_subject}: {stats['total']} runs {stats['failures']} failures") content = template.render( - subject=subject, root=root_node, groups=groups + subject=subject, root=root_node, groups=results['groups'], patch=patch_metadata, ) return content, subject