forked from spearbit-audits/report-generator-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenerate_report.py
76 lines (62 loc) · 3.88 KB
/
generate_report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import re
import subprocess
import scripts.helpers as helpers
import scripts.linter as linter
from scripts.fetch_issues import fetch_issues
# Get issues
fetch_issues()
# Get static info from conf files
summary_data = helpers.get_summary_information()
severity_count_data = helpers.get_severity_counts()
# Project name taken from summary_information.conf, inserted in Title section -> title.tex file
REPLACE_TITLE = [["__PLACEHOLDER__PROJECT_NAME", summary_data['project_name']]]
source_org, repo_name = re.search(r'/(?P<org_name>[^/]+)/([^/.]+)(?:\.git)?$', summary_data['project_github']).groups()
# Information from summary_information.conf, inserted in Summary section -> summary.tex file
REPLACE_SUMMARY = [["__PLACEHOLDER__REVIEW_LENGTH", str(helpers.calculate_period(summary_data['review_timeline']))],
["__PLACEHOLDER__TEAM_NAME", summary_data['team_name']],
["__PLACEHOLDER__TEAM_WEBSITE", summary_data['team_website']],
["__PLACEHOLDER__PROJECT_NAME", summary_data['project_name']],
["__PLACEHOLDER__REPO_LINK", summary_data['project_github']],
["__PLACEHOLDER__REPO_NAME", repo_name],
["__PLACEHOLDER__COMMIT_HASH_LINK", re.sub(r'(\.git)?$', '', summary_data['project_github']) + "/blob/" + summary_data['commit_hash']],
["__PLACEHOLDER__COMMIT_HASH", summary_data['commit_hash']],
["__PLACEHOLDER__AUDIT_TIMELINE", summary_data['review_timeline']],
["__PLACEHOLDER__AUDIT_METHODS", summary_data['review_methods']]]
# Severities count taken from severity_count.conf, inserted in Total Issues section -> summary.tex file
REPLACE_SEVERITIES = [["__PLACEHOLDER__ISSUE_CRITICAL_COUNT", severity_count_data['critical']],
["__PLACEHOLDER__ISSUE_HIGH_COUNT", severity_count_data['high']],
["__PLACEHOLDER__ISSUE_MEDIUM_COUNT", severity_count_data['medium']],
["__PLACEHOLDER__ISSUE_LOW_COUNT", severity_count_data['low']],
["__PLACEHOLDER__ISSUE_INFORMATIONAL_COUNT" ,severity_count_data['informational']],
["__PLACEHOLDER__ISSUE_GAS_OPTIMIZATION_COUNT", severity_count_data['gas_optimization']],
["__PLACEHOLDER__ISSUE_TOTAL_COUNT", severity_count_data['total']]]
# Lint the report.md
print("Linting the report.md file ...")
report = helpers.get_file_contents(helpers.OUTPUT_REPORT)
report = linter.lint(report, summary_data['team_name'], source_org, "ChainAccelOrg")
helpers.save_file_contents(helpers.OUTPUT_REPORT, report)
print(f"Done.\n")
# Convert all .md to .tex and save to working dir
print("Converting Markdown files to LaTeX ...")
with open("./working/conversion.log", "w") as log:
subprocess.call("./scripts/convert.sh", stdout=log, stderr=log)
print(f"Done.\n")
# Process for title.tex: Get the file and replace placeholders.
print("Replacing information in title.tex ...")
title = helpers.get_file_contents("./templates/title.tex")
title = helpers.replace_in_file_content(title, REPLACE_TITLE)
helpers.save_file_contents("./working/title.tex", title)
print(f"Done.\n")
# Process for summary.tex: Get the file and replace placeholders.
print("Replacing information in summary.tex ...")
summary = helpers.get_file_contents("./templates/summary.tex")
summary = helpers.replace_in_file_content(summary, REPLACE_SUMMARY)
summary = helpers.replace_in_file_content(summary, REPLACE_SEVERITIES)
helpers.save_file_contents("./working/summary.tex", summary)
print(f"Done.\n")
# Generate PDF in output folder
print("Generating report PDF file ...")
with open("./working/generation.log", "w") as log:
subprocess.call("./scripts/generate.sh", stdout=log, stderr=log)
print(f"\nAll tasks completed. Report should be in the 'output' folder.")
print(f"If it wasn't generated, check 'working/conversion.log' and 'working/generation.log'.")