|
2 | 2 |
|
3 | 3 | import hashlib
|
4 | 4 | import json
|
| 5 | +import os |
5 | 6 | import re
|
6 | 7 | from enum import Enum
|
7 | 8 | from functools import reduce
|
@@ -33,29 +34,37 @@ class GitlabIssue(TypedDict):
|
33 | 34 |
|
34 | 35 |
|
35 | 36 | def parse_issue(line: str) -> GitlabIssue | None:
|
36 |
| - match = re.fullmatch( |
37 |
| - r"(?P<path>.+?)" |
38 |
| - r":(?P<line_number>\d+)(?::\d+)?" # ignore column number if exists |
39 |
| - r":\s(?P<error_level>\w+)" |
40 |
| - r":\s(?P<description>.+?)" |
41 |
| - r"(?:\s\s\[(?P<error_code>.*)])?", |
42 |
| - line, |
43 |
| - ) |
| 37 | + if line.startswith("{"): |
| 38 | + try: |
| 39 | + match = json.loads(line) |
| 40 | + except json.JSONDecodeError: |
| 41 | + match = None |
| 42 | + if hint := match.get("hint"): # attach hint to message |
| 43 | + match["message"] += os.linesep + hint |
| 44 | + else: |
| 45 | + match = re.fullmatch( |
| 46 | + r"(?P<file>.+?)" |
| 47 | + r":(?P<line>\d+)(?::\d+)?" # ignore column number if exists |
| 48 | + r":\s(?P<severity>\w+)" |
| 49 | + r":\s(?P<message>.+?)" |
| 50 | + r"(?:\s\s\[(?P<code>.*)])?", |
| 51 | + line, |
| 52 | + ) |
44 | 53 | if match is None:
|
45 | 54 | return None
|
46 | 55 | # TODO(soul-catcher): add usedforsecurity=False and remove noqa
|
47 | 56 | # when python 3.8 will be discontinued
|
48 | 57 | fingerprint = hashlib.md5(line.encode("utf-8")).hexdigest() # noqa: S324
|
49 | 58 | error_levels_table = {"error": Severity.major, "note": Severity.info}
|
50 | 59 | return {
|
51 |
| - "description": match["description"], |
52 |
| - "check_name": match["error_code"], |
| 60 | + "description": match["message"], |
| 61 | + "check_name": match["code"], |
53 | 62 | "fingerprint": fingerprint,
|
54 |
| - "severity": error_levels_table.get(match["error_level"], Severity.unknown), |
| 63 | + "severity": error_levels_table.get(match["severity"], Severity.unknown), |
55 | 64 | "location": {
|
56 |
| - "path": match["path"], |
| 65 | + "path": match["file"], |
57 | 66 | "lines": {
|
58 |
| - "begin": int(match["line_number"]), |
| 67 | + "begin": int(match["line"]), |
59 | 68 | },
|
60 | 69 | },
|
61 | 70 | }
|
|
0 commit comments