Skip to content

Commit 4f8fc57

Browse files
CodeCasterXclaude
andcommitted
feat(commands): 新增 refine-title 智能标题重构命令
新增 /refine-title 命令,用于深度分析 GitHub Issue 或 PR 的内容, 并将其标题重构为符合 Conventional Commits 规范的格式。 功能特性: - 智能分析 Issue/PR 的 Body、Labels 和文件变更 - 自动推断 type(fix/feat/chore 等) - 自动推断 scope(fit/fel/waterflow 等) - 生成中文 subject,简洁明确 - 交互式确认,避免误操作 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0feaba2 commit 4f8fc57

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

.claude/commands/refine-title.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
name: "refine-title"
3+
description: "深度分析 Issue 或 PR 内容,并将其标题重构为 Conventional Commits 格式"
4+
usage: "/refine-title <id>"
5+
---
6+
7+
# Refine Title Command
8+
9+
## 功能说明
10+
11+
针对指定的 GitHub Issue 或 PR,读取其详细描述(Body)、标签(Labels)以及代码变更(如果是 PR),深度理解其意图,然后生成符合 `type(scope): subject` 规范的新标题并执行修改。
12+
13+
## 执行流程
14+
15+
### 1. 识别对象与获取信息
16+
17+
尝试判断 ID 是 Issue 还是 PR,并获取详细信息。
18+
19+
```bash
20+
# 尝试获取 Issue 信息
21+
gh issue view <id> --json number,title,body,labels,state
22+
23+
# 如果提示是 PR,或者查不到 Issue 但存在同号 PR,则获取 PR 信息
24+
gh pr view <id> --json number,title,body,labels,state,files
25+
```
26+
27+
### 2. 智能分析
28+
29+
根据获取到的 JSON 数据进行分析:
30+
31+
1. **确定 Type (类型)**
32+
- 阅读 `body` 中的 "变更类型" 或描述。
33+
- 检查 `labels` (如 `type: bug` -> `fix`, `type: feature` -> `feat`)。
34+
- 如果是 PR,分析 `files` (仅文档变动 -> `docs`,仅测试变动 -> `test`)。
35+
36+
2. **确定 Scope (范围)**
37+
- 阅读 `body` 提及的模块。
38+
- 检查 `labels` (如 `in: fit` -> `fit`)。
39+
- 如果是 PR,分析 `files` 路径 (如 `framework/fit/java/...` -> `fit`)。
40+
41+
3. **生成 Subject (摘要)**
42+
- **忽略原标题**(避免受干扰),直接从 `body` 中提炼核心意图。
43+
- 确保简练(20字以内)、中文描述、无句号。
44+
45+
### 3. 生成建议与交互
46+
47+
输出分析结果供用户确认:
48+
49+
```text
50+
🔍 分析对象: Issue #<id> / PR #<id>
51+
52+
当前标题: [原标题]
53+
--------------------------------------------------
54+
🧠 分析依据:
55+
- 原始意图: (从 Body 提取的一句话摘要)
56+
- 推断类型: Fix (依据: 标签 type:bug, Body 关键词 "修复")
57+
- 推断范围: fit (依据: 涉及文件路径 framework/fit/...)
58+
--------------------------------------------------
59+
✨ 建议标题: fix(fit): 修复并发场景下的空指针异常
60+
```
61+
62+
询问用户:*"是否确认修改?(y/n)"*
63+
64+
### 4. 执行修改
65+
66+
用户确认(y)后,根据对象类型执行命令:
67+
68+
```bash
69+
# 如果是 Issue
70+
gh issue edit <id> --title "<new-title>"
71+
72+
# 如果是 PR
73+
gh pr edit <id> --title "<new-title>"
74+
```
75+
76+
## 参数说明
77+
78+
- `<id>`: Issue 或 PR 的编号(必需)。
79+
80+
## 使用示例
81+
82+
```bash
83+
# 智能重命名 Issue #1024
84+
/refine-title 1024
85+
```
86+
87+
## 优势
88+
89+
相比于批量修改 (`/normalize-titles`),本命令:
90+
1. **修正错误**:如果原标题是 "Help me",此命令能读懂内容并改为 "fix(core): 修复启动报错"。
91+
2. **更精准的 Scope**:通过分析 PR 的文件变动,能自动判断是 `fit` 还是 `waterflow`,无需人工指定。

0 commit comments

Comments
 (0)