-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitmessage.js
More file actions
108 lines (100 loc) · 2.7 KB
/
.gitmessage.js
File metadata and controls
108 lines (100 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const path = require('path');
const promptsPath = path.resolve(__dirname, 'node_modules', 'prompts');
const prompts = require(promptsPath);
const { execSync } = require('child_process');
const fs = require('fs');
(async () => {
try {
console.log('Starting commit message prompts...');
const onCancel = () => {
console.log('\nCommit cancelled by user');
process.exit(1);
};
const response = await prompts(
[
{
type: 'text',
name: 'description',
message: 'Enter a description of your changes:',
validate: value =>
value.length >= 10 ||
'Description must be at least 10 characters',
},
{
type: 'select',
name: 'type',
message: 'Select the type of change:',
choices: [
{
title: 'Bug fix (non-breaking change which fixes an issue)',
value: 'bug',
},
{
title: 'New feature (non-breaking change which adds functionality)',
value: 'feature',
},
{ title: 'Breaking change', value: 'breaking' },
{ title: 'Documentation update', value: 'docs' },
{ title: 'Code refactor', value: 'refactor' },
{ title: 'Performance improvement', value: 'perf' },
{ title: 'Dependencies update', value: 'deps' },
],
},
{
type: 'confirm',
name: 'buildCheck',
message:
'Would you like to verify the build before committing?',
initial: true,
},
{
type: 'text',
name: 'notes',
message: 'Additional notes (optional):',
},
],
{
onCancel,
}
);
// Check if we have all required fields
if (!response.description || !response.type) {
console.error('Commit cancelled: Required fields missing');
process.exit(1);
}
// Only run build check if user confirms
if (response.buildCheck) {
console.log('\nRunning build check...');
try {
execSync('npm run build', { stdio: 'inherit' });
console.log('✅ Build successful!');
} catch (error) {
console.error(
'\n❌ Build failed. Please fix errors before committing.'
);
process.exit(1);
}
}
const typeEmoji = {
bug: '🐛',
feature: '✨',
breaking: '💥',
docs: '📚',
refactor: '♻️',
perf: '⚡',
deps: '📦',
};
const commitMessage =
`${typeEmoji[response.type]} ${response.description}\n\n` +
`Type: ${response.type}\n` +
`Build: ${response.buildCheck ? '✅ Verified' : '⏩ Skipped'}\n` +
(response.notes ? `\nNotes: ${response.notes}` : '');
// Write to Git commit message file
fs.writeFileSync('.git/COMMIT_EDITMSG', commitMessage);
console.log('\nCommit message created successfully!');
process.exit(0);
} catch (err) {
console.error('Error during commit:', err);
process.exit(1);
}
})();