Skip to content

Commit ee56436

Browse files
authored
Merge pull request #1010 from GitGuardian/samuel/spi-526-implement-deletion-commit-identification-in-ggshield
feat(output): Only fail secret scans when the secret is introduced
2 parents 6427d8f + b34d264 commit ee56436

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
-->
6+
7+
<!--
8+
### Removed
9+
10+
- A bullet item for the Removed category.
11+
12+
-->
13+
<!--
14+
### Added
15+
16+
- A bullet item for the Added category.
17+
18+
-->
19+
20+
### Changed
21+
22+
- When scanning commits, ggshield will ignore by default secrets which are removed or contextual to the patch.
23+
24+
<!--
25+
### Deprecated
26+
27+
- A bullet item for the Deprecated category.
28+
29+
-->
30+
<!--
31+
### Fixed
32+
33+
- A bullet item for the Fixed category.
34+
35+
-->
36+
<!--
37+
### Security
38+
39+
- A bullet item for the Security category.
40+
41+
-->

ggshield/verticals/secret/secret_scan_collection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class IgnoreReason(Enum):
2828
IGNORED_MATCH = "ignored_match"
2929
IGNORED_DETECTOR = "ignored_detector"
3030
KNOWN_SECRET = "known_secret"
31+
NOT_INTRODUCED = "not_introduced"
3132

3233

3334
class Result:

ggshield/verticals/secret/secret_scanner.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
from typing import Dict, Iterable, List, Optional, Union
88

99
from pygitguardian import GGClient
10-
from pygitguardian.models import APITokensResponse, Detail, MultiScanResult, TokenScope
10+
from pygitguardian.models import (
11+
APITokensResponse,
12+
Detail,
13+
DiffKind,
14+
MultiScanResult,
15+
TokenScope,
16+
)
1117

1218
from ggshield.core import ui
1319
from ggshield.core.cache import Cache
@@ -220,6 +226,11 @@ def _collect_results(
220226
)
221227
if not scan_result.has_policy_breaks:
222228
continue
229+
result.apply_ignore_function(
230+
IgnoreReason.NOT_INTRODUCED,
231+
lambda policy_break: policy_break.diff_kind
232+
in {DiffKind.DELETION, DiffKind.CONTEXT},
233+
)
223234
result.apply_ignore_function(
224235
IgnoreReason.IGNORED_MATCH,
225236
lambda policy_break: is_in_ignored_matches(

0 commit comments

Comments
 (0)