Skip to content

Commit f838e67

Browse files
committed
feat(scan): Ignore secret which are not introduced
1 parent 6427d8f commit f838e67

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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)