11from .render_common import (
2- HEADER_COLS ,
32 NVD_URL ,
43 days_ago ,
54 group_by_repo ,
65 pr_label ,
6+ select_columns ,
77 time_to_publish ,
88)
99
10- # org/repo are headings in markdown, so they drop out of the table itself
11- _COLS = [c for c in HEADER_COLS if c not in ("org" , "repo" )]
12- # redaction strips advisory-identifying columns, same as the terminal renderer
13- _REDACTED_COLS = _COLS [: _COLS .index ("state" ) + 1 ]
14-
1510
1611def _cell (text ):
1712 """Escape what would otherwise break out of a table cell."""
1813 return str (text ).replace ("|" , "\\ |" ).replace ("\n " , " " )
1914
2015
21- def render_org (org , states , results_by_key , pull_results = None , redact = False ):
16+ def render_org (org , states , results_by_key , pull_results = None , redact = False , columns = None ):
2217 advisories = []
2318 for state in states :
2419 advisories .extend (results_by_key .get ((org , state ), []))
2520
2621 if not advisories :
2722 return ""
2823
29- cols = _REDACTED_COLS if redact else _COLS
24+ # org/repo are headings in markdown, so they never appear as columns
25+ cols = [c for c in select_columns (columns , redact ) if c not in ("org" , "repo" )]
26+ if not cols :
27+ return ""
28+
3029 header = "| " + " | " .join (cols ) + " |"
3130 divider = "|" + "|" .join ("-" * (len (c ) + 2 ) for c in cols ) + "|"
3231
@@ -39,27 +38,22 @@ def render_org(org, states, results_by_key, pull_results=None, redact=False):
3938 lines .append (divider )
4039 for advisory in items :
4140 ttp = time_to_publish (advisory )
42- cells = [
43- days_ago (advisory .get ("created_at" , "" )),
44- days_ago (advisory .get ("updated_at" , "" )),
45- "" if ttp is None else ttp ,
46- advisory .get ("state" ) or "?" ,
47- ]
48-
49- if not redact :
50- url = advisory .get ("html_url" , "" )
51- ghsa_id = advisory .get ("ghsa_id" ) or ""
52- cve = advisory .get ("cve_id" ) or ""
53- fork = advisory .get ("private_fork" )
54- fork_html_url = fork .get ("html_url" ) if fork else None
55- pulls = (pull_results or {}).get (fork_html_url , []) if fork_html_url else []
56- cells += [
57- f"[{ ghsa_id } ]({ url } )" if (ghsa_id and url ) else ghsa_id ,
58- f"[{ cve } ]({ NVD_URL .format (cve )} )" if cve else "" ,
59- _cell (advisory .get ("summary" ) or "" ),
60- ", " .join (f"[{ pr_label (p )} ]({ p ['html_url' ]} )" for p in pulls ),
61- ]
62-
63- lines .append ("| " + " | " .join (str (c ) for c in cells ) + " |" )
41+ url = advisory .get ("html_url" , "" )
42+ ghsa_id = advisory .get ("ghsa_id" ) or ""
43+ cve = advisory .get ("cve_id" ) or ""
44+ fork = advisory .get ("private_fork" )
45+ fork_html_url = fork .get ("html_url" ) if fork else None
46+ pulls = (pull_results or {}).get (fork_html_url , []) if fork_html_url else []
47+ cell = {
48+ "created" : days_ago (advisory .get ("created_at" , "" )),
49+ "updated" : days_ago (advisory .get ("updated_at" , "" )),
50+ "to-publish" : "" if ttp is None else ttp ,
51+ "state" : advisory .get ("state" ) or "?" ,
52+ "ghsa" : f"[{ ghsa_id } ]({ url } )" if (ghsa_id and url ) else ghsa_id ,
53+ "cve" : f"[{ cve } ]({ NVD_URL .format (cve )} )" if cve else "" ,
54+ "title" : _cell (advisory .get ("summary" ) or "" ),
55+ "PRs" : ", " .join (f"[{ pr_label (p )} ]({ p ['html_url' ]} )" for p in pulls ),
56+ }
57+ lines .append ("| " + " | " .join (str (cell [c ]) for c in cols ) + " |" )
6458
6559 return "\n " .join (lines )
0 commit comments