mirror of
https://github.com/hohn/sarif-cli.git
synced 2025-12-16 17:23:03 +01:00
Introduce get_relatedlocation_message_info to co-locate tree information
This commit is contained in:
committed by
=Michael Hohn
parent
1f7e78b049
commit
6147e57260
@@ -39,10 +39,8 @@ for runi in S.indices(sarif_struct, 'runs'):
|
|||||||
relatedLocations = result.get('relatedLocations', None)
|
relatedLocations = result.get('relatedLocations', None)
|
||||||
if type(relatedLocations) == list:
|
if type(relatedLocations) == list:
|
||||||
# Linking is explicit in output, so no need to get id(s) from message string.
|
# Linking is explicit in output, so no need to get id(s) from message string.
|
||||||
for relo_i in S.indices(relatedLocations):
|
for relo in relatedLocations:
|
||||||
message = S.get(relatedLocations, relo_i, 'message', 'text')
|
message, artifact, region = S.get_relatedlocation_message_info(relo)
|
||||||
artifact = S.get(relatedLocations, relo_i, 'physicalLocation', 'artifactLocation')
|
|
||||||
region = S.get(relatedLocations, relo_i, 'physicalLocation', 'region')
|
|
||||||
l1, c1, l2, c2 = S.lineinfo(region)
|
l1, c1, l2, c2 = S.lineinfo(region)
|
||||||
filepath = "%s:%d:%d:%d:%d" % (artifact['uri'], l1, c1, l2, c2)
|
filepath = "%s:%d:%d:%d:%d" % (artifact['uri'], l1, c1, l2, c2)
|
||||||
S.msg("info: %s: %s\n\n" % (filepath, message))
|
S.msg("info: %s: %s\n\n" % (filepath, message))
|
||||||
|
|||||||
@@ -6,6 +6,17 @@ MIN_PYTHON = (3, 7)
|
|||||||
if sys.version_info < MIN_PYTHON:
|
if sys.version_info < MIN_PYTHON:
|
||||||
sys.exit("Python %s.%s or later is required.\n" % MIN_PYTHON)
|
sys.exit("Python %s.%s or later is required.\n" % MIN_PYTHON)
|
||||||
|
|
||||||
|
def get_relatedlocation_message_info(related_location):
|
||||||
|
""" Given a relatedLocation, extract message information.
|
||||||
|
|
||||||
|
The relatedLocation typically starts from
|
||||||
|
get(sarif_struct, 'runs', [int], 'results', [int], 'relatedLocations', [int])
|
||||||
|
"""
|
||||||
|
message = get(related_location, 'message', 'text')
|
||||||
|
artifact = get(related_location, 'physicalLocation', 'artifactLocation')
|
||||||
|
region = get(related_location, 'physicalLocation', 'region')
|
||||||
|
return message, artifact, region
|
||||||
|
|
||||||
def get_location_message_info(result):
|
def get_location_message_info(result):
|
||||||
""" Given one of the results, extract message information.
|
""" Given one of the results, extract message information.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user