@@ -35,7 +35,7 @@ class GitlabIssue(TypedDict):
35
35
location : GitlabIssueLocation
36
36
37
37
38
- def parse_issue (line : str ) -> GitlabIssue | None :
38
+ def parse_issue (line : str , fingerprints : set [ str ] | None = None ) -> GitlabIssue | None :
39
39
if line .startswith ("{" ):
40
40
try :
41
41
match = json .loads (line )
@@ -54,17 +54,38 @@ def parse_issue(line: str) -> GitlabIssue | None:
54
54
)
55
55
if match is None :
56
56
return None
57
- fingerprint = hashlib .md5 (line .encode ("utf-8" ), usedforsecurity = False ).hexdigest ()
58
57
error_levels_table = {"error" : Severity .major , "note" : Severity .info }
58
+
59
+ path = match ["file" ]
60
+ line_number = int (match ["line" ])
61
+ error_level = match ["severity" ]
62
+ message = match ["message" ]
63
+ error_code = match ["code" ]
64
+
65
+ if fingerprints is None :
66
+ fingerprints = set ()
67
+
68
+ def make_fingerprint (salt : str ) -> str :
69
+ fingerprint_text = f"{ salt } ::{ path } ::{ error_level } ::{ error_code } ::{ message } "
70
+ return hashlib .md5 (
71
+ fingerprint_text .encode ("utf-8" ),
72
+ usedforsecurity = False ,
73
+ ).hexdigest ()
74
+
75
+ fingerprint = make_fingerprint ("" )
76
+ while fingerprint in fingerprints :
77
+ fingerprint = make_fingerprint (fingerprint )
78
+ fingerprints .add (fingerprint )
79
+
59
80
return {
60
- "description" : match [ " message" ] ,
61
- "check_name" : match [ "code" ] ,
81
+ "description" : message ,
82
+ "check_name" : error_code ,
62
83
"fingerprint" : fingerprint ,
63
- "severity" : error_levels_table .get (match [ "severity" ] , Severity .unknown ),
84
+ "severity" : error_levels_table .get (error_level , Severity .unknown ),
64
85
"location" : {
65
- "path" : match [ "file" ] ,
86
+ "path" : path ,
66
87
"lines" : {
67
- "begin" : int ( match [ "line" ]) ,
88
+ "begin" : line_number ,
68
89
},
69
90
},
70
91
}
@@ -91,7 +112,8 @@ def append_or_extend(issues: list[GitlabIssue], new: GitlabIssue) -> list[Gitlab
91
112
92
113
93
114
def generate_report (lines : Iterable [str ]) -> list [GitlabIssue ]:
94
- issues = filter (None , map (parse_issue , lines ))
115
+ fingerprints : set [str ] = set ()
116
+ issues = filter (None , (parse_issue (line , fingerprints ) for line in lines ))
95
117
return reduce (append_or_extend , issues , [])
96
118
97
119
0 commit comments