@yuki-no/plugin-batch-pr
Version:
Batch PR plugin for yuki-no - Collects opened Yuki-no translation issues and creates a single pull request
29 lines (28 loc) • 1.11 kB
JavaScript
import { Git } from '@yuki-no/plugin-sdk/infra/git';
import { log } from '@yuki-no/plugin-sdk/utils/log';
export const createCommit = (git, { message, allowEmpty = false }) => {
log('I', `createCommit :: Starting commit process with message: "${message}"`);
const emptyFlag = allowEmpty ? '--allow-empty' : '';
const escapedMessage = escapeShellArg(message);
log('I', 'createCommit :: Adding all changes to staging area');
git.exec('add .');
log('I', `createCommit :: Creating commit${allowEmpty ? ' (allow empty)' : ''}`);
git.exec(`commit ${emptyFlag} -m "${escapedMessage}"`);
log('S', 'createCommit :: Commit created successfully');
};
const escapeShellArg = (arg) => arg
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"')
.replace(/'/g, "\\'")
.replace(/`/g, '\\`')
.replace(/\$/g, '\\$')
.replace(/;/g, '\\;')
.replace(/&/g, '\\&')
.replace(/\|/g, '\\|')
.replace(/</g, '\\<')
.replace(/>/g, '\\>')
.replace(/\(/g, '\\(')
.replace(/\)/g, '\\)')
.replace(/\n/g, '\\n')
.replace(/\r/g, '\\r')
.replace(/\t/g, '\\t');