function parseResult()

in scan/src/annotations.ts [122:156]


function parseResult(
  result: Result,
  rules: Map<string, Rule>
): Annotation | null {
  if (
    !result.locations ||
    result.locations.length === 0 ||
    !result.locations[0].physicalLocation
  ) {
    return null
  }
  const location = result.locations[0].physicalLocation
  const region = location.region
  return {
    message: result.message.markdown ?? result.message.text!,
    title: rules.get(result.ruleId!)?.shortDescription,
    path: location.artifactLocation!.uri!,
    start_line: region?.startLine || 0,
    end_line: region?.endLine || region?.startLine || 1,
    start_column:
      region?.startLine === region?.endColumn ? region?.startColumn : undefined,
    end_column:
      region?.startLine === region?.endColumn ? region?.endColumn : undefined,
    annotation_level: (() => {
      switch (result.level) {
        case 'error':
          return ANNOTATION_FAILURE
        case 'warning':
          return ANNOTATION_WARNING
        default:
          return ANNOTATION_NOTICE
      }
    })()
  }
}