Code Monkey home page Code Monkey logo

Comments (3)

sebastienfi avatar sebastienfi commented on June 15, 2024 1

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.

from opencommit.

github-actions avatar github-actions commented on June 15, 2024

Stale issue message

from opencommit.

di-sukharev avatar di-sukharev commented on June 15, 2024

will look into this, thanks

from opencommit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.