Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to commit with generic message #36421

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 64 additions & 24 deletions scripts/monorepo/bump-all-updated-packages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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());
}
Expand Down
13 changes: 12 additions & 1 deletion scripts/monorepo/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};