Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] src/test_report.py: Include patchwork patch metadata into test report #297

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion config/reports/test-report.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.")
Expand Down
32 changes: 23 additions & 9 deletions src/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down