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

Feature: Adding noninteractive mode #75

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ aicommits hook uninstall
3. Save and close the editor to commit!


5. Enable non-interactive mode to use automatically the commit retrieved withot review:
`aicommits -y` or `aicommits --noninteractive`

## How it works

This CLI tool runs `git diff` to grab all your latest code changes, sends them to OpenAI's GPT-3, then returns the AI generated commit message.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"eslintConfig": {
"extends": "@pvtnbr",
"rules": {
"unicorn/no-process-exit": "off"
"unicorn/no-process-exit": "off",
"complexity": ["error", { "max": 11 }]
},
"overrides": [
{
Expand Down
7 changes: 7 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ cli(
description: 'Number of messages to generate. (Warning: generating multiple costs more) (default: 1)',
alias: 'g',
},
noninteractive: {
type: Boolean,
description: 'Non interactive mode',
alias: 'y',
default: false,
},
},

commands: [
Expand All @@ -43,6 +49,7 @@ cli(
} else {
aicommits(
argv.flags.generate,
argv.flags.noninteractive,
rawArgv,
);
}
Expand Down
15 changes: 8 additions & 7 deletions src/commands/aicommits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { KnownError, handleCliError } from '../utils/error.js';

export default async (
generate: number | undefined,
noninteractive: boolean | undefined,
rawArgv: string[],
) => (async () => {
intro(bgCyan(black(' aicommits ')));
Expand Down Expand Up @@ -56,19 +57,19 @@ export default async (
let message: string;
if (messages.length === 1) {
[message] = messages;
const confirmed = await confirm({
message: `Use this commit message?\n\n ${message}\n`,
});
const confirmed = noninteractive ? true : await confirm({ message: `Use this commit message?\n\n ${message}\n` });

if (!confirmed || isCancel(confirmed)) {
outro('Commit cancelled');
return;
}
} else {
const selected = await select({
message: `Pick a commit message to use: ${dim('(Ctrl+c to exit)')}`,
options: messages.map(value => ({ label: value, value })),
});
const selected = noninteractive
? messages[1]
nthings marked this conversation as resolved.
Show resolved Hide resolved
: await select({
message: `Pick a commit message to use: ${dim('(Ctrl+c to exit)')}`,
options: messages.map(value => ({ label: value, value })),
});

if (isCancel(selected)) {
outro('Commit cancelled');
Expand Down