Skip to content

Commit

Permalink
add-timestamp-to-html-report
Browse files Browse the repository at this point in the history
  • Loading branch information
SurajBDeore committed Jan 10, 2025
1 parent fc633e9 commit aeb6733
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 454 deletions.
2 changes: 1 addition & 1 deletion lobster/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def to_html(self):

return '<a href="%s/blob/%s/%s" target="_blank">%s</a>' % (
self.gh_root,
self.commit,
self.exec_commit_id,
file_ref,
self.to_string())

Expand Down
37 changes: 35 additions & 2 deletions lobster/tools/core/html_report/html_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import subprocess
import hashlib
import tempfile
from datetime import datetime, timezone

from lobster.html import htmldoc, assets
from lobster.report import Report
Expand Down Expand Up @@ -189,6 +190,23 @@ def create_item_coverage(doc, report):
doc.add_line("</table>")


def get_commit_timestamp_utc(commit_hash):
try:
result = subprocess.run(
['git', 'show', '-s', '--format=%ct', commit_hash],
capture_output=True,
text=True,
check=True
)
epoch_time = int(result.stdout.strip())
# Convert to UTC datetime
utc_time = datetime.fromtimestamp(epoch_time, tz=timezone.utc)
return utc_time
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
return None


def write_item_box_begin(doc, item):
assert isinstance(doc, htmldoc.Document)
assert isinstance(item, Item)
Expand All @@ -209,6 +227,13 @@ def write_item_box_begin(doc, item):
doc.add_line('<div class="attribute">Source: ')
doc.add_line(assets.SVG_EXTERNAL_LINK)
doc.add_line(item.location.to_html())
# commit_hash = item.location.exec_commit_id
# doc.add_line(
# f'<div class="attribute">'
# f'Build Reference: <strong>{commit_hash}</strong> | '
# f'Timestamp: {get_commit_timestamp_utc(commit_hash)}'
# f'</div>'
# )
doc.add_line("</div>")


Expand Down Expand Up @@ -252,8 +277,16 @@ def write_item_tracing(doc, report, item):
doc.add_line("</div>")


def write_item_box_end(doc):
def write_item_box_end(doc, item):
assert isinstance(doc, htmldoc.Document)

commit_hash = item.location.exec_commit_id
doc.add_line(
f'<div class="attribute">'
f'Build Reference: <strong>{commit_hash}</strong> | '
f'Timestamp: {get_commit_timestamp_utc(commit_hash)}'
f'</div>'
)
doc.add_line("</div>")
doc.add_line('<!-- end item -->')

Expand Down Expand Up @@ -480,7 +513,7 @@ def write_html(fd, report, dot, high_contrast):
html.escape(item.text).replace("\n", "<br>"))
doc.add_line('</div>')
write_item_tracing(doc, report, item)
write_item_box_end(doc)
write_item_box_end(doc, item)
else:
doc.add_line("No items recorded at this level.")
# Closing tag for id #search-sec-id
Expand Down
Loading

0 comments on commit aeb6733

Please sign in to comment.