-
Notifications
You must be signed in to change notification settings - Fork 10
/
converter.py
47 lines (34 loc) · 1.33 KB
/
converter.py
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
import os
import sys
import xml.etree.ElementTree as ET
if len(sys.argv) == 1:
raise NameError('No lint file specified')
if not os.path.isfile(sys.argv[1]):
raise IOError('Invalid file specified')
RUNNER_WORKSPACE = os.environ['RUNNER_WORKSPACE']
REPO_NAME = os.environ['GITHUB_REPOSITORY'].split('/')[1]
checkstyle = ET.Element('checkstyle')
checkstyle.attrib['version'] = '8.0'
for issue in ET.parse(sys.argv[1]).getroot().iter('issue'):
file = ET.SubElement(checkstyle, 'file')
if '.gradle/caches' in issue[0].attrib['file']:
continue
file.attrib['name'] = issue[0].attrib['file'].replace(f'{RUNNER_WORKSPACE}/{REPO_NAME}/', '')
error = ET.SubElement(file, 'error')
if 'line' in issue[0].attrib:
error.attrib['line'] = issue[0].attrib['line']
else:
error.attrib['line'] = str(0)
if 'column' in issue[0].attrib:
error.attrib['column'] = issue[0].attrib['column']
else:
error.attrib['column'] = str(0)
if 'severity' in issue.attrib:
error.attrib['severity'] = issue.attrib['severity']
else:
error.attrib['severity'] = 'info'
issueId = issue.attrib['id']
message = issue.attrib['message']
error.attrib['message'] = f'{issueId}: {message}'
checkStyleFile = ET.ElementTree(checkstyle)
checkStyleFile.write('output_checkstyle.xml')