diff --git a/ggshield/hook_cmd.py b/ggshield/hook_cmd.py index f4c296c75b..cedf8917e2 100644 --- a/ggshield/hook_cmd.py +++ b/ggshield/hook_cmd.py @@ -9,7 +9,7 @@ from ggshield.dev_scan import scan_commit_range from ggshield.output import TextHandler from ggshield.scan import Commit, ScanCollection -from ggshield.utils import EMPTY_SHA, EMPTY_TREE +from ggshield.utils import EMPTY_SHA, EMPTY_TREE, SupportedScanMode from .git_shell import check_git_dir, get_list_commit_SHA @@ -35,6 +35,7 @@ def precommit_cmd( matches_ignore=config.matches_ignore, all_policies=config.all_policies, verbose=config.verbose, + mode_header=SupportedScanMode.PRE_COMMIT.value, ) return output_handler.process_scan( @@ -133,6 +134,7 @@ def prepush_cmd(ctx: click.Context, prepush_args: List[str]) -> int: # pragma: matches_ignore=config.matches_ignore, all_policies=config.all_policies, scan_id=" ".join(commit_list), + mode_header=SupportedScanMode.PRE_PUSH.value, ) except click.exceptions.Abort: return 0 diff --git a/ggshield/utils.py b/ggshield/utils.py index adef090388..b847c5fbe6 100644 --- a/ggshield/utils.py +++ b/ggshield/utils.py @@ -182,4 +182,5 @@ class SupportedScanMode(Enum): PATH = "path" COMMIT_RANGE = "commit_range" PRE_COMMIT = "pre_commit" + PRE_PUSH = "pre_push" CI = "ci" diff --git a/tests/test_hook_cmd.py b/tests/test_hook_cmd.py index dd25d96d54..bef7d5992f 100644 --- a/tests/test_hook_cmd.py +++ b/tests/test_hook_cmd.py @@ -1,4 +1,4 @@ -from unittest.mock import Mock, patch +from unittest.mock import ANY, Mock, patch from click.testing import CliRunner @@ -55,7 +55,8 @@ def test_prepush_pre_commit_framework_new( THEN it should pass onto scan and return 0 """ scan_commit_range_mock.return_value = 0 - get_list_mock.return_value = ["a" for _ in range(20)] + commit_list = ["a" for _ in range(20)] + get_list_mock.return_value = commit_list result = cli_fs_runner.invoke( cli, @@ -63,7 +64,18 @@ def test_prepush_pre_commit_framework_new( env={"PRE_COMMIT_FROM_REF": "a" * 40, "PRE_COMMIT_TO_REF": "b" * 40}, ) get_list_mock.assert_called_once_with("b" * 40 + "..." + "a" * 40) - scan_commit_range_mock.assert_called_once() + scan_commit_range_mock.assert_called_once_with( + client=ANY, + cache=ANY, + commit_list=commit_list, + output_handler=ANY, + verbose=True, + filter_set=set(), + matches_ignore=ANY, + all_policies=False, + scan_id=ANY, + mode_header="pre_push", + ) assert "Commits to scan: 20" in result.output assert result.exit_code == 0