Skip to content

Feature: 支持 SARIF 输出格式 #819

Description

@Syt3s

Problem Statement

OpenCodeReview 当前仅支持两种输出格式:textjson

Proposed Solution

在现有的 --format flag 中新增 sarif 选项:

ocr review --from main --to feature-branch --format sarif > results.sarif

SARIF 输出将 LlmComment 字段映射为 SARIF result 对象:

LlmComment 字段 SARIF result 字段
Path location.physicalLocation.artifactLocation.uri
StartLine / EndLine location.physicalLocation.region.startLine / endLine
Content message.text
Category(bug, security, performance, ...) ruleId + tool.driver.rules[].id
Severity(critical, high, medium, low) level(critical/high → error, medium → warning, low → note
SuggestionCode fixes[].artifactChanges[].replacements[].insertedContent.text
ExistingCode fixes[].artifactChanges[].replacements[].deletedRegion

这是一个纯输出层变更——不涉及审查 Agent、LLM 循环、Diff 解析器或工具系统。实现完全遵循 cmd/opencodereview/output.go 中现有 outputJSONoutputText 函数的相同模式。

在 GitHub Actions 工作流中,SARIF 文件可通过标准的 github/codeql-action/upload-sarif action 上传:

- name: Run OCR
  run: ocr review --from ${{ env.MERGE_BASE }} --to ${{ env.HEAD_SHA }} --format sarif > ocr-results.sarif

- name: Upload SARIF to Code Scanning
  uses: github/codeql-action/upload-sarif@v3
  with:
    sarif_file: ocr-results.sarif

这是对现有 PR 评论流程的补充(而非替代)。团队可以同时使用两者:行内评论用于面向开发者的 PR 反馈,SARIF 上传用于 Security tab 中的持久化告警追踪。

Alternatives Considered

No response

Affected Area

CLI / Commands, Output / Formatting

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions