-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckstyle_to_codeclimate.py
More file actions
49 lines (41 loc) · 1.34 KB
/
checkstyle_to_codeclimate.py
File metadata and controls
49 lines (41 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import hashlib
import json
import os
import sys
import xml.etree.ElementTree as ET
SEVERITY_MAP = {
"error": "critical",
"warning": "major",
"info": "minor",
}
def convert(input_path, output_path):
tree = ET.parse(input_path)
project_root = os.getcwd() + os.sep
issues = []
for file_elem in tree.findall("file"):
path = file_elem.get("name", "")
if path.startswith(project_root):
path = path[len(project_root):]
for error in file_elem.findall("error"):
message = error.get("message", "")
line = int(error.get("line", "1"))
source = error.get("source", "")
severity = SEVERITY_MAP.get(error.get("severity", "warning"), "minor")
fingerprint = hashlib.md5(
f"{path}:{source}:{line}".encode()
).hexdigest()
issues.append({
"type": "issue",
"check_name": source,
"description": message,
"severity": severity,
"fingerprint": fingerprint,
"location": {
"path": path,
"lines": {"begin": line},
},
})
with open(output_path, "w") as f:
json.dump(issues, f, indent=2)
if __name__ == "__main__":
convert(sys.argv[1], sys.argv[2])