Skip to content

Commit

Permalink
feat(cmd): make the exit-zero option apply to all errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gg-jonathangriffe committed Jan 6, 2025
1 parent 7d85eb1 commit 5f4b86a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Changed

- The `--exit-zero` option now applies to all errors.
5 changes: 1 addition & 4 deletions ggshield/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ def exit_code(ctx: click.Context, exit_code: int, **kwargs: Any) -> int:
when exit_zero is enabled
"""
ctx_obj = ContextObj.get(ctx)
if (
exit_code == ExitCode.SCAN_FOUND_PROBLEMS
and ctx_obj.config.user_config.exit_zero
):
if ctx_obj.config.user_config.exit_zero:
logger.debug("scan exit_code forced to 0")
sys.exit(ExitCode.SUCCESS)

Expand Down
18 changes: 18 additions & 0 deletions tests/unit/cmd/scan/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest
from click.testing import CliRunner
from pygitguardian.models import MultiScanResult
from requests.exceptions import ConnectionError

from ggshield.__main__ import cli
from ggshield.core.errors import ExitCode
Expand Down Expand Up @@ -146,6 +147,23 @@ def test_scan_file_secret_exit_zero(self, cli_fs_runner, json_output):
if json_output:
json.loads(result.output)

@patch("pygitguardian.GGClient.request", side_effect=ConnectionError)
def test_scan_connection_error_exit_zero(self, _, cli_fs_runner):
write_text(Path("file"), "")
result = cli_fs_runner.invoke(
cli,
[
"secret",
"scan",
"-v",
"path",
"--exit-zero",
"file",
],
)
assert_invoke_ok(result)
assert not result.exception

def test_files_abort(self, cli_fs_runner):
self.create_files()
result = cli_fs_runner.invoke(
Expand Down

0 comments on commit 5f4b86a

Please sign in to comment.