refactor(ci):项目提交名重新升为“约定式提交规范” (Conventional Commits)#288
Conversation
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (2)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
审阅者指南(Reviewer's Guide)重构变更日志(changelog)生成器,使其使用分级的、兼容 Conventional Commits 的分组系统,并改进类型/作用域解析与工程类次级变更的按需渲染,从而让 CI 提交信息与 Conventional Commits 规范保持一致。 分级 Conventional Commits 变更日志生成流程图flowchart TD
A[Commits list
subject messages
ci uses Conventional Commits] --> B[group_commits_by_type]
B --> C{tier1,tier2,other
structure}
C --> D[_render_tier tier1
TIER1_TITLES]
C --> E[_render_tier tier2
TIER2_TITLES]
C --> F[other commits
appended to tier2]
F --> E
G[_get_tag_type current_tag] --> H{tag_type}
D --> I[Changelog markdown]
E --> I
H -->|stable| J[Render tier2
inside details
Engineering section]
H -->|beta alpha ci| K[Render tier2
expanded
Engineering section]
J --> I
K --> I
文件级变更(File-Level Changes)
提示与命令(Tips and commands)与 Sourcery 交互(Interacting with Sourcery)
自定义你的使用体验(Customizing Your Experience)打开你的 dashboard 以:
获取帮助(Getting Help)Original review guide in EnglishReviewer's GuideRefactors the changelog generator to use a tiered, Conventional Commits–aware grouping system with improved type/scope parsing and conditional rendering of secondary (engineering) changes, aligning CI commit messages with the Conventional Commits spec. Flow diagram for tiered Conventional Commits changelog generationflowchart TD
A[Commits list
subject messages
ci uses Conventional Commits] --> B[group_commits_by_type]
B --> C{tier1,tier2,other
structure}
C --> D[_render_tier tier1
TIER1_TITLES]
C --> E[_render_tier tier2
TIER2_TITLES]
C --> F[other commits
appended to tier2]
F --> E
G[_get_tag_type current_tag] --> H{tag_type}
D --> I[Changelog markdown]
E --> I
H -->|stable| J[Render tier2
inside details
Engineering section]
H -->|beta alpha ci| K[Render tier2
expanded
Engineering section]
J --> I
K --> I
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - 我发现了两个问题,并留下了一些高层次的反馈:
group_commits_by_type函数在每次运行时都会为疑似 type/scope 反转打印警告,这在 CI 中可能比较嘈杂;建议将其通过现有的日志机制输出,或者用调试标志(debug flag)进行控制。- 对以
Merge:'开头的 subject 的过滤逻辑在_render_tier和other分支中有重复;可以考虑提取一个小的辅助函数(例如is_merge_commit),或者对commits进行一次预过滤,从而把这条规则集中维护在单一位置。
供 AI Agent 使用的提示(Prompt)
Please address the comments from this code review:
## Overall Comments
- The `group_commits_by_type` function prints a warning for suspected type/scope inversion on every run, which can be noisy in CI; consider routing this through the existing logging mechanism or guarding it behind a debug flag.
- The filtering of `Merge:'` subjects is duplicated in `_render_tier` and the `other` block; consider extracting a small helper (e.g. `is_merge_commit`) or pre-filtering `commits` once to keep this rule maintained in a single place.
## Individual Comments
### Comment 1
<location path="scripts/changelog_generator.py" line_range="77-78" />
<code_context>
+ continue
+
+ # 反转检测:type 是地方词、scope 是行为词 → 自动提升到 Tier 1
+ if type_str in TIER2_TYPES and scope in TIER1_TYPES:
+ print(f"⚠️ 疑似 type/scope 反转: '{subject[:60]}' → 自动提升到 Tier 1,建议改为 {scope}({type_str}):")
+ groups['tier1'][scope].append(commit)
+ elif type_str in TIER1_TYPES:
</code_context>
<issue_to_address>
**suggestion:** Unconditional printing for suspected type/scope reversal may be noisy and hard to control.
This `print` runs on every suspected type/scope reversal and always writes to stdout, which can pollute CI logs or break callers that expect only markdown output.
Please either:
- send this message to stderr,
- guard it with a verbosity/debug flag, or
- collect these warnings and emit them in a controlled way (e.g., a final summary or separate log).
Suggested implementation:
```python
# 反转检测:type 是地方词、scope 是行为词 → 自动提升到 Tier 1
if type_str in TIER2_TYPES and scope in TIER1_TYPES:
print(
f"⚠️ 疑似 type/scope 反转: '{subject[:60]}' → 自动提升到 Tier 1,建议改为 {scope}({type_str}):",
file=sys.stderr,
)
groups['tier1'][scope].append(commit)
elif type_str in TIER1_TYPES:
```
To support `file=sys.stderr`, ensure that at the top of `scripts/changelog_generator.py` you have:
- `import sys`
If there is an existing import block, add `import sys` there in a style consistent with the rest of the file.
</issue_to_address>
### Comment 2
<location path="scripts/changelog_generator.py" line_range="331-335" />
<code_context>
+ grouped = group_commits_by_type(commits)
+ tag_type = _get_tag_type(current_tag)
+
+ def _render_tier(tier_dict, tier_titles):
+ """渲染单个 Tier 内各分组,返回 markdown 字符串"""
+ out = ''
+ for type_key, title in tier_titles.items():
+ type_commits = [
+ c for c in tier_dict.get(type_key, [])
if not c['subject'].startswith("Merge:'")
</code_context>
<issue_to_address>
**suggestion:** The merge-commit filter is duplicated and could be centralized to avoid divergence.
That condition is now hardcoded both in `_render_tier` and in the `other_commits` handling. If the merge pattern changes, both spots must be updated. Consider extracting a helper like `is_merge_commit(subject)` and reusing it to keep the logic consistent and maintainable.
Suggested implementation:
```python
tag_type = _get_tag_type(current_tag)
def _is_merge_commit(commit):
subject = commit.get("subject", "")
return subject.startswith("Merge:'")
def _render_tier(tier_dict, tier_titles):
"""渲染单个 Tier 内各分组,返回 markdown 字符串"""
out = ''
```
```python
type_commits = [
c for c in tier_dict.get(type_key, [])
if not _is_merge_commit(c)
]
```
There is another mention of “merge-commit filter” in the `other_commits` handling that is not shown in the snippet. To fully implement the suggestion, you should:
1. Locate any other merge-commit filters, e.g. conditions like `if not c['subject'].startswith("Merge:'")` or similar.
2. Replace those conditions with calls to `_is_merge_commit` (e.g. `if not _is_merge_commit(c)`), so all merge-detection logic is centralized in the new helper.
</issue_to_address>帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈不断改进评审质量。
Original comment in English
Hey - I've found 2 issues, and left some high level feedback:
- The
group_commits_by_typefunction prints a warning for suspected type/scope inversion on every run, which can be noisy in CI; consider routing this through the existing logging mechanism or guarding it behind a debug flag. - The filtering of
Merge:'subjects is duplicated in_render_tierand theotherblock; consider extracting a small helper (e.g.is_merge_commit) or pre-filteringcommitsonce to keep this rule maintained in a single place.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `group_commits_by_type` function prints a warning for suspected type/scope inversion on every run, which can be noisy in CI; consider routing this through the existing logging mechanism or guarding it behind a debug flag.
- The filtering of `Merge:'` subjects is duplicated in `_render_tier` and the `other` block; consider extracting a small helper (e.g. `is_merge_commit`) or pre-filtering `commits` once to keep this rule maintained in a single place.
## Individual Comments
### Comment 1
<location path="scripts/changelog_generator.py" line_range="77-78" />
<code_context>
+ continue
+
+ # 反转检测:type 是地方词、scope 是行为词 → 自动提升到 Tier 1
+ if type_str in TIER2_TYPES and scope in TIER1_TYPES:
+ print(f"⚠️ 疑似 type/scope 反转: '{subject[:60]}' → 自动提升到 Tier 1,建议改为 {scope}({type_str}):")
+ groups['tier1'][scope].append(commit)
+ elif type_str in TIER1_TYPES:
</code_context>
<issue_to_address>
**suggestion:** Unconditional printing for suspected type/scope reversal may be noisy and hard to control.
This `print` runs on every suspected type/scope reversal and always writes to stdout, which can pollute CI logs or break callers that expect only markdown output.
Please either:
- send this message to stderr,
- guard it with a verbosity/debug flag, or
- collect these warnings and emit them in a controlled way (e.g., a final summary or separate log).
Suggested implementation:
```python
# 反转检测:type 是地方词、scope 是行为词 → 自动提升到 Tier 1
if type_str in TIER2_TYPES and scope in TIER1_TYPES:
print(
f"⚠️ 疑似 type/scope 反转: '{subject[:60]}' → 自动提升到 Tier 1,建议改为 {scope}({type_str}):",
file=sys.stderr,
)
groups['tier1'][scope].append(commit)
elif type_str in TIER1_TYPES:
```
To support `file=sys.stderr`, ensure that at the top of `scripts/changelog_generator.py` you have:
- `import sys`
If there is an existing import block, add `import sys` there in a style consistent with the rest of the file.
</issue_to_address>
### Comment 2
<location path="scripts/changelog_generator.py" line_range="331-335" />
<code_context>
+ grouped = group_commits_by_type(commits)
+ tag_type = _get_tag_type(current_tag)
+
+ def _render_tier(tier_dict, tier_titles):
+ """渲染单个 Tier 内各分组,返回 markdown 字符串"""
+ out = ''
+ for type_key, title in tier_titles.items():
+ type_commits = [
+ c for c in tier_dict.get(type_key, [])
if not c['subject'].startswith("Merge:'")
</code_context>
<issue_to_address>
**suggestion:** The merge-commit filter is duplicated and could be centralized to avoid divergence.
That condition is now hardcoded both in `_render_tier` and in the `other_commits` handling. If the merge pattern changes, both spots must be updated. Consider extracting a helper like `is_merge_commit(subject)` and reusing it to keep the logic consistent and maintainable.
Suggested implementation:
```python
tag_type = _get_tag_type(current_tag)
def _is_merge_commit(commit):
subject = commit.get("subject", "")
return subject.startswith("Merge:'")
def _render_tier(tier_dict, tier_titles):
"""渲染单个 Tier 内各分组,返回 markdown 字符串"""
out = ''
```
```python
type_commits = [
c for c in tier_dict.get(type_key, [])
if not _is_merge_commit(c)
]
```
There is another mention of “merge-commit filter” in the `other_commits` handling that is not shown in the snippet. To fully implement the suggestion, you should:
1. Locate any other merge-commit filters, e.g. conditions like `if not c['subject'].startswith("Merge:'")` or similar.
2. Replace those conditions with calls to `_is_merge_commit` (e.g. `if not _is_merge_commit(c)`), so all merge-detection logic is centralized in the new helper.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Summary by Sourcery
在变更日志生成器中为 Conventional Commit 类型引入分级分组和渲染机制,改善结构并提升对误写提交 scope 情况的处理。
Enhancements:
Original summary in English
Summary by Sourcery
Introduce tiered grouping and rendering for Conventional Commit types in the changelog generator, improving structure and handling of mis-typed commit scopes.
Enhancements: