mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add option to commit with generic message (#36421)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
50068d0070
commit
8d8b44a5e3
@@ -14,7 +14,13 @@ const path = require('path');
|
||||
const {echo, exec, exit} = require('shelljs');
|
||||
const yargs = require('yargs');
|
||||
|
||||
const {PUBLISH_PACKAGES_TAG} = require('../constants');
|
||||
const {
|
||||
PUBLISH_PACKAGES_TAG,
|
||||
GENERIC_COMMIT_MESSAGE,
|
||||
NO_COMMIT_CHOICE,
|
||||
COMMIT_WITH_GENERIC_MESSAGE_CHOICE,
|
||||
COMMIT_WITH_CUSTOM_MESSAGE_CHOICE,
|
||||
} = require('../constants');
|
||||
const forEachPackage = require('../for-each-package');
|
||||
const checkForGitChanges = require('../check-for-git-changes');
|
||||
const bumpPackageVersion = require('./bump-package-version');
|
||||
@@ -156,33 +162,67 @@ const main = async () => {
|
||||
.prompt([
|
||||
{
|
||||
type: 'list',
|
||||
name: 'shouldSubmitCommit',
|
||||
name: 'commitChoice',
|
||||
message: 'Do you want to submit a commit with these changes?',
|
||||
choices: ['Yes', 'No'],
|
||||
filter: val => val === 'Yes',
|
||||
choices: [
|
||||
{
|
||||
name: 'Yes, with generic message',
|
||||
value: COMMIT_WITH_GENERIC_MESSAGE_CHOICE,
|
||||
},
|
||||
{
|
||||
name: 'Yes, with custom message',
|
||||
value: COMMIT_WITH_CUSTOM_MESSAGE_CHOICE,
|
||||
},
|
||||
{
|
||||
name: 'No',
|
||||
value: NO_COMMIT_CHOICE,
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
.then(({shouldSubmitCommit}) => {
|
||||
if (!shouldSubmitCommit) {
|
||||
echo('Not submitting a commit, but keeping all changes');
|
||||
return;
|
||||
.then(({commitChoice}) => {
|
||||
switch (commitChoice) {
|
||||
case NO_COMMIT_CHOICE: {
|
||||
echo('Not submitting a commit, but keeping all changes');
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case COMMIT_WITH_GENERIC_MESSAGE_CHOICE: {
|
||||
exec(`git commit -am "${GENERIC_COMMIT_MESSAGE}"`, {
|
||||
cwd: ROOT_LOCATION,
|
||||
silent: true,
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case COMMIT_WITH_CUSTOM_MESSAGE_CHOICE: {
|
||||
// exec from shelljs currently does not support interactive input
|
||||
// https://github.com/shelljs/shelljs/wiki/FAQ#running-interactive-programs-with-exec
|
||||
execSync('git commit -a', {cwd: ROOT_LOCATION, stdio: 'inherit'});
|
||||
|
||||
const enteredCommitMessage = exec(
|
||||
'git log -n 1 --format=format:%B',
|
||||
{
|
||||
cwd: ROOT_LOCATION,
|
||||
silent: true,
|
||||
},
|
||||
).stdout.trim();
|
||||
const commitMessageWithTag =
|
||||
enteredCommitMessage + `\n\n${PUBLISH_PACKAGES_TAG}`;
|
||||
|
||||
exec(`git commit --amend -m "${commitMessageWithTag}"`, {
|
||||
cwd: ROOT_LOCATION,
|
||||
silent: true,
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
throw new Error('');
|
||||
}
|
||||
|
||||
// exec from shelljs currently does not support interactive input
|
||||
// https://github.com/shelljs/shelljs/wiki/FAQ#running-interactive-programs-with-exec
|
||||
execSync('git commit -a', {cwd: ROOT_LOCATION, stdio: 'inherit'});
|
||||
|
||||
const enteredCommitMessage = exec('git log -n 1 --format=format:%B', {
|
||||
cwd: ROOT_LOCATION,
|
||||
silent: true,
|
||||
}).stdout.trim();
|
||||
const commitMessageWithTag =
|
||||
enteredCommitMessage + `\n\n${PUBLISH_PACKAGES_TAG}`;
|
||||
|
||||
exec(`git commit --amend -m "${commitMessageWithTag}"`, {
|
||||
cwd: ROOT_LOCATION,
|
||||
silent: true,
|
||||
});
|
||||
})
|
||||
.then(() => echo());
|
||||
}
|
||||
|
||||
@@ -9,5 +9,16 @@
|
||||
*/
|
||||
|
||||
const PUBLISH_PACKAGES_TAG = '#publish-packages-to-npm';
|
||||
const GENERIC_COMMIT_MESSAGE = `bumped packages versions\n\n${PUBLISH_PACKAGES_TAG}`;
|
||||
|
||||
module.exports = {PUBLISH_PACKAGES_TAG};
|
||||
const NO_COMMIT_CHOICE = 'NO_COMMIT';
|
||||
const COMMIT_WITH_GENERIC_MESSAGE_CHOICE = 'COMMIT_WITH_GENERIC_MESSAGE';
|
||||
const COMMIT_WITH_CUSTOM_MESSAGE_CHOICE = 'COMMIT_WITH_CUSTOM_MESSAGE';
|
||||
|
||||
module.exports = {
|
||||
PUBLISH_PACKAGES_TAG,
|
||||
GENERIC_COMMIT_MESSAGE,
|
||||
NO_COMMIT_CHOICE,
|
||||
COMMIT_WITH_GENERIC_MESSAGE_CHOICE,
|
||||
COMMIT_WITH_CUSTOM_MESSAGE_CHOICE,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user