Skip to content

Commit

Permalink
fix(ggshield): add pre-push mode header
Browse files Browse the repository at this point in the history
  • Loading branch information
Jguer committed Mar 31, 2021
1 parent 1e26ae6 commit 18b72b4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 3 additions & 1 deletion ggshield/hook_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ggshield/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,5 @@ class SupportedScanMode(Enum):
PATH = "path"
COMMIT_RANGE = "commit_range"
PRE_COMMIT = "pre_commit"
PRE_PUSH = "pre_push"
CI = "ci"
18 changes: 15 additions & 3 deletions tests/test_hook_cmd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from unittest.mock import Mock, patch
from unittest.mock import ANY, Mock, patch

from click.testing import CliRunner

Expand Down Expand Up @@ -55,15 +55,27 @@ 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,
["-v", "scan", "pre-push"],
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

Expand Down

0 comments on commit 18b72b4

Please sign in to comment.