@@ -123,18 +123,30 @@ def from_json(report_str: str) -> Iterable[Issue]:
123123
124124
125125def issues_to_markdown (issues : Iterable [Issue ]) -> str :
126- markdown_str = ""
127- markdown_str += "# Security\n \n "
128- markdown_str += "|File|Cve|Cwe|Details|\n "
129- markdown_str += "|---|:-:|:-:|---|\n "
130- for issue in issues :
126+ template = cleandoc ("""
127+ {header}{rows}
128+ """ )
129+ def _header ():
130+ header = ""
131+ markdown_str = ""
132+ markdown_str += "# Security\n \n "
133+ header += "|File|Cve|Cwe|Details|\n "
134+ header += "|---|:-:|:-:|---|\n "
135+ return header
136+
137+ def _row (issue ):
131138 row = "|" + issue .coordinates + "|"
132139 row += issue .cve + "|"
133140 row += issue .cwe + "|"
134141 for element in issue .references :
135142 row += element + " ,<br>"
136- markdown_str += row [:- 5 ] + "|\n "
137- return markdown_str
143+ row += row [:- 5 ] + "|"
144+ return row
145+
146+ return template .format (
147+ header = _header (),
148+ rows = "\n " .join (_row (i ) for i in issues )
149+ )
138150
139151
140152def security_issue_title (issue : Issue ) -> str :
@@ -186,16 +198,14 @@ def create_security_issue(issue: Issue, project="") -> Tuple[str, str]:
186198 raise ex
187199
188200 std_err = result .stderr .decode ("utf-8" )
189- std_out = result .stdout .decode ("utf-8r " )
201+ std_out = result .stdout .decode ("utf-8 " )
190202
191203 return std_err , std_out
192204
193205
194206CLI = typer .Typer ()
195207CVE_CLI = typer .Typer ()
196- PP_CLI = typer .Typer ()
197208CLI .add_typer (CVE_CLI , name = "cve" , help = "Work with CVE's" )
198- CLI .add_typer (PP_CLI , name = "prettyprint" , help = "Prints pretty" )
199209
200210class Format (str , Enum ):
201211 Maven = "maven"
@@ -294,13 +304,18 @@ def create(
294304 stdout (format_jsonl (issue_url , issue ))
295305
296306
297- @PP_CLI .command (name = "markdown" )
307+ class PPrintFormats (str , Enum ):
308+ markdown = "markdown"
309+
310+
311+ @CLI .command (name = "pretty-print" )
298312def json_issue_to_markdown (
299- json_file : str = typer .Argument (help = "json file with issues to convert" ),
313+ format : PPrintFormats = typer .Option (default = "" , help = "output format" ,),
314+ json_file : typer .FileText = typer .Argument (default = "" , mode = "r" , help = "json file with issues to convert" ),
300315) -> None :
301- with open ( json_file , "r" ) as file :
302- issues_ = from_json (file . read () )
303- print (issues_to_markdown (issues_ ))
316+ content = json_file . read ()
317+ issues = from_json (content )
318+ print (issues_to_markdown (issues ))
304319
305320
306321def format_jsonl (issue_url : str , issue : Issue ) -> str :
0 commit comments