SuperAPI AI Directory

refactor-code-review

Coding & development

View repository

Updated 10-15 19:58

About this skill

Refactoring and Code Review

For PR submissions and periodic repository reviews, analyze current implementation and architecture issues, and output analysis reports and refactoring optimization suggestions.

Use Cases

  • PR Review: For each submitted pull request, focus on implementation quality and architectural consistency within the scope of changes
  • Pull an existing PR: Pull the remote branch based on the PR URL, switch to that branch, and then perform review and refactoring
  • Periodic review: Conduct an architecture- and implementation-level examination of the entire repository

Analysis Dimensions

PR-level review (change-driven)

Dimension Focus
Implementation consistency Whether the changes are consistent with the existing style and patterns
Dependency introduction Whether new dependencies are necessary and whether they introduce circular dependencies
Boundaries and exceptions Whether error handling and boundary conditions are sufficient
Testability Whether the changes are easy to unit test and integration test
Backward compatibility Whether interface/behavior changes are compatible with existing usage

Repository review (architecture-driven)

Dimension Focus
Layering and responsibilities Whether module boundaries are clear and whether layering principles are violated
Coupling Whether coupling between modules is too high and whether circular dependencies exist
Extensibility Whether adding new features requires extensive modifications
Duplicate code Whether there is common logic that can be extracted
Technical debt Outdated patterns, TODOs, temporary implementations, etc.

Analysis Report Template

# [项目/PR] 重构分析报告

## 概览
- **审视范围**: [PR #xxx / 代码仓路径]
- **审视日期**: YYYY-MM-DD
- **风险等级**: 🔴 高 / 🟡 中 / 🟢 低

## 一、发现的问题

### 1. [问题类别]
- **位置**: 文件路径:行号
- **描述**: 具体问题说明
- **影响**: 对质量、维护性、性能的影响
- **建议**: 具体重构或优化建议

### 2. ...
(按优先级排序)

## 二、架构层面

- **当前结构**: 简要描述
- **问题点**: 列出主要架构问题
- **改进方向**: 高层次的改进建议

## 三、重构优先级建议

| 优先级 | 项目 | 预估工作量 | 预期收益 |
|--------|------|------------|----------|
| P0 | ... | ... | ... |
| P1 | ... | ... | ... |
| P2 | ... | ... | ... |

## 四、总结与行动计划

- 关键结论(3–5 条)
- 建议的下一步行动

Workflow

Process for pulling an existing PR

When the user provides a PR URL (such as https://gitcode.com/Ascend/RecSDK/pull/2303/diffs), first pull the PR branch before performing the analysis:

  1. Parse the PR URL: Extract the repository URL and PR number from the URL (such as Ascend/RecSDK、2303)
  2. Update remote code:git fetch origin
  3. Pull the PR branch:git fetch https://gitcode.com/Ascend/RecSDK.git +refs/merge-requests/2303/head:pr_2303
    • Replace 2303 with the actual PR number; the local branch name is pr_2303
    • GitLab/GitCode use refs/merge-requests/; GitHub uses refs/pull/2303/head
  4. Switch to the PR branch:git checkout pr_2303
  5. Perform review: Analyze and generate the report according to the "PR Review Process" below

Determining the target branch

The PR diff needs to be compared with the target branch (merge target). The target branch should:

  • Prefer extracting from the user request: For example, "merge into the develop branch …/pull/2303/diffs" → the target branch is develop; "PR #100 merged into main" → main
  • Common phrasing: merge into/merging into/merge to X branch, with target base as X
  • When unclear: Ask the user (for example, "What is the PR's target merge branch? Default is main"), or use the repository convention main / master / develop

Obtain the PR change scope and diff

Use upstream as the comparison branch, based on upstream's target branch (the PR will be merged into that branch of the upstream repository):

On the PR branch (such as pr_2303), use the following command (BASE_BRANCH Replace with the above target branch, such as develop):

# 确保 upstream 已配置,无则添加:git remote add upstream <仓库URL>
git fetch upstream

# 变更文件列表(含状态:A=新增, M=修改, D=删除)
git diff --name-status upstream/BASE_BRANCH...HEAD

# 带增删行数统计
git diff --stat upstream/BASE_BRANCH...HEAD

# 完整 diff(可重定向到文件)
git diff upstream/BASE_BRANCH...HEAD

Specified directory:git diff upstream/BASE_BRANCH...HEAD -- path/to/dir/

PR review process

  1. Determine the change scope: Use the command in the previous section to get the diff and identify the changed files
  2. File-by-file analysis: Check the implementation and dependencies against the above PR dimensions
  3. Context correlation: Assess the impact scope in combination with the call chain and dependency relationships
  4. Generate a report: Fill it in according to the template, highlighting findings related to this PR

Code repository review process

  1. Understand the project structure: Read the README, main entry points, and directory structure
  2. Identify core modules: Find the core business, shared libraries, and boundary layers
  3. Dependency and coupling analysis: Sort out module dependencies and identify circular dependencies and high coupling
  4. Patterns and duplication: Look for duplicate implementations and extractable patterns
  5. Generate a report: Fill it in according to the template, focusing on architecture and long-term maintainability

Output specifications

  • Issue severity: 🔴 Must fix / 🟡 Recommended fix / 🟢 Can optimize
  • Suggestions must be specific: Provide executable steps or code examples, and avoid vague statements
  • Quantification first: If quantities, proportions, or impact scope can be provided, quantify them as much as possible
  • Language: The main body of the report uses Chinese, and technical terms remain in English

Additional reference

  • For more detailed architecture analysis patterns and anti-patterns, see reference.md