Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add-security-linter-results-to-workflow-summary #254

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Jannis-Mittenzwei
Copy link
Contributor

closes #248

@Jannis-Mittenzwei Jannis-Mittenzwei changed the title add to tbx security pretty print for markdown add-security-linter-results-to-workflow-summary Oct 2, 2024
exasol/toolbox/tools/security.py Outdated Show resolved Hide resolved
exasol/toolbox/tools/security.py Outdated Show resolved Hide resolved
exasol/toolbox/tools/security.py Outdated Show resolved Hide resolved
exasol/toolbox/tools/security.py Outdated Show resolved Hide resolved
Comment on lines 125 to 137
def issues_to_markdown(issues: Iterable[Issue]) -> str:
markdown_str = ""
markdown_str += "# Security\n\n"
markdown_str += "|File|Cve|Cwe|Details|\n"
markdown_str += "|---|:-:|:-:|---|\n"
for issue in issues:
row = "|" + issue.coordinates + "|"
row += issue.cve + "|"
row += issue.cwe + "|"
for element in issue.references:
row += element + " ,<br>"
markdown_str += row[:-5] + "|\n"
return markdown_str
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def issues_to_markdown(issues: Iterable[Issue]) -> str:
markdown_str = ""
markdown_str += "# Security\n\n"
markdown_str += "|File|Cve|Cwe|Details|\n"
markdown_str += "|---|:-:|:-:|---|\n"
for issue in issues:
row = "|" + issue.coordinates + "|"
row += issue.cve + "|"
row += issue.cwe + "|"
for element in issue.references:
row += element + " ,<br>"
markdown_str += row[:-5] + "|\n"
return markdown_str
from inspect import cleandoc
def issues_to_markdown(issues: Iterable[Issue]) -> str:
template = cleandoc("""
{header}
{rows}
""")
def _header():
header = ""
markdown_str += "# Security\n\n"
header += "|File|Cve|Cwe|Details|\n"
header += "|---|:-:|:-:|---|\n"
return header
def _row(issue):
row = "|" + issue.coordinates + "|"
row += issue.cve + "|"
row += issue.cwe + "|"
for element in issue.references:
row += element + " ,<br>"
row += row[:-5] + "|"
return row
return template.format(
header=_header()
rows = "\n".jon(_entry(i) for i in issues)
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally if you make use of "".join() you can safe yourself the head egg with removing the bits from the last line here:

        for element in issue.references:
            row += element + " ,<br>"
        row += row[:-5] + "|"

Similar to what is done in the new return statement for rows

description=issue["issue_text"],
coordinates=issue["filename"].replace(
str(PROJECT_CONFIG.root) + "/", ""
) + ":" + str(issue["line_number"]) + ":" + str(issue["col_offset"]) + ":",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f'{issue["line_number"]}' has the same effect as str(issue["line_number"])

Comment on lines +119 to +120
str(PROJECT_CONFIG.root) + "/", ""
) + ":" + str(issue["line_number"]) + ":" + str(issue["col_offset"]) + ":",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
str(PROJECT_CONFIG.root) + "/", ""
) + ":" + str(issue["line_number"]) + ":" + str(issue["col_offset"]) + ":",
f'{PROJECT_CONFIG.root}/, ""') + f':{issue["line_number"]}:{issue["col_offset"]}:',

.github/workflows/report.yml Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

✨ Add security linter results to workflow summary
2 participants