opencommit icon indicating copy to clipboard operation
opencommit copied to clipboard

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

Open marco76tv opened this issue 1 year ago • 3 comments

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

marco76tv avatar Jan 08 '24 09:01 marco76tv

Stale issue message

github-actions[bot] avatar Feb 17 '24 21:02 github-actions[bot]

will look into this, thanks

di-sukharev avatar Feb 28 '24 11:02 di-sukharev

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:

  • Add the new flags to the flags object within the cli function call. This will allow the CLI to recognize --yes and -y as valid options.
flags: {
  fgm: Boolean,
  yes: Boolean, // Add this line
  y: 'yes' // Alias -y to --yes
},

Handling the Flag in the Commit Process:

  • In the commit function within ./src/commands/commit.ts, check if the --yes or -y flag is set and adjust the flow accordingly.
// 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

  • Backward Compatibility: Ensure that adding this option does not alter the default behavior for existing users. The interactive mode should remain the default unless the --yes or -y flag is explicitly used.
  • Clear Documentation: Update the CLI's help text and any associated documentation to explain the new option and its intended use case.
  • Error Handling: Consider scenarios where the AI might not generate any commit messages or generates an error. Ensure there's graceful handling for these cases, even in non-interactive mode.

4. Testing the Feature

  • Unit Tests: Add unit tests for the new flag, ensuring that it correctly alters the command's flow.
  • Integration Tests: Test the command in a CI/CD pipeline setup to verify it works as expected in automated environments. Mock the AI response to simulate different scenarios, including success, no messages generated, and error responses.

5. Relevant Files and Preliminary Steps

  • ./src/cli.ts: To register the new flag and its behavior.
  • ./src/commands/commit.ts: To modify the commit process based on the flag.
  • Preliminary Steps: Before coding, sketch out the logic changes and how they interact with existing code. Consider any edge cases, such as no AI-generated messages available.

6. Usability and Existing Users

  • Ensure the introduction of the --yes or -y option is communicated clearly in the version release notes.
  • Provide examples of how to use the new option in automation scripts or CI/CD pipelines, helping users integrate it smoothly into their workflows.

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

sebastienfi avatar Mar 04 '24 10:03 sebastienfi