1
+ function getMergeCommitsSection (
2
+ allowMergeCommits : boolean ,
3
+ splitChangesInSingleFile : boolean ,
4
+ useEmoji : boolean
5
+ ) {
6
+ const formatExample = useEmoji
7
+ ? "<emoji> <type>(<scope>): <subject>"
8
+ : "<type>(<scope>): <subject>" ;
9
+
10
+ if ( ! allowMergeCommits ) {
11
+ return `### Separate Commits
12
+
13
+ - If multiple file diffs are provided, generate separate commit messages for each file.
14
+ - If only one file diff is provided, ${
15
+ splitChangesInSingleFile
16
+ ? "split different types of changes in the file into separate commit messages"
17
+ : "combine all changes in the file into a single commit message"
18
+ } .
19
+ \`\`\`
20
+ ${ formatExample }
21
+ <body for changes in file>
22
+ \`\`\`
23
+ ` ;
24
+ }
25
+
26
+ return `### Merged Commit
27
+
28
+ If multiple file diffs are provided, merge them into a single commit message:
29
+ \`\`\`
30
+ ${ formatExample }
31
+ <body of merged changes>
32
+ \`\`\`
33
+ ` ;
34
+ }
35
+
36
+ function getVCSExamples (
37
+ vcsType : "svn" | "git" ,
38
+ allowMergeCommits : boolean ,
39
+ splitChangesInSingleFile : boolean ,
40
+ useEmoji : boolean
41
+ ) {
42
+ const exampleContent =
43
+ vcsType === "git"
44
+ ? getGitExamples ( allowMergeCommits , splitChangesInSingleFile , useEmoji )
45
+ : getSVNExamples ( allowMergeCommits , splitChangesInSingleFile , useEmoji ) ;
46
+
47
+ return `### Example (${ vcsType . toUpperCase ( ) } )
48
+
49
+ ${ exampleContent } `;
50
+ }
51
+
52
+ function getGitExamples (
53
+ allowMergeCommits : boolean ,
54
+ splitChangesInSingleFile : boolean ,
55
+ useEmoji : boolean
56
+ ) {
57
+ return allowMergeCommits
58
+ ? getMergedGitExample ( useEmoji )
59
+ : getSeparateGitExample ( splitChangesInSingleFile , useEmoji ) ;
60
+ }
61
+
62
+ function getSVNExamples (
63
+ allowMergeCommits : boolean ,
64
+ splitChangesInSingleFile : boolean ,
65
+ useEmoji : boolean
66
+ ) {
67
+ return allowMergeCommits
68
+ ? getMergedSVNExample ( useEmoji )
69
+ : getSeparateSVNExample ( splitChangesInSingleFile , useEmoji ) ;
70
+ }
71
+
1
72
export function generateCommitMessageSystemPrompt (
2
73
language : string ,
3
74
allowMergeCommits : boolean ,
4
75
splitChangesInSingleFile : boolean ,
5
- vcsType : "svn" | "git"
76
+ vcsType : "svn" | "git" ,
77
+ useEmoji : boolean = true
6
78
) {
7
79
const VCSUpper = vcsType ?. toUpperCase ( ) ;
8
80
return `# ${ VCSUpper } Commit Message Guide
@@ -13,30 +85,7 @@ All output MUST be in ${language} language. You are to act as a pure ${VCSUpper}
13
85
14
86
## Output Format
15
87
16
- ${
17
- allowMergeCommits
18
- ? `### Merged Commit
19
-
20
- If multiple file diffs are provided, merge them into a single commit message:
21
- \`\`\`
22
- <emoji> <type>(<scope>): <subject>
23
- <body of merged changes>
24
- \`\`\`
25
- `
26
- : `### Separate Commits
27
-
28
- - If multiple file diffs are provided, generate separate commit messages for each file.
29
- - If only one file diff is provided, ${
30
- splitChangesInSingleFile
31
- ? "split different types of changes in the file into separate commit messages"
32
- : "combine all changes in the file into a single commit message"
33
- } .
34
- \`\`\`
35
- <emoji> <type>(<scope>): <subject>
36
- <body for changes in file>
37
- \`\`\`
38
- `
39
- }
88
+ ${ getMergeCommitsSection ( allowMergeCommits , splitChangesInSingleFile , useEmoji ) }
40
89
41
90
## File Status Detection
42
91
@@ -69,7 +118,9 @@ By analyzing both the file status and the changes within the file (e.g., diff),
69
118
70
119
## Type Reference
71
120
72
- | Type | Emoji | Description | Example Scopes |
121
+ ${
122
+ useEmoji
123
+ ? `| Type | Emoji | Description | Example Scopes |
73
124
| -------- | ----- | -------------------- | ------------------- |
74
125
| feat | ✨ | New feature | user, payment |
75
126
| fix | 🐛 | Bug fix | auth, data |
@@ -81,7 +132,21 @@ By analyzing both the file status and the changes within the file (e.g., diff),
81
132
| build | 📦 | Build system | webpack, npm |
82
133
| ci | 👷 | CI config | Travis, Jenkins |
83
134
| chore | 🔧 | Other changes | scripts, config |
84
- | i18n | 🌐 | Internationalization | locale, translation |
135
+ | i18n | 🌐 | Internationalization | locale, translation |`
136
+ : `| Type | Description | Example Scopes |
137
+ | -------- | -------------------- | ------------------- |
138
+ | feat | New feature | user, payment |
139
+ | fix | Bug fix | auth, data |
140
+ | docs | Documentation | README, API |
141
+ | style | Code style | formatting |
142
+ | refactor | Code refactoring | utils, helpers |
143
+ | perf | Performance | query, cache |
144
+ | test | Testing | unit, e2e |
145
+ | build | Build system | webpack, npm |
146
+ | ci | CI config | Travis, Jenkins |
147
+ | chore | Other changes | scripts, config |
148
+ | i18n | Internationalization | locale, translation |`
149
+ }
85
150
86
151
## Writing Rules
87
152
@@ -126,13 +191,18 @@ Remember: All output MUST be in ${language} language. You are to act as a pure c
126
191
127
192
## ${ VCSUpper } Examples
128
193
129
- ${
130
- vcsType === "git"
131
- ? `### Example (Git)
194
+ ${ getVCSExamples (
195
+ vcsType ,
196
+ allowMergeCommits ,
197
+ splitChangesInSingleFile ,
198
+ useEmoji
199
+ ) } `;
200
+ }
132
201
133
- ${
134
- allowMergeCommits
135
- ? `#### Merged Commit (allowMergeCommits: true)
202
+ // Helper functions for examples generation (implementations omitted for brevity)
203
+ function getMergedGitExample ( useEmoji : boolean ) {
204
+ const prefix = useEmoji ? "✨ " : "" ;
205
+ return `#### Merged Commit (allowMergeCommits: true)
136
206
137
207
- **Input (Multiple Diffs)**:
138
208
\`\`\`
154
224
155
225
- **Generated Commit Message**:
156
226
\`\`\`
157
- ✨ feat(app): 添加多个新文件
227
+ ${ prefix } feat(app): 添加多个新文件
158
228
- 添加 file1.js 文件
159
229
- 添加 file2.js 文件,包含基础日志输出
160
- \`\`\`
161
- `
162
- : `#### Separate Commits (allowMergeCommits: false)
230
+ \`\`\`` ;
231
+ }
163
232
164
- ${
165
- splitChangesInSingleFile
166
- ? `- **Input (Single File with Multiple Changes)**:
233
+ function getSeparateGitExample (
234
+ splitChangesInSingleFile : boolean ,
235
+ useEmoji : boolean
236
+ ) {
237
+ const featPrefix = useEmoji ? "✨ " : "" ;
238
+ const fixPrefix = useEmoji ? "🐛 " : "" ;
239
+
240
+ if ( splitChangesInSingleFile ) {
241
+ return `- **Input (Single File with Multiple Changes)**:
167
242
\`\`\`
168
243
diff --git a/file.js b/file.js
169
244
index e69de29..b6fc4c6 100644
176
251
177
252
- **Generated Commit Messages**:
178
253
\`\`\`
179
- ✨ feat(file): 添加功能 A
254
+ ${ featPrefix } feat(file): 添加功能 A
180
255
- 在 file.js 中添加了 "Feature A"
181
256
182
- 🐛 fix(file): 修复 B 的问题
257
+ ${ fixPrefix } fix(file): 修复 B 的问题
183
258
- 在 file.js 中修复了与 B 相关的问题
184
- \`\`\`
185
- `
186
- : `- **Input (Single File with Multiple Changes)**:
259
+ \`\`\`` ;
260
+ }
261
+
262
+ return `- **Input (Single File with Multiple Changes)**:
187
263
\`\`\`
188
264
diff --git a/file.js b/file.js
189
265
index e69de29..b6fc4c6 100644
196
272
197
273
- **Generated Commit Message**:
198
274
\`\`\`
199
- ✨ feat(file): 添加功能 A 和修复问题 B
275
+ ${ featPrefix } feat(file): 添加功能 A 和修复问题 B
200
276
- 在 file.js 中添加了 "Feature A"
201
277
- 修复了与 B 相关的问题
202
- \`\`\`
203
- `
278
+ \`\`\`` ;
204
279
}
205
- `
206
- }
207
- `
208
- : `### Example (SVN)
209
280
210
- $ {
211
- allowMergeCommits
212
- ? `#### Merged Commit (allowMergeCommits: true)
281
+ function getMergedSVNExample ( useEmoji : boolean ) {
282
+ const prefix = useEmoji ? "✨ " : "" ;
283
+ return `#### Merged Commit (allowMergeCommits: true)
213
284
214
285
- **Input (Multiple Diffs)**:
215
286
\`\`\`
230
301
231
302
- **Generated Commit Message**:
232
303
\`\`\`
233
- ✨ feat(app): 添加多个新文件
304
+ ${ prefix } feat(app): 添加多个新文件
234
305
- 添加 file1.js 文件
235
306
- 添加 file2.js 文件,包含基础日志输出
236
- \`\`\`
237
- `
238
- : `#### Separate Commits (allowMergeCommits: false)
307
+ \`\`\`` ;
308
+ }
239
309
240
- ${
241
- splitChangesInSingleFile
242
- ? `- **Input (Single File with Multiple Changes)**:
310
+ function getSeparateSVNExample (
311
+ splitChangesInSingleFile : boolean ,
312
+ useEmoji : boolean
313
+ ) {
314
+ const featPrefix = useEmoji ? "✨ " : "" ;
315
+ const fixPrefix = useEmoji ? "🐛 " : "" ;
316
+
317
+ if ( splitChangesInSingleFile ) {
318
+ return `- **Input (Single File with Multiple Changes)**:
243
319
\`\`\`
244
320
Index: file.js
245
321
===================================================================
252
328
253
329
- **Generated Commit Messages**:
254
330
\`\`\`
255
- ✨ feat(file): 添加功能 A
331
+ ${ featPrefix } feat(file): 添加功能 A
256
332
- 在 file.js 中添加了 "Feature A"
257
333
258
- 🐛 fix(file): 修复 B 的问题
334
+ ${ fixPrefix } fix(file): 修复 B 的问题
259
335
- 在 file.js 中修复了与 B 相关的问题
260
- \`\`\`
261
- `
262
- : `- **Input (Single File with Multiple Changes)**:
336
+ \`\`\`` ;
337
+ }
338
+
339
+ return `- **Input (Single File with Multiple Changes)**:
263
340
\`\`\`
264
341
Index: file.js
265
342
===================================================================
272
349
273
350
- **Generated Commit Message**:
274
351
\`\`\`
275
- ✨ feat(file): 添加功能 A 和修复问题 B
352
+ ${ featPrefix } feat(file): 添加功能 A 和修复问题 B
276
353
- 在 file.js 中添加了 "Feature A"
277
- - 修复了与 B 相关的问题
278
- \`\`\`
279
- `
280
- }
281
- `
282
- }
283
- `
284
- }
285
- ` ;
354
+ - 修复了与 B 相��的问题
355
+ \`\`\`` ;
286
356
}
287
357
288
358
export function generateCommitMessageUserPrompt ( language : string ) { }
0 commit comments