chore(package.json): update version to 1.1.18
refactor(commit.ts): rename getStagedGitDiff to getChangedFiles and remove unused import of generateCommitMessageWithChatCompletion refactor(commit.ts): reformat import statements for better readability refactor(commit.ts): reformat code for better readability feat(commit.ts): add support for selecting remote to push to when multiple remotes are available refactor(commit.ts): remove unnecessary code and fix formatting feat(commit.ts): add support for extraArgs parameter in generateCommitMessageFromGitDiff function chore(checkIsLatestVersion.ts): update console message for clarity and readability fix(git.ts): handle empty output from git command fix(git.ts): add -- argument to git diff command to handle file names with leading hyphens refactor(mergeStrings.ts): remove unnecessary whitespace and add missing semicolon
This commit is contained in:
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "opencommit",
|
"name": "opencommit",
|
||||||
"version": "1.1.16",
|
"version": "1.1.18",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "opencommit",
|
"name": "opencommit",
|
||||||
"version": "1.1.16",
|
"version": "1.1.18",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@clack/prompts": "^0.6.1",
|
"@clack/prompts": "^0.6.1",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "opencommit",
|
"name": "opencommit",
|
||||||
"version": "1.1.16",
|
"version": "1.1.18",
|
||||||
"description": "GPT CLI to auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
|
"description": "GPT CLI to auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"git",
|
"git",
|
||||||
|
|||||||
+60
-32
@@ -3,8 +3,22 @@ import {
|
|||||||
GenerateCommitMessageErrorEnum,
|
GenerateCommitMessageErrorEnum,
|
||||||
generateCommitMessageWithChatCompletion
|
generateCommitMessageWithChatCompletion
|
||||||
} from '../generateCommitMessageFromGitDiff';
|
} from '../generateCommitMessageFromGitDiff';
|
||||||
import { assertGitRepo, getStagedGitDiff, getDiff, getStagedFiles, gitAdd } from '../utils/git';
|
import {
|
||||||
import { spinner, confirm, outro, isCancel, intro, multiselect, select } from '@clack/prompts';
|
assertGitRepo,
|
||||||
|
getChangedFiles,
|
||||||
|
getDiff,
|
||||||
|
getStagedFiles,
|
||||||
|
gitAdd
|
||||||
|
} from '../utils/git';
|
||||||
|
import {
|
||||||
|
spinner,
|
||||||
|
confirm,
|
||||||
|
outro,
|
||||||
|
isCancel,
|
||||||
|
intro,
|
||||||
|
multiselect,
|
||||||
|
select
|
||||||
|
} from '@clack/prompts';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import { trytm } from '../utils/trytm';
|
import { trytm } from '../utils/trytm';
|
||||||
|
|
||||||
@@ -53,44 +67,58 @@ ${chalk.grey('——————————————————')}`
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (isCommitConfirmedByUser && !isCancel(isCommitConfirmedByUser)) {
|
if (isCommitConfirmedByUser && !isCancel(isCommitConfirmedByUser)) {
|
||||||
const { stdout } = await execa('git', ['commit', '-m', commitMessage, ...extraArgs]);
|
const { stdout } = await execa('git', [
|
||||||
|
'commit',
|
||||||
|
'-m',
|
||||||
|
commitMessage,
|
||||||
|
...extraArgs
|
||||||
|
]);
|
||||||
|
|
||||||
outro(`${chalk.green('✔')} successfully committed`);
|
outro(`${chalk.green('✔')} successfully committed`);
|
||||||
|
|
||||||
outro(stdout);
|
outro(stdout);
|
||||||
const remotes = await getGitRemotes();
|
const remotes = await getGitRemotes();
|
||||||
|
|
||||||
if (remotes.length === 1) {
|
if (remotes.length === 1) {
|
||||||
const isPushConfirmedByUser = await confirm({
|
const isPushConfirmedByUser = await confirm({
|
||||||
message: 'Do you want to run `git push`?'
|
message: 'Do you want to run `git push`?'
|
||||||
});
|
|
||||||
|
|
||||||
if (isPushConfirmedByUser && !isCancel(isPushConfirmedByUser)) {
|
|
||||||
const pushSpinner = spinner();
|
|
||||||
pushSpinner.start(`Running \`git push ${remotes[0]}\``);
|
|
||||||
const { stdout } = await execa('git', ['push', remotes[0]]);
|
|
||||||
pushSpinner.stop(`${chalk.green('✔')} successfully pushed all commits to ${remotes[0]}`);
|
|
||||||
if (stdout) outro(stdout);
|
|
||||||
} else {
|
|
||||||
const selectedRemote = await select({
|
|
||||||
message: 'Choose a remote to push to',
|
|
||||||
choices: remotes.map((remote) => ({ title: remote, value: remote })),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (isPushConfirmedByUser && !isCancel(isPushConfirmedByUser)) {
|
||||||
|
const pushSpinner = spinner();
|
||||||
|
pushSpinner.start(`Running \`git push ${remotes[0]}\``);
|
||||||
|
const { stdout } = await execa('git', ['push', remotes[0]]);
|
||||||
|
pushSpinner.stop(
|
||||||
|
`${chalk.green('✔')} successfully pushed all commits to ${remotes[0]}`
|
||||||
|
);
|
||||||
|
if (stdout) outro(stdout);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const selectedRemote = (await select({
|
||||||
|
message: 'Choose a remote to push to',
|
||||||
|
options: remotes.map((remote) => ({ value: remote, label: remote }))
|
||||||
|
})) as string;
|
||||||
|
|
||||||
if (!isCancel(selectedRemote)) {
|
if (!isCancel(selectedRemote)) {
|
||||||
const pushSpinner = spinner();
|
const pushSpinner = spinner();
|
||||||
pushSpinner.start(`Running \`git push ${selectedRemote}\``);
|
pushSpinner.start(`Running \`git push ${selectedRemote}\``);
|
||||||
const { stdout } = await execa('git', ['push', selectedRemote]);
|
const { stdout } = await execa('git', ['push', selectedRemote]);
|
||||||
pushSpinner.stop(`${chalk.green('✔')} successfully pushed all commits to ${selectedRemote}`);
|
pushSpinner.stop(
|
||||||
|
`${chalk.green(
|
||||||
|
'✔'
|
||||||
|
)} successfully pushed all commits to ${selectedRemote}`
|
||||||
|
);
|
||||||
|
|
||||||
|
if (stdout) outro(stdout);
|
||||||
if (stdout) outro(stdout);
|
} else outro(`${chalk.gray('✖')} process cancelled`);
|
||||||
}
|
}
|
||||||
} else outro(`${chalk.gray('✖')} process cancelled`);
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export async function commit(
|
||||||
export async function commit(extraArgs=[], isStageAllFlag = false) {
|
extraArgs: string[] = [],
|
||||||
|
isStageAllFlag: Boolean = false
|
||||||
|
) {
|
||||||
if (isStageAllFlag) {
|
if (isStageAllFlag) {
|
||||||
const changedFiles = await getChangedFiles();
|
const changedFiles = await getChangedFiles();
|
||||||
|
|
||||||
@@ -129,7 +157,6 @@ export async function commit(extraArgs=[], isStageAllFlag = false) {
|
|||||||
isStageAllAndCommitConfirmedByUser &&
|
isStageAllAndCommitConfirmedByUser &&
|
||||||
!isCancel(isStageAllAndCommitConfirmedByUser)
|
!isCancel(isStageAllAndCommitConfirmedByUser)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
await commit(extraArgs, true);
|
await commit(extraArgs, true);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
@@ -158,10 +185,11 @@ export async function commit(extraArgs=[], isStageAllFlag = false) {
|
|||||||
.join('\n')}`
|
.join('\n')}`
|
||||||
);
|
);
|
||||||
|
|
||||||
await generateCommitMessageFromGitDiff(staged.diff);
|
|
||||||
}
|
|
||||||
const [, generateCommitError] = await trytm(
|
const [, generateCommitError] = await trytm(
|
||||||
generateCommitMessageFromGitDiff(await getDiff({ files: stagedFiles }), extraArgs)
|
generateCommitMessageFromGitDiff(
|
||||||
|
await getDiff({ files: stagedFiles }),
|
||||||
|
extraArgs
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (generateCommitError) {
|
if (generateCommitError) {
|
||||||
|
|||||||
@@ -11,11 +11,9 @@ export const checkIsLatestVersion = async () => {
|
|||||||
console.warn(
|
console.warn(
|
||||||
chalk.yellow(
|
chalk.yellow(
|
||||||
`
|
`
|
||||||
You are not using the latest stable version of OpenCommit!
|
You are not using the latest stable version of OpenCommit with new features and bug fixes.
|
||||||
Consider updating to the latest version to get the latest features and bug fixes.
|
Current version: ${currentVersion}. Latest version: ${latestVersion}.
|
||||||
Current version: ${currentVersion}
|
🚀 To update run: npm i -g opencommit@latest.
|
||||||
Latest version: ${latestVersion}
|
|
||||||
🎉 To update to the latest version, run: npm update opencommit
|
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
+6
-4
@@ -20,10 +20,10 @@ export const getOpenCommitIgnore = (): Ignore => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
ig.add(readFileSync('.opencommitignore').toString().split('\n'));
|
ig.add(readFileSync('.opencommitignore').toString().split('\n'));
|
||||||
} catch(e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
return ig;
|
return ig;
|
||||||
}
|
};
|
||||||
|
|
||||||
export const getStagedFiles = async (): Promise<string[]> => {
|
export const getStagedFiles = async (): Promise<string[]> => {
|
||||||
const { stdout: files } = await execa('git', [
|
const { stdout: files } = await execa('git', [
|
||||||
@@ -33,11 +33,12 @@ export const getStagedFiles = async (): Promise<string[]> => {
|
|||||||
'--relative'
|
'--relative'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if (!files) return [];
|
||||||
|
|
||||||
const filesList = files.split('\n');
|
const filesList = files.split('\n');
|
||||||
|
|
||||||
|
|
||||||
const ig = getOpenCommitIgnore();
|
const ig = getOpenCommitIgnore();
|
||||||
const allowedFiles = filesList.filter(file => !ig.ignores(file));
|
const allowedFiles = filesList.filter((file) => !ig.ignores(file));
|
||||||
|
|
||||||
if (!allowedFiles) return [];
|
if (!allowedFiles) return [];
|
||||||
|
|
||||||
@@ -86,6 +87,7 @@ export const getDiff = async ({ files }: { files: string[] }) => {
|
|||||||
const { stdout: diff } = await execa('git', [
|
const { stdout: diff } = await execa('git', [
|
||||||
'diff',
|
'diff',
|
||||||
'--staged',
|
'--staged',
|
||||||
|
'--',
|
||||||
...filesWithoutLocks
|
...filesWithoutLocks
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ export function mergeStrings(arr: string[], maxStringLength: number): string[] {
|
|||||||
currentItem = item;
|
currentItem = item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mergedArr.push(currentItem);
|
mergedArr.push(currentItem);
|
||||||
|
|
||||||
return mergedArr;
|
return mergedArr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user