Skip to content
This repository was archived by the owner on May 31, 2023. It is now read-only.

Commit d9908dc

Browse files
author
Ryan Faircloth
authored
Merge pull request #3 from hsekowski/main
fix: does not fail in case no data from /dev/stdin or the data does n…
2 parents e4c3f86 + f226626 commit d9908dc

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

annotate.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,35 @@
3131

3232
diagnostics=[]
3333

34-
for hit in data['hits']:
35-
diagnostic={}
36-
diagnostic['location'] ={
37-
'path': hit['filename'].replace(f'{ws}/',''),
38-
'range': {
39-
'start': {
40-
'line': hit['line'],
41-
'column': 1
34+
HITS = 'hits'
35+
if data and (HITS in data) :
36+
for hit in data[HITS]:
37+
diagnostic={}
38+
diagnostic['location'] ={
39+
'path': hit['filename'].replace(f'{ws}/',''),
40+
'range': {
41+
'start': {
42+
'line': hit['line'],
43+
'column': 1
44+
}
4245
}
4346
}
44-
}
45-
diagnostic['severity'] ="ERROR"
46-
diagnostic['code'] = {
47-
"value": "hit['code']"
48-
}
49-
50-
diagnostic['message'] = f"""{hit['caption']}
51-
solution={hit['solution']}
52-
category={hit['category']}
53-
code={hit['code']}
54-
confidence={hit['confidence']}
55-
cwe={hit['cwe']}
56-
labels={hit['labels']}
57-
"""
58-
diagnostics.append(diagnostic)
59-
60-
rd['diagnostics']=diagnostics
61-
62-
json_formatted_str = json.dumps(rd, indent=4)
63-
print(json_formatted_str)
47+
diagnostic['severity'] ="ERROR"
48+
diagnostic['code'] = {
49+
"value": "hit['code']"
50+
}
51+
52+
diagnostic['message'] = f"""{hit['caption']}
53+
solution={hit['solution']}
54+
category={hit['category']}
55+
code={hit['code']}
56+
confidence={hit['confidence']}
57+
cwe={hit['cwe']}
58+
labels={hit['labels']}
59+
"""
60+
diagnostics.append(diagnostic)
61+
62+
rd['diagnostics']=diagnostics
63+
64+
json_formatted_str = json.dumps(rd, indent=4)
65+
print(json_formatted_str)

0 commit comments

Comments
 (0)