Skip to content

feat(ci): 添加 OpenCodeReview PR 自动审查工作流#12

Merged
zshs000 merged 3 commits into
masterfrom
feat/add-ocr-review-workflow
Jun 6, 2026
Merged

feat(ci): 添加 OpenCodeReview PR 自动审查工作流#12
zshs000 merged 3 commits into
masterfrom
feat/add-ocr-review-workflow

Conversation

@zshs000

@zshs000 zshs000 commented Jun 6, 2026

Copy link
Copy Markdown
Owner
  • 本 PR 为项目引入了 OpenCodeReview (https://github.com/alibaba/open-code-review) 自动代码审查工具,用于在 PR 提交时自动进行代码审查并生成内联评论。支持 PR创建自动触发和评论手动触发(/open-code-review 或 @open-code-review)。

@gemini-code-assist

Copy link
Copy Markdown

Note

Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 OpenCodeReview found 3 issue(s) in this PR.

  • ✅ 3 posted as inline comment(s)
  • 📝 0 posted as summary (missing line info)

Comment thread .github/workflows/ocr-review.yml
Comment thread .github/workflows/ocr-review.yml
Comment thread .github/workflows/ocr-review.yml Outdated

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 OpenCodeReview found 5 issue(s) in this PR.

  • ✅ 5 posted as inline comment(s)
  • 📝 0 posted as summary (missing line info)

Comment thread .github/workflows/ocr-review.yml Outdated
Comment thread .github/workflows/ocr-review.yml
Comment thread .github/workflows/ocr-review.yml
Comment thread .github/workflows/ocr-review.yml
Comment thread .github/workflows/ocr-review.yml
- 仅允许 OWNER/MEMBER/COLLABORATOR/CONTRIBUTOR 触发
- PR 创建触发不受影响

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 OpenCodeReview found 10 issue(s) in this PR.

  • ✅ 8 posted as inline comment(s)
  • 📝 2 posted as summary (missing line info)

📄 .github/workflows/ocr-review.yml

安全风险:ocr review命令的输出直接写入文件并cat显示,如果OCR输出包含敏感信息,可能会在GitHub Actions日志中泄露。建议:1) 对输出文件进行加密或混淆处理;2) 或者只记录必要的错误信息,避免完整输出日志;3) 考虑使用::add-mask::来掩码敏感信息。

💡 Suggested Change

Before:

          # Run OCR in range mode with JSON output
          ocr review \
            --from "origin/${BASE_REF}" \
            --to "origin/${HEAD_REF}" \
            --format json \
            > /tmp/ocr-result.json 2>/tmp/ocr-stderr.log || true

          echo "OCR review completed. Output:"
          cat /tmp/ocr-result.json
          echo "OCR review completed. Error log:"
          cat /tmp/ocr-stderr.log

After:

          # Run OCR in range mode with JSON output
          ocr review \
            --from "origin/${BASE_REF}" \
            --to "origin/${HEAD_REF}" \
            --format json \
            > /tmp/ocr-result.json 2>/tmp/ocr-stderr.log || true

          echo "OCR review completed. Check /tmp/ocr-result.json for details."

📄 .github/workflows/ocr-review.yml

代码重复:formatCommentformatCommentMarkdown函数有重复的代码逻辑,特别是处理suggestion_code的部分。建议:1) 提取公共逻辑到辅助函数;2) 或者使用统一的格式化函数;3) 减少代码重复,提高可维护性。

💡 Suggested Change

Before:

            function formatComment(comment) {
              let body = comment.content || '';

              // Add code suggestion if available
              if (comment.suggestion_code && comment.existing_code) {
                body += '\n\n**Suggestion:**\n';
                body += '```suggestion\n';
                body += comment.suggestion_code;
                if (!comment.suggestion_code.endsWith('\n')) body += '\n';
                body += '```';
              }

              return body;
            }

            function formatCommentMarkdown(comment) {
              let md = `### 📄 \`${comment.path}\``;
              if (comment.start_line && comment.end_line) {
                md += ` (L${comment.start_line}-L${comment.end_line})`;
              }
              md += '\n\n';
              md += comment.content || '';

              if (comment.suggestion_code && comment.existing_code) {
                md += '\n\n<details><summary>💡 Suggested Change</summary>\n\n';
                md += '**Before:**\n```\n' + comment.existing_code + '\n```\n\n';
                md += '**After:**\n```\n' + comment.suggestion_code + '\n```\n\n';
                md += '</details>';
              }

              return md;
            }

After:

            function formatSuggestion(comment) {
              if (!comment.suggestion_code || !comment.existing_code) return '';
              
              let md = '\n\n<details><summary>💡 Suggested Change</summary>\n\n';
              md += '**Before:**\n```\n' + comment.existing_code + '\n```\n\n';
              md += '**After:**\n```\n' + comment.suggestion_code + '\n```\n\n';
              md += '</details>';
              return md;
            }

            function formatComment(comment) {
              let body = comment.content || '';

              // Add code suggestion if available
              if (comment.suggestion_code && comment.existing_code) {
                body += '\n\n**Suggestion:**\n';
                body += '```suggestion\n';
                body += comment.suggestion_code;
                if (!comment.suggestion_code.endsWith('\n')) body += '\n';
                body += '```';
              }

              return body;
            }

            function formatCommentMarkdown(comment) {
              let md = `### 📄 \`${comment.path}\``;
              if (comment.start_line && comment.end_line) {
                md += ` (L${comment.start_line}-L${comment.end_line})`;
              }
              md += '\n\n';
              md += comment.content || '';
              md += formatSuggestion(comment);

              return md;
            }

Comment thread .github/workflows/ocr-review.yml
Comment thread .github/workflows/ocr-review.yml
Comment thread .github/workflows/ocr-review.yml
Comment thread .github/workflows/ocr-review.yml
Comment thread .github/workflows/ocr-review.yml
Comment thread .github/workflows/ocr-review.yml
Comment thread .github/workflows/ocr-review.yml
Comment thread .github/workflows/ocr-review.yml
@zshs000

zshs000 commented Jun 6, 2026

Copy link
Copy Markdown
Owner Author

实测效果可能不是很好,可能是因为模型使用了 MiMo2.5-Pro,但 opus 的渠道不太稳定,先用着吧。

同时这个技术对我来说还是挺新颖的,给了我一些思路。

目前主要存在两个问题:

  1. 结果不一致:同一个 PR,代码没有修改,上一次没有给出意见,这次却给出了
  2. 错误意见无法纠正:审查给出的错误意见没有反馈机制告诉它"这个判断是错的",导致后续审查继续重复同样的错误建议。

@zshs000

zshs000 commented Jun 6, 2026

Copy link
Copy Markdown
Owner Author

同时项目本身存在的审查体系已经能做到充分的审查了,所以这些只是兜底

@zshs000
zshs000 merged commit 30204ea into master Jun 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant