diff --git a/bin/sarif-results-summary b/bin/sarif-results-summary index a07f24f..bf3343c 100755 --- a/bin/sarif-results-summary +++ b/bin/sarif-results-summary @@ -39,10 +39,8 @@ for runi in S.indices(sarif_struct, 'runs'): relatedLocations = result.get('relatedLocations', None) if type(relatedLocations) == list: # Linking is explicit in output, so no need to get id(s) from message string. - for relo_i in S.indices(relatedLocations): - message = S.get(relatedLocations, relo_i, 'message', 'text') - artifact = S.get(relatedLocations, relo_i, 'physicalLocation', 'artifactLocation') - region = S.get(relatedLocations, relo_i, 'physicalLocation', 'region') + for relo in relatedLocations: + message, artifact, region = S.get_relatedlocation_message_info(relo) l1, c1, l2, c2 = S.lineinfo(region) filepath = "%s:%d:%d:%d:%d" % (artifact['uri'], l1, c1, l2, c2) S.msg("info: %s: %s\n\n" % (filepath, message)) diff --git a/sarif_cli/__init__.py b/sarif_cli/__init__.py index be54131..43a38dd 100644 --- a/sarif_cli/__init__.py +++ b/sarif_cli/__init__.py @@ -6,6 +6,17 @@ MIN_PYTHON = (3, 7) if sys.version_info < 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): """ Given one of the results, extract message information.