Skip to content

Commit

Permalink
chore: mics fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gg-mmill committed Dec 4, 2024
1 parent c1ec7e9 commit f63eef8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
14 changes: 2 additions & 12 deletions ggshield/core/text_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,15 @@ def file_info(
filename: str,
incident_count: int,
incident_status: IncidentStatus = IncidentStatus.DETECTED,
hidden_secrets_count: int = 0,
) -> str:
"""Return the formatted file info (number of incidents + filename)."""
result = "\n{} {}: {} {} {}\n".format(
return "\n{} {}: {} {} {}\n".format(
format_text(">", STYLE["detector_line_start"]),
format_text(filename, STYLE["filename"]),
incident_count,
pluralize("secret", incident_count, "secrets"),
pluralize("incident", incident_count, "incidents"),
incident_status.value,
)
if hidden_secrets_count > 0:
result += "{} {} {} {} ignored - use the `--all-secrets` option to display {}\n".format(
format_text(">", STYLE["detector_line_start"]),
" " * len(filename),
hidden_secrets_count,
pluralize("secret", hidden_secrets_count, "secrets"),
pluralize("it", hidden_secrets_count, "them"),
)
return result


def file_diff_info(
Expand Down
29 changes: 27 additions & 2 deletions ggshield/verticals/secret/output/secret_text_output_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from pygitguardian.client import VERSIONS
from pygitguardian.models import PolicyBreak

from ggshield.core.constants import IncidentStatus
from ggshield.core.filter import group_policy_breaks_by_ignore_sha
from ggshield.core.lines import Line, get_offset, get_padding
from ggshield.core.text_utils import (
STYLE,
clip_long_line,
file_info,
format_text,
pluralize,
translate_validity,
Expand All @@ -28,6 +28,31 @@
NB_CONTEXT_LINES = 3


def secret_file_info(
filename: str,
incident_count: int,
incident_status: IncidentStatus = IncidentStatus.DETECTED,
hidden_secrets_count: int = 0,
) -> str:
"""Return the formatted file info (number of secrets, filename, optional number of hidden secrets)."""
result = "\n{} {}: {} {} {}\n".format(
format_text(">", STYLE["detector_line_start"]),
format_text(filename, STYLE["filename"]),
incident_count,
pluralize("secret", incident_count, "secrets"),
incident_status.value,
)
if hidden_secrets_count > 0:
result += "{} {} {} {} ignored - use the `--all-secrets` option to display {}\n".format(
format_text(">", STYLE["detector_line_start"]),
" " * len(filename),
hidden_secrets_count,
pluralize("secret", hidden_secrets_count, "secrets"),
pluralize("it", hidden_secrets_count, "them"),
)
return result


class SecretTextOutputHandler(SecretOutputHandler):
def _process_scan_impl(self, scan: SecretScanCollection) -> str:
"""Output Secret Scan Collection in text format"""
Expand Down Expand Up @@ -121,7 +146,7 @@ def process_result(self, result: Result) -> str:

file_info_line = ""
if number_of_displayed_secrets > 0 or number_of_hidden_secrets > 0:
file_info_line = file_info(
file_info_line = secret_file_info(
result.filename,
incident_count=number_of_displayed_secrets,
hidden_secrets_count=number_of_hidden_secrets,
Expand Down
5 changes: 2 additions & 3 deletions ggshield/verticals/secret/secret_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ def __init__(
self.client = client
self.cache = cache
self.secret_config = secret_config
self.headers = scan_context.get_http_headers() | {
"scan_options": secret_config.dump_for_monitoring()
}
self.headers = scan_context.get_http_headers()
self.headers.update({"scan_options": secret_config.dump_for_monitoring()})

self.command_id = scan_context.command_id

Expand Down

0 comments on commit f63eef8

Please sign in to comment.