Skip to content

Commit 8d8b44a

Browse files
hoxyqfacebook-github-bot
authored andcommitted
Add option to commit with generic message (#36421)
Summary: Pull Request resolved: #36421 Changelog: [Internal] Adding an extra choice for commit question, user can now choose between three options: 1. Commit with generic message, no further actions needed 2. Commit with custom message, intercative VIM input will open 3. Not committing anything Reviewed By: cortinico Differential Revision: D43943526 fbshipit-source-id: 014215105d192961486b7d1c697f491697492812
1 parent 50068d0 commit 8d8b44a

File tree

2 files changed

+76
-25
lines changed

2 files changed

+76
-25
lines changed

scripts/monorepo/bump-all-updated-packages/index.js

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ const path = require('path');
1414
const {echo, exec, exit} = require('shelljs');
1515
const yargs = require('yargs');
1616

17-
const {PUBLISH_PACKAGES_TAG} = require('../constants');
17+
const {
18+
PUBLISH_PACKAGES_TAG,
19+
GENERIC_COMMIT_MESSAGE,
20+
NO_COMMIT_CHOICE,
21+
COMMIT_WITH_GENERIC_MESSAGE_CHOICE,
22+
COMMIT_WITH_CUSTOM_MESSAGE_CHOICE,
23+
} = require('../constants');
1824
const forEachPackage = require('../for-each-package');
1925
const checkForGitChanges = require('../check-for-git-changes');
2026
const bumpPackageVersion = require('./bump-package-version');
@@ -156,33 +162,67 @@ const main = async () => {
156162
.prompt([
157163
{
158164
type: 'list',
159-
name: 'shouldSubmitCommit',
165+
name: 'commitChoice',
160166
message: 'Do you want to submit a commit with these changes?',
161-
choices: ['Yes', 'No'],
162-
filter: val => val === 'Yes',
167+
choices: [
168+
{
169+
name: 'Yes, with generic message',
170+
value: COMMIT_WITH_GENERIC_MESSAGE_CHOICE,
171+
},
172+
{
173+
name: 'Yes, with custom message',
174+
value: COMMIT_WITH_CUSTOM_MESSAGE_CHOICE,
175+
},
176+
{
177+
name: 'No',
178+
value: NO_COMMIT_CHOICE,
179+
},
180+
],
163181
},
164182
])
165-
.then(({shouldSubmitCommit}) => {
166-
if (!shouldSubmitCommit) {
167-
echo('Not submitting a commit, but keeping all changes');
168-
return;
183+
.then(({commitChoice}) => {
184+
switch (commitChoice) {
185+
case NO_COMMIT_CHOICE: {
186+
echo('Not submitting a commit, but keeping all changes');
187+
188+
break;
189+
}
190+
191+
case COMMIT_WITH_GENERIC_MESSAGE_CHOICE: {
192+
exec(`git commit -am "${GENERIC_COMMIT_MESSAGE}"`, {
193+
cwd: ROOT_LOCATION,
194+
silent: true,
195+
});
196+
197+
break;
198+
}
199+
200+
case COMMIT_WITH_CUSTOM_MESSAGE_CHOICE: {
201+
// exec from shelljs currently does not support interactive input
202+
// https://github.com/shelljs/shelljs/wiki/FAQ#running-interactive-programs-with-exec
203+
execSync('git commit -a', {cwd: ROOT_LOCATION, stdio: 'inherit'});
204+
205+
const enteredCommitMessage = exec(
206+
'git log -n 1 --format=format:%B',
207+
{
208+
cwd: ROOT_LOCATION,
209+
silent: true,
210+
},
211+
).stdout.trim();
212+
const commitMessageWithTag =
213+
enteredCommitMessage + `\n\n${PUBLISH_PACKAGES_TAG}`;
214+
215+
exec(`git commit --amend -m "${commitMessageWithTag}"`, {
216+
cwd: ROOT_LOCATION,
217+
silent: true,
218+
});
219+
220+
break;
221+
}
222+
223+
default:
224+
throw new Error('');
169225
}
170-
171-
// exec from shelljs currently does not support interactive input
172-
// https://github.com/shelljs/shelljs/wiki/FAQ#running-interactive-programs-with-exec
173-
execSync('git commit -a', {cwd: ROOT_LOCATION, stdio: 'inherit'});
174-
175-
const enteredCommitMessage = exec('git log -n 1 --format=format:%B', {
176-
cwd: ROOT_LOCATION,
177-
silent: true,
178-
}).stdout.trim();
179-
const commitMessageWithTag =
180-
enteredCommitMessage + `\n\n${PUBLISH_PACKAGES_TAG}`;
181-
182-
exec(`git commit --amend -m "${commitMessageWithTag}"`, {
183-
cwd: ROOT_LOCATION,
184-
silent: true,
185-
});
186226
})
187227
.then(() => echo());
188228
}

scripts/monorepo/constants.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,16 @@
99
*/
1010

1111
const PUBLISH_PACKAGES_TAG = '#publish-packages-to-npm';
12+
const GENERIC_COMMIT_MESSAGE = `bumped packages versions\n\n${PUBLISH_PACKAGES_TAG}`;
1213

13-
module.exports = {PUBLISH_PACKAGES_TAG};
14+
const NO_COMMIT_CHOICE = 'NO_COMMIT';
15+
const COMMIT_WITH_GENERIC_MESSAGE_CHOICE = 'COMMIT_WITH_GENERIC_MESSAGE';
16+
const COMMIT_WITH_CUSTOM_MESSAGE_CHOICE = 'COMMIT_WITH_CUSTOM_MESSAGE';
17+
18+
module.exports = {
19+
PUBLISH_PACKAGES_TAG,
20+
GENERIC_COMMIT_MESSAGE,
21+
NO_COMMIT_CHOICE,
22+
COMMIT_WITH_GENERIC_MESSAGE_CHOICE,
23+
COMMIT_WITH_CUSTOM_MESSAGE_CHOICE,
24+
};

0 commit comments

Comments
 (0)