forked from reviewdog/action-detect-secrets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
baseline2rdf.py
executable file
·53 lines (45 loc) · 1.36 KB
/
baseline2rdf.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
48
49
50
51
52
53
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import json
rdjson = {
'source': {
'name': 'detect-secrets',
'url': 'https://github.com/Yelp/detect-secrets'
},
'severity': 'ERROR',
'diagnostics': []
}
def main():
baseline = json.load(sys.stdin)
if not baseline['results']:
baseline['results'] = {}
results = {}
for detects in baseline['results'].values():
for item in detects:
key = '%s:%s' % (item['filename'], item['line_number'])
if key in results:
results[key]['message'] += '\n* ' + item['type']
else:
results[key] = {
'message': '\n* ' + item['type'],
'location': {
'path': item['filename'],
'range': {
'start': {
'line': item['line_number']
}
}
}
}
for result in results.values():
rdjson['diagnostics'].append(result)
try:
sys.stdout.write(json.dumps(rdjson, indent=2, ensure_ascii=False))
sys.stdout.write('\n')
except Exception as error:
sys.stderr.write('Error: %s\n' % error)
return 1
return 0
if __name__ == '__main__':
sys.exit(main())