di-sukharev / opencommit

Auto-generate impressive commits with AI in 1 second 🤯🔫
https://www.npmjs.com/package/opencommit
MIT License
5.51k stars 289 forks source link

[Feature]: Add '--yes' or '-y' option to automatically accept AI generated commit messages #292

Open marco76tv opened 5 months ago

marco76tv commented 5 months ago

Description

I propose to add a --yes or -y option to the aic command line utility, which will allow users to automatically accept the first AI generated commit message without requiring interactive input. This feature will be especially useful when aic is integrated into automation scripts or other environments where manual input is not convenient or possible.

Currently, when a user runs aic, they are presented with one or multiple AI-generated commit messages and are asked to select one. While this is a great feature for manual use, it becomes a bottleneck when trying to automate the Git commit process as it requires an interactive terminal to make a choice.

Suggested Solution

oco -y

Alternatives

No response

Additional Context

No response

github-actions[bot] commented 4 months ago

Stale issue message

di-sukharev commented 4 months ago

will look into this, thanks

sebastienfi commented 4 months ago

I also see this as a useful yet dangerous option, but you, "use at your own risks". @marco76tv would you like to propose a PR? Here are some guidelines to get you started. We'll provide you with assistance once you start a PR.

To implement the --yes or -y option for the aic command line utility, allowing users to bypass interactive selection and automatically accept the first AI-generated commit message, you'll need to modify several parts of the codebase. Here's a step-by-step guide based on the provided context:

1. Understanding the Current Interaction Mechanism

The current interaction with users primarily happens in the commit function within ./src/commands/commit.ts. This function uses prompts (from @clack/prompts) to interactively ask users to confirm commit messages or select files to stage.

2. Integrating the --yes or -y Option

To add the --yes or -y option, you'll need to modify the CLI setup in ./src/cli.ts to recognize the new flags and alter the flow based on these flags.

Modifying ./src/cli.ts:

flags: {
  fgm: Boolean,
  yes: Boolean, // Add this line
  y: 'yes' // Alias -y to --yes
},

Handling the Flag in the Commit Process:

// At the beginning of the commit function, add a check for the flag
if (flags.yes) {
  // If the flag is set, automatically select the first AI-generated commit message
  // and bypass any other interactive prompts (e.g., file staging or commit confirmation)
  // You might need to adjust the logic to directly use the first AI-generated message
  // and proceed with the commit without further user interaction.
}

3. Best Practices

4. Testing the Feature

5. Relevant Files and Preliminary Steps

6. Usability and Existing Users

You should be able to implement the --yes or -y option, let us know how this works for you.