Skip to content

Commit eeb29a8

Browse files
committed
🐛 fix: 添加贡献者和问题id等属性,添加自动分类功能
1 parent e15d0b5 commit eeb29a8

File tree

13 files changed

+811
-254
lines changed

13 files changed

+811
-254
lines changed

.github/copilot-instructions.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Git Commit Helper - AI Coding Instructions
2+
3+
## Project Overview
4+
5+
A **uTools plugin** built with Vue 3 + Vite that helps generate standardized git commit messages with emoji icons. The app runs inside uTools desktop application and provides two views: main commit generator and configuration panel.
6+
7+
## Architecture & Key Concepts
8+
9+
### uTools Plugin Integration
10+
11+
- **Entry point**: `public/plugin.json` defines plugin metadata, features, and entry commands
12+
- **Development mode**: Uses `http://localhost:5173` (configured in `plugin.json`)
13+
- **Production**: Serves from `index.html` after build
14+
- **Preload script**: `public/preload/services.js` injects Node.js capabilities into renderer process via `window.services`
15+
- **Plugin lifecycle**: App uses `window.utools.onPluginEnter()` and `window.utools.onPluginOut()` for navigation
16+
- **Feature codes**: `commit` (main view) and `config` (settings) trigger different views in `App.vue`
17+
18+
### Data Persistence
19+
20+
- **Storage**: Uses `utools.dbStorage` API wrapped in `src/utils/store.js`
21+
- **No backend**: All settings stored locally in uTools database
22+
- **Config keys**: `useIcon`, `isCustomType`, `isCustomIcon`, `isKill`, `customFileUrl`, `customIconUrl`, `hideTip`
23+
24+
### Custom Data Sources
25+
26+
Users can override default commit types and icons via remote JSON URLs:
27+
28+
- Default data: `src/data/commitTypes.json` and `src/data/iconOptions.json`
29+
- Custom URLs fetched at runtime if enabled in config
30+
- Expected format: Array of `{value, label, icon}` objects
31+
32+
## Development Workflow
33+
34+
### Commands
35+
36+
- **Dev server**: `pnpm dev` - Starts Vite on port 5173
37+
- **Build**: `pnpm build` - Creates production bundle in `dist/`
38+
- **Test in uTools**: Run dev server, then trigger plugin with keywords like "feat", "commit", "fix"
39+
40+
### Path Aliasing
41+
42+
- `@` resolves to `src/` directory (configured in `vite.config.js`)
43+
- Use `@/utils/store` instead of `../utils/store`
44+
45+
### Debugging
46+
47+
- **Vue DevTools**: Integrated via `vite-plugin-vue-devtools`
48+
- **Console logging**: Check browser DevTools when running in uTools
49+
- **Entry action payload**: `props.enterAction.payload` contains the keyword used to trigger plugin
50+
51+
## Project-Specific Patterns
52+
53+
### Component Communication
54+
55+
- **Props-based routing**: `App.vue` passes `enterAction` prop to child components
56+
- **No Vue Router**: Simple conditional rendering based on `route.value` from uTools plugin code
57+
- **Payload initialization**: `HomeView` uses `enterAction.payload` to pre-select commit type
58+
59+
### UI Framework
60+
61+
- **Ant Design Vue 4.x**: Use `<a-select>`, `<a-input>`, `<a-textarea>`, `<a-switch>`, etc.
62+
- **Icons**: Import from `@ant-design/icons-vue` (e.g., `SettingFilled`)
63+
- **Messages**: Use `message.success()` for toast notifications
64+
- **Copy interaction**: `<a-typography-paragraph :copyable="...">` with `onCopy` callback
65+
66+
### State Management
67+
68+
- **Composition API**: All components use `<script setup>`
69+
- **Reactive state**: Use `ref()` for all mutable state
70+
- **Computed values**: `generatedCommitMessage` and `generatedGitCommitMessage` auto-update
71+
- **Config defaults**: Use `getData(key) ?? defaultValue` pattern in `ConfigView.vue`
72+
73+
### Commit Message Format
74+
75+
Generated format: `{icon} {type}({scope}): {message}` or `{type}({scope}): {message}`
76+
77+
- Example with icon: `✨ feat(ui): add new button component`
78+
- Example without: `feat(api): add user endpoint`
79+
- Git command output: `git commit -m"{generated message}"`
80+
81+
## Key Files Reference
82+
83+
- `src/App.vue` - Plugin lifecycle and view routing
84+
- `src/components/HomeView.vue` - Main commit generator (200+ lines)
85+
- `src/components/ConfigView.vue` - Settings panel
86+
- `public/plugin.json` - uTools plugin manifest
87+
- `public/preload/services.js` - Node.js API bridge
88+
- `src/utils/store.js` - uTools storage wrapper
89+
90+
## Common Pitfalls
91+
92+
1. **Don't use Vue Router** - uTools plugins use custom routing via `onPluginEnter()`
93+
2. **Don't forget `window.utools` prefix** - All uTools APIs require `window.` or global scope
94+
3. **Base path matters** - Set `base: './'` in Vite config for proper asset loading
95+
4. **Preload script limitations** - Can't use ES modules, must use CommonJS (`require`)
96+
5. **Plugin exit behavior** - Respect `isKill` config when copying (controls auto-hide)
97+
98+
## Testing Plugin Changes
99+
100+
1. Start dev server: `pnpm dev`
101+
2. Open uTools (usually Alt+Space)
102+
3. Type trigger keywords: "feat", "commit", "fix", etc.
103+
4. Plugin should load from `localhost:5173`
104+
5. For config: Type "git commit config"

MIGRATION_NOTES.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# 迁移完成说明
2+
3+
## 已完成的工作
4+
5+
### 1. ✅ 添加 Vue DevTools
6+
- 安装了 `vite-plugin-vue-devtools@8.0.3`
7+
- 升级了 Vite 从 5.4.21 到 7.2.2
8+
-`vite.config.js` 中配置了 DevTools 插件
9+
10+
### 2. ✅ 迁移到 Pinia 状态管理
11+
- 安装了 `pinia@2.x``pinia-plugin-persistedstate@4.7.1`
12+
- 创建了两个 Pinia stores:
13+
- `src/stores/commitTypes.js` - 管理提交类型 CRUD 操作
14+
- `src/stores/settings.js` - 管理应用设置
15+
16+
### 3. ✅ 删除旧的数据文件
17+
- 删除了 `src/data/commitTypes.json`
18+
- 删除了 `src/data/iconOptions.json`
19+
- 删除了整个 `src/data/` 目录
20+
- 删除了 `src/utils/store.js` (uTools storage wrapper)
21+
22+
### 4. ✅ 重构组件
23+
- **HomeView.vue**: 完全重写
24+
- 使用 Pinia stores 替代 uTools storage
25+
- 移除了独立的图标选择器 (图标现在自动绑定到提交类型)
26+
- 添加了提交类型管理功能 (添加/编辑/删除/重置)
27+
- 添加了贡献者和问题ID字段
28+
- 实现了自动分类功能
29+
30+
- **ConfigView.vue**: 完全重构
31+
- 使用 Pinia stores 替代 uTools storage
32+
- 移除了自定义 JSON 源配置 (不再需要)
33+
- 简化了配置界面,只保留核心设置
34+
35+
### 5. ✅ 新增功能
36+
- **提交类型 CRUD**: 用户可以添加、编辑、删除自定义提交类型
37+
- **自动分类**: 根据提交信息关键词自动选择提交类型
38+
- **贡献者自动格式化**: 自动添加 @ 符号
39+
- **问题ID自动格式化**: 自动添加 # 符号
40+
- **数据持久化**: 使用 localStorage 自动保存所有设置
41+
42+
## 技术架构变更
43+
44+
### 之前 (Before)
45+
```
46+
数据存储: utools.dbStorage
47+
配置文件: src/data/*.json
48+
状态管理: 组件内 ref + getData/setData
49+
```
50+
51+
### 之后 (After)
52+
```
53+
数据存储: localStorage (via Pinia persist)
54+
配置数据: Pinia stores (内存 + 持久化)
55+
状态管理: Pinia stores with composition API
56+
```
57+
58+
## 数据迁移
59+
60+
### commitTypes Store
61+
默认包含 11 种提交类型:
62+
- feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
63+
64+
### settings Store
65+
默认设置:
66+
- `useIcon`: true (使用 emoji)
67+
- `autoClassify`: true (启用自动分类)
68+
- `isKill`: true (复制后退出)
69+
- `hideTip`: false (显示提示文本)
70+
- `classifyRules`: 7 种类型的分类规则
71+
72+
## 如何测试
73+
74+
### 1. 启动开发服务器
75+
```bash
76+
pnpm dev
77+
```
78+
79+
### 2. 在 uTools 中测试
80+
- 打开 uTools (Alt+Space)
81+
- 输入触发词: `feat`, `commit`, `fix`
82+
- 应该会加载 `http://localhost:5173`
83+
84+
### 3. 测试功能
85+
- [ ] 选择提交类型
86+
- [ ] 输入提交信息 (测试自动分类)
87+
- [ ] 添加范围、贡献者、问题ID
88+
- [ ] 切换图标开关
89+
- [ ] 切换自动分类开关
90+
- [ ] 点击"管理提交类型"按钮
91+
- [ ] 添加新类型
92+
- [ ] 编辑现有类型
93+
- [ ] 删除类型
94+
- [ ] 重置为默认
95+
- [ ] 复制生成的提交信息
96+
- [ ] 打开配置页面 (输入 `git commit config`)
97+
- [ ] 修改设置并保存
98+
- [ ] 重启插件验证持久化
99+
100+
## 已修复的问题
101+
102+
1.**uTools cloning error**: 不再使用 utools.dbStorage,使用 localStorage 替代
103+
2.**编辑按钮无响应**: 重新实现了编辑功能,使用正确的 v-model 绑定
104+
3.**重置默认错误**: 实现了正确的深拷贝逻辑
105+
4.**图标选择器多余**: 移除了独立选择器,图标自动绑定到类型
106+
107+
## 注意事项
108+
109+
### 用户数据迁移
110+
如果用户之前使用过旧版本,其 utools.dbStorage 中的数据不会自动迁移。
111+
用户需要:
112+
1. 在新版本中重新配置设置
113+
2. 重新添加自定义提交类型 (如果有)
114+
115+
### 端口配置
116+
如果 5173 端口被占用,Vite 会自动使用下一个可用端口 (如 5174)。
117+
记得在 `public/plugin.json` 的 development.main 中更新端口号。
118+
119+
## 文件清单
120+
121+
### 新增文件
122+
- `src/stores/commitTypes.js` (182 行)
123+
- `src/stores/settings.js` (124 行)
124+
- `MIGRATION_NOTES.md` (本文件)
125+
126+
### 修改文件
127+
- `src/main.js` (添加 Pinia 初始化)
128+
- `src/components/HomeView.vue` (完全重写, 340 行)
129+
- `src/components/ConfigView.vue` (重构, 117 行)
130+
- `vite.config.js` (添加 VueDevTools)
131+
- `package.json` (添加 pinia 相关依赖)
132+
133+
### 删除文件
134+
- `src/data/commitTypes.json`
135+
- `src/data/iconOptions.json`
136+
- `src/utils/store.js`
137+
138+
## 下一步建议
139+
140+
1. **添加分类规则编辑器**: 允许用户自定义自动分类规则
141+
2. **导入/导出配置**: 支持配置备份和恢复
142+
3. **提交历史**: 记录最近使用的提交信息
143+
4. **模板功能**: 保存常用的提交信息模板
144+
5. **多语言支持**: 添加英文界面
145+
146+
## 性能优化
147+
148+
- ✅ 使用 Pinia 替代多次 getData/setData 调用
149+
- ✅ 使用 computed 属性自动更新 UI
150+
- ✅ 使用 persist plugin 自动保存,无需手动调用 setData
151+
- ✅ 移除了不必要的网络请求 (自定义 JSON 源)
152+
153+
---
154+
155+
**迁移完成时间**: 2024
156+
**迁移人员**: GitHub Copilot
157+
**测试状态**: 待测试 ⏳

package.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
},
1010
"dependencies": {
1111
"@ant-design/icons-vue": "^7.0.1",
12-
"ant-design-vue": "4.x",
12+
"ant-design-vue": "~4.2.6",
1313
"lodash": "^4.17.21",
14-
"vue": "^3.4.19"
14+
"pinia": "^3.0.4",
15+
"pinia-plugin-persistedstate": "^4.7.1",
16+
"vue": "^3.5.24"
1517
},
1618
"devDependencies": {
17-
"@rollup/plugin-alias": "^5.1.1",
18-
"@vitejs/plugin-vue": "^5.0.4",
19-
"utools-api-types": "^5.2.0",
20-
"vite": "^5.4.11"
19+
"@rollup/plugin-alias": "^6.0.0",
20+
"@vitejs/plugin-vue": "^6.0.1",
21+
"utools-api-types": "^7.2.0",
22+
"vite": "^7.2.2",
23+
"vite-plugin-vue-devtools": "^8.0.3"
2124
}
2225
}

src/App.vue

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
<script lang="ts" setup>
1+
<script setup>
22
import { onMounted, ref } from 'vue';
3+
import { ConfigProvider } from 'ant-design-vue';
34
import HomeView from './components/HomeView.vue';
45
import ConfigView from './components/ConfigView.vue';
6+
57
const route = ref('')
68
const enterAction = ref({})
79
@@ -19,10 +21,12 @@ onMounted(() => {
1921
</script>
2022

2123
<template>
22-
<template v-if="route === 'commit'">
23-
<HomeView :enterAction="enterAction" />
24-
</template>
25-
<template v-if="route === 'config'">
26-
<ConfigView :enterAction="enterAction" />
27-
</template>
24+
<ConfigProvider>
25+
<template v-if="route === 'commit'">
26+
<HomeView :enterAction="enterAction" />
27+
</template>
28+
<template v-if="route === 'config'">
29+
<ConfigView :enterAction="enterAction" />
30+
</template>
31+
</ConfigProvider>
2832
</template>

0 commit comments

Comments
 (0)