1+ /* eslint-disable @typescript-eslint/naming-convention */
12import {
23 Diagnostic ,
34 Range ,
@@ -15,18 +16,29 @@ import {
1516
1617const validityDisplayName : Record < Validity , string > = {
1718 unknown : "Unknown" ,
18- // eslint-disable-next-line @typescript-eslint/naming-convention
1919 cannot_check : "Cannot Check" ,
20- // eslint-disable-next-line @typescript-eslint/naming-convention
2120 no_checker : "No Checker" ,
22- // eslint-disable-next-line @typescript-eslint/naming-convention
2321 failed_to_check : "Failed to Check" ,
24- // eslint-disable-next-line @typescript-eslint/naming-convention
2522 not_checked : "Not Checked" ,
2623 invalid : "Invalid" ,
2724 valid : "Valid" ,
2825} ;
2926
27+ /**
28+ * Given a list of occurrences, this function searches for the matches of type "connection_uri"
29+ * and returns it if found. If no "connection_uri" match is found, the original list is returned.
30+ * This ensures that only the full URI match is kept, avoiding multiple matches for its components (e.g. scheme, username, password, host).
31+ *
32+ * @param occurrences - An array of `Occurrence` objects to be filtered.
33+ * @returns An array containing the "connection_uri" occurrence, or the original list if no such match exists.
34+ */
35+ function filterUriOccurrences ( occurrences : Occurrence [ ] ) : Occurrence [ ] {
36+ const uriOccurrence = occurrences . find (
37+ ( { type } ) => type === "connection_uri"
38+ ) ;
39+ return uriOccurrence ? [ uriOccurrence ] : occurrences ;
40+ }
41+
3042/**
3143 * Parse ggshield results and return diagnostics of found incidents
3244 *
@@ -45,27 +57,29 @@ export function parseGGShieldResults(
4557 results . entities_with_incidents . forEach (
4658 ( entityWithIncidents : EntityWithIncidents ) => {
4759 entityWithIncidents . incidents . forEach ( ( incident : Incident ) => {
48- incident . occurrences . forEach ( ( occurrence : Occurrence ) => {
49- let range = new Range (
50- new Position ( occurrence . line_start - 1 , occurrence . index_start ) ,
51- new Position ( occurrence . line_end - 1 , occurrence . index_end )
52- ) ;
53- let diagnostic = new Diagnostic (
54- range ,
55- `ggshield: ${ occurrence . type }
60+ filterUriOccurrences ( incident . occurrences ) . forEach (
61+ ( occurrence : Occurrence ) => {
62+ let range = new Range (
63+ new Position ( occurrence . line_start - 1 , occurrence . index_start ) ,
64+ new Position ( occurrence . line_end - 1 , occurrence . index_end )
65+ ) ;
66+ let diagnostic = new Diagnostic (
67+ range ,
68+ `ggshield: ${ occurrence . type }
5669
5770Secret detected: ${ incident . type }
5871Validity: ${ validityDisplayName [ incident . validity ] }
5972Known by GitGuardian dashboard: ${ incident . known_secret ? "YES" : "NO" }
6073Total occurrences: ${ incident . total_occurrences }
6174Incident URL: ${ incident . incident_url || "N/A" }
6275Secret SHA: ${ incident . ignore_sha } ` ,
63- DiagnosticSeverity . Warning
64- ) ;
76+ DiagnosticSeverity . Warning
77+ ) ;
6578
66- diagnostic . source = "gitguardian" ;
67- diagnostics . push ( diagnostic ) ;
68- } ) ;
79+ diagnostic . source = "gitguardian" ;
80+ diagnostics . push ( diagnostic ) ;
81+ }
82+ ) ;
6983 } ) ;
7084 }
7185 ) ;
0 commit comments