Skip to content

Commit 7e38c60

Browse files
committed
Adding a new highlights section in the HTML report
1 parent fefeae2 commit 7e38c60

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/gitxray/include/gx_output.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,23 @@ def _create_html_output(self):
164164
# Load all template files
165165
templates = {
166166
name: open(os.path.join(TEMPLATE_DIR, f"template_{name}.html"), "r", encoding="utf-8").read()
167-
for name in ["main", "repository", "contributor", "non_contributor", "table"]
167+
for name in ["main", "repository", "contributor", "non_contributor", "table", "highlights"]
168168
}
169169

170170
category_sections = ""
171171
contributor_sections = ""
172172
more_sections = ""
173+
highlights_section = ""
173174
repository_sections = ""
174175
repository_sidebar_links = ""
175176
contributor_sidebar_links = ""
176177
category_sidebar_links = ""
177178
more_sidebar_links = ""
179+
highlights_rows = []
178180

179181
for entity, data in self._repositories.items():
180-
sanitized_entity = self.html_data_sanitize_and_process(entity)
182+
sanitized_entity_raw = self.html_data_sanitize_and_process(entity)
183+
sanitized_entity = sanitized_entity_raw.replace("/","_")
181184
r_template = templates['repository'].replace("{{repository_id}}", str(sanitized_entity))
182185

183186
r_tables = []
@@ -186,6 +189,7 @@ def _create_html_output(self):
186189
if not self.debug_enabled() and ("debug" in rtype.lower()): continue
187190
data_rows = []
188191
for line in data[rtype]:
192+
if "warning: " in line.lower(): highlights_rows.append(f"<tr><td>{rtype}</td><td>{self.html_data_sanitize_and_process(line)}</td></tr>")
189193
if self._filters != None and (all(f.lower() not in f'{rtype.lower()} {line.lower()}' for f in self._filters)): continue
190194
data_rows.append(f"<tr><td>{rtype}</td><td>{self.html_data_sanitize_and_process(line)}</td></tr>")
191195

@@ -194,7 +198,7 @@ def _create_html_output(self):
194198
r_tables.append(templates['table'].replace("{{table_rows}}", "".join(data_rows)).replace("{{table_title}}", f"{rtype} {gx_definitions.HTML_REPORT_EMOJIS.get(rtype,'')}").replace("{{table_id}}", "repository_"+str(sanitized_entity)+"_"+rtype))
195199

196200
if len(r_tables) > 0:
197-
repository_sidebar_links += '<ul class="nav flex-column mb-0"><li class="nav-item"><a class="nav-link collapsed" data-bs-toggle="collapse" role="button" aria-expanded="false" aria-controls="nav_'+str(sanitized_entity)+'" href="#nav_'+str(sanitized_entity)+'">'+str(sanitized_entity)+' &#128193;</a><div class="collapse" id="nav_'+str(sanitized_entity)+'"><ul class="nav flex-column ms-3">'
201+
repository_sidebar_links += '<ul class="nav flex-column mb-0"><li class="nav-item"><a class="nav-link collapsed" data-bs-toggle="collapse" role="button" aria-expanded="false" aria-controls="nav_'+str(sanitized_entity)+'" href="#nav_'+str(sanitized_entity)+'">'+str(sanitized_entity_raw)+' &#128193;</a><div class="collapse" id="nav_'+str(sanitized_entity)+'"><ul class="nav flex-column ms-3">'
198202
repository_sidebar_links += "".join(r_sidebar_links)
199203
repository_sidebar_links += '</ul></div></li></ul>'
200204
r_template = r_template.replace("{{repository_tables}}", "".join(r_tables))
@@ -245,6 +249,7 @@ def _create_html_output(self):
245249
if not self.debug_enabled() and ("debug" in rtype.lower()): continue
246250
data_rows = []
247251
for line in data[rtype]:
252+
if "warning: " in line.lower(): highlights_rows.append(f"<tr><td>{rtype}</td><td>{self.html_data_sanitize_and_process(line)}</td></tr>")
248253
if self._filters != None and (all(f.lower() not in f'{rtype.lower()} {line.lower()}' for f in self._filters)): continue
249254
data_rows.append(f"<tr><td>{sanitized_entity}</td><td>{self.html_data_sanitize_and_process(line)}</td></tr>")
250255

@@ -269,6 +274,7 @@ def _create_html_output(self):
269274
for rtype in data.keys():
270275
data_rows = []
271276
for line in data[rtype]:
277+
if "warning: " in line.lower(): highlights_rows.append(f"<tr><td>{rtype}</td><td>{self.html_data_sanitize_and_process(line)}</td></tr>")
272278
if self._filters != None and (all(f.lower() not in f'{rtype.lower()} {line.lower()}' for f in self._filters)): continue
273279
data_rows.append(f"<tr><td>{rtype}</td><td>{self.html_data_sanitize_and_process(line)}</td></tr>")
274280

@@ -310,6 +316,10 @@ def _create_html_output(self):
310316
more_sections += table_html
311317

312318

319+
# We now have all highlights under highlights_rows; let's fill the highlights table and section of the report
320+
if len(highlights_rows) > 0:
321+
highlights_section = templates['table'].replace("{{table_rows}}", "".join(highlights_rows)).replace("{{table_title}}", "Highlights").replace("{{table_id}}", "highlights")
322+
else: highlights_section = "<br/><h5>No results were highlighted by Gitxray.</h5>"
313323

314324
output = templates['main'].replace("{{repository_sections}}", repository_sections)
315325
# repository sidebar links
@@ -321,6 +331,9 @@ def _create_html_output(self):
321331
# more sidebar links
322332
output = output.replace("{{more_sidebar_links}}", more_sidebar_links)
323333

334+
# highlights section
335+
output = output.replace("{{highlights_section}}", highlights_section)
336+
324337
output = output.replace("{{category_sections}}", category_sections)
325338
output = output.replace("{{contributor_sections}}", contributor_sections)
326339
output = output.replace("{{report_date}}", datetime.datetime.now().strftime("%B %d, %Y"))

0 commit comments

Comments
 (0)