@waron97/prbot 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/commands/commit.js +139 -90
package/README.md
CHANGED
|
@@ -118,7 +118,7 @@ Options:
|
|
|
118
118
|
|
|
119
119
|
### `prbot commit`
|
|
120
120
|
|
|
121
|
-
Interactive commit builder. Prompts for operation type (`[IMP]`, `[FIX]`, etc.),
|
|
121
|
+
Interactive commit builder. Prompts for operation type (`[IMP]`, `[FIX]`, etc.), and a message. The destinatin module will be automatically detected. If nothing is staged, shows unstaged files and lets you select which to stage first. Previews the final commit message before confirming.
|
|
122
122
|
|
|
123
123
|
```bash
|
|
124
124
|
prbot commit
|
package/package.json
CHANGED
package/src/commands/commit.js
CHANGED
|
@@ -13,133 +13,182 @@ const commitOperations = [
|
|
|
13
13
|
},
|
|
14
14
|
{ name: `📖 DOC ${chalk.gray('- Documentation changes')}`, value: '[DOC]' },
|
|
15
15
|
{ name: `🩹 FIX ${chalk.gray('- Bugfix or hotfix')}`, value: '[FIX]' },
|
|
16
|
-
{ name: `🛠️
|
|
16
|
+
{ name: `🛠️ IMP ${chalk.gray('- Improvement of existing code')}`, value: '[IMP]' },
|
|
17
17
|
{ name: `💬 I18N ${chalk.gray('- Translation changes')}`, value: '[I18N]' },
|
|
18
18
|
{ name: `📦 MIG ${chalk.gray('- Module migration')}`, value: '[MIG]' },
|
|
19
19
|
{ name: `🔄 REF ${chalk.gray('- Code refactoring')}`, value: '[REF]' },
|
|
20
20
|
{ name: `🎉 REL ${chalk.gray('- Release commit')}`, value: '[REL]' },
|
|
21
|
-
{ name: `🗑️
|
|
22
|
-
{ name: `✏️
|
|
21
|
+
{ name: `🗑️ REM ${chalk.gray('- Removing unnecessary files')}`, value: '[REM]' },
|
|
22
|
+
{ name: `✏️ REN ${chalk.gray('- Renaming files/variables/models/etc.')}`, value: '[REN]' },
|
|
23
23
|
{ name: `🔙 REV ${chalk.gray('- Revert of an existing commit')}`, value: '[REV]' },
|
|
24
24
|
{ name: `🧳 SUB ${chalk.gray('- Submodule adding/updating')}`, value: '[SUB]' },
|
|
25
|
-
{ name: `#️⃣
|
|
25
|
+
{ name: `#️⃣ VER ${chalk.gray('- Versioning')}`, value: '[VER]' },
|
|
26
26
|
];
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
{ name: '📋 Module', value: 'module' },
|
|
31
|
-
{ name: '👤 Wizard', value: 'wizard' },
|
|
32
|
-
{ name: '⚙️ Symphony Process', value: 'symphony' },
|
|
33
|
-
];
|
|
28
|
+
function getModuleFromFile(file) {
|
|
29
|
+
const parts = file.split('/');
|
|
34
30
|
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
if (parts[0] === 'config') {
|
|
32
|
+
return parts[1];
|
|
33
|
+
}
|
|
37
34
|
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
if (parts[0] === '.cloudbuild') {
|
|
36
|
+
const allIndex = parts.indexOf('all');
|
|
40
37
|
|
|
41
|
-
|
|
38
|
+
if (allIndex !== -1) {
|
|
39
|
+
return parts.slice(0, allIndex + 1).join('/');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return parts[0];
|
|
44
|
+
}
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
function validateSameModule(files) {
|
|
47
|
+
const modules = files.map(getModuleFromFile);
|
|
48
|
+
const currentModule = `[${modules[0]}]`;
|
|
49
|
+
|
|
50
|
+
const allSameModule = modules.every((module) => `[${module}]` === currentModule);
|
|
51
|
+
|
|
52
|
+
if (!allSameModule) {
|
|
53
|
+
console.log(chalk.red('Selected files are not of the same module'));
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return currentModule;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function getFilesToCommit(stagedChanges, unstagedChanges) {
|
|
61
|
+
if (stagedChanges.trim()) {
|
|
62
|
+
console.log(chalk.green('Staged changes:'));
|
|
63
|
+
console.log(stagedChanges);
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
filesToCheck: stagedChanges.trim().split('\n'),
|
|
67
|
+
filesToStage: [],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const unstagedFiles = unstagedChanges.trim().split('\n');
|
|
72
|
+
|
|
73
|
+
while (true) {
|
|
44
74
|
console.log(chalk.yellow('No staged changes found.'));
|
|
45
75
|
console.log(chalk.yellow('Unstaged changes:'));
|
|
46
76
|
console.log(unstagedChanges);
|
|
47
77
|
|
|
48
|
-
|
|
78
|
+
const answers = await inquirer.prompt([
|
|
49
79
|
{
|
|
50
80
|
message: 'Select unstaged files to stage for commit:',
|
|
51
81
|
type: 'checkbox',
|
|
52
82
|
name: 'filesToStage',
|
|
53
|
-
choices:
|
|
54
|
-
.trim()
|
|
55
|
-
.split('\n')
|
|
56
|
-
.map((file) => file),
|
|
83
|
+
choices: unstagedFiles,
|
|
57
84
|
},
|
|
58
85
|
]);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
86
|
+
|
|
87
|
+
const currentModule = validateSameModule(answers.filesToStage);
|
|
88
|
+
|
|
89
|
+
if (currentModule) {
|
|
90
|
+
return {
|
|
91
|
+
filesToCheck: answers.filesToStage,
|
|
92
|
+
filesToStage: answers.filesToStage,
|
|
93
|
+
currentModule,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
62
96
|
}
|
|
97
|
+
}
|
|
63
98
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
{
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
99
|
+
async function commit() {
|
|
100
|
+
const ADDONS_PATH = resolveAddonsPath(process.env.ADDONS_PATH);
|
|
101
|
+
|
|
102
|
+
while (true) {
|
|
103
|
+
const unstagedChanges = await execGit(['diff', '--name-only'], ADDONS_PATH);
|
|
104
|
+
const stagedChanges = await execGit(['diff', '--cached', '--name-only'], ADDONS_PATH);
|
|
105
|
+
|
|
106
|
+
if (!unstagedChanges.trim() && !stagedChanges.trim()) {
|
|
107
|
+
console.log(chalk.red('No changes found to commit.'));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const {
|
|
112
|
+
filesToCheck,
|
|
113
|
+
filesToStage,
|
|
114
|
+
currentModule: selectedModule,
|
|
115
|
+
} = await getFilesToCommit(stagedChanges, unstagedChanges);
|
|
116
|
+
|
|
117
|
+
if (filesToCheck.length === 0) {
|
|
118
|
+
console.log(chalk.red('No files selected.'));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let currentModule = selectedModule || validateSameModule(filesToCheck);
|
|
123
|
+
|
|
124
|
+
if (!currentModule) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const answers = await inquirer.prompt([
|
|
129
|
+
{
|
|
130
|
+
type: 'search-list',
|
|
131
|
+
message: 'Select an operation:',
|
|
132
|
+
name: 'commitOperation',
|
|
133
|
+
choices: commitOperations,
|
|
84
134
|
},
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
135
|
+
{
|
|
136
|
+
type: 'input',
|
|
137
|
+
message: 'Please enter your message:',
|
|
138
|
+
name: 'commitMessage',
|
|
139
|
+
filter: (input) => input.trim(),
|
|
140
|
+
when(answers) {
|
|
141
|
+
return answers.commitOperation !== '[DOC]';
|
|
142
|
+
},
|
|
89
143
|
},
|
|
90
|
-
|
|
91
|
-
let value = input.trim();
|
|
144
|
+
]);
|
|
92
145
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
146
|
+
if (answers.commitOperation === '[DOC]') {
|
|
147
|
+
currentModule = '[CHANGELOG]';
|
|
148
|
+
answers.commitMessage = 'Changelog';
|
|
149
|
+
}
|
|
96
150
|
|
|
97
|
-
|
|
98
|
-
value = `${value}]`;
|
|
99
|
-
}
|
|
151
|
+
const commitMessage = `${answers.commitOperation}${currentModule} ${answers.commitMessage}`;
|
|
100
152
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
message: 'Please enter your message:',
|
|
107
|
-
name: 'commitMessage',
|
|
108
|
-
filter: (input) => input.trim(),
|
|
109
|
-
when(answers) {
|
|
110
|
-
return answers.commitOperation !== '[DOC]';
|
|
153
|
+
const finalPrompt = await inquirer.prompt([
|
|
154
|
+
{
|
|
155
|
+
type: 'confirm',
|
|
156
|
+
message: `${chalk.red(commitMessage)}\nDo you want to proceed with this commit message?`,
|
|
157
|
+
name: 'confirmCommit',
|
|
111
158
|
},
|
|
112
|
-
|
|
113
|
-
]);
|
|
159
|
+
]);
|
|
114
160
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
161
|
+
if (!finalPrompt.confirmCommit) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
119
164
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
165
|
+
if (filesToStage.length > 0) {
|
|
166
|
+
await execGit(['add', ...filesToStage], ADDONS_PATH);
|
|
167
|
+
}
|
|
123
168
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
169
|
+
await execGit(['commit', '-m', commitMessage], ADDONS_PATH);
|
|
170
|
+
console.log(chalk.green('Commit created successfully!'));
|
|
127
171
|
|
|
128
|
-
|
|
172
|
+
const remainingUnstaged = await execGit(['diff', '--name-only'], ADDONS_PATH);
|
|
173
|
+
const remainingStaged = await execGit(['diff', '--cached', '--name-only'], ADDONS_PATH);
|
|
129
174
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
name: 'confirmCommit',
|
|
135
|
-
},
|
|
136
|
-
]);
|
|
175
|
+
if (!remainingUnstaged.trim() && !remainingStaged.trim()) {
|
|
176
|
+
console.log(chalk.green('No more changes to commit.'));
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
137
179
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
180
|
+
const { continueCommit } = await inquirer.prompt([
|
|
181
|
+
{
|
|
182
|
+
type: 'confirm',
|
|
183
|
+
name: 'continueCommit',
|
|
184
|
+
message: 'Do you want to create another commit?',
|
|
185
|
+
default: true,
|
|
186
|
+
},
|
|
187
|
+
]);
|
|
188
|
+
|
|
189
|
+
if (!continueCommit) {
|
|
190
|
+
break;
|
|
141
191
|
}
|
|
142
|
-
await execGit(['commit', '-m', commitMessage], ADDONS_PATH);
|
|
143
192
|
}
|
|
144
193
|
}
|
|
145
194
|
|