Skip to content

Conversation

@aneeshsunganahalli
Copy link
Contributor

@aneeshsunganahalli aneeshsunganahalli commented Oct 8, 2025

Description

Added a auto commit flag, commit . --auto that automatically commits after the LLM generates the commit message, and a condition has been put autoCommit && !dryRun which prevents auto flag to be called when dry run flag is used.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Other (please describe):

Related Issue

Fixes #88

Changes Made

  • Added the commit . --auto flag for this feature
  • Applied a condition to make sure dry run and auto don't occur at the same time

Testing

  • Tested with Gemini API
  • Tested with Grok API
  • Tested on Windows
  • Tested on Linux
  • Tested on macOS
  • Added/updated tests (if applicable)

Checklist

  • My code follows the project's code style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have tested this in a real Git repository
  • I have read the CONTRIBUTING.md guidelines

Screenshots (if applicable)

image(2)

Additional Notes

Used commits in this PR to test the --auto flag as well.


For Hacktoberfest Participants

  • This PR is submitted as part of Hacktoberfest 2025

Thank you for your contribution! 🎉

Summary by CodeRabbit

  • New Features

    • Added a --auto flag to automatically create a git commit with the generated message; default remains interactive.
    • --auto can be used with --dry-run for previewing (no commit) or alone for hands-free commits.
  • Documentation

    • README updated with "Auto Commit Mode" and examples showing --auto, --dry-run, and their combinations.

- Implements an `autoCommit` flag to automatically commit
- changes after message generation.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 8, 2025

Walkthrough

Adds a new --auto CLI flag, threads its boolean value through RunE into CreateCommitMsg, and implements an automatic git commit path when autoCommit is true. Also updates README usage docs and initializes a package-level HTTP client in internal/groq.

Changes

Cohort / File(s) Summary
CLI flag parsing & wiring
cmd/cli/root.go
Adds --auto flag, reads its value in RunE, and forwards it to CreateCommitMsg(dryRun, autoCommit).
Commit generation + auto-commit logic
cmd/cli/createMsg.go
Updates signature to CreateCommitMsg(dryRun bool, autoCommit bool) and adds branch to run git commit -m <message> (with spinner, output/error handling) when autoCommit is true and not dry-run.
Documentation
README.md
Adds "Auto Commit Mode" and "Combining Flags" documentation describing --auto, its interaction with --dry-run, and usage examples; adjusts placement of LLM setup notes.
HTTP client initialization
internal/groq/groq.go
Introduces package-level httpClient *http.Client, initializes it in init() via internalHTTP.GetClient(), and replaces prior GetClient().Do(req) callsites with httpClient.Do(req) to allow test override.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant CLI as CLI (cmd/cli/root.go)
  participant Creator as CreateCommitMsg

  User->>CLI: run "commit . [--dry-run] [--auto]"
  CLI->>CLI: parse flags (dryRun, auto)
  CLI->>Creator: CreateCommitMsg(dryRun, auto)
  alt dry-run == true
    Creator-->>CLI: generate message only (no git ops)
  else if auto == true
    Creator->>CLI: generate finalMessage
    CLI->>CLI: start spinner
    Creator->>shell: run `git commit -m finalMessage`
    alt git success
      Creator-->>CLI: commit output (success)
      CLI->>User: print commit output
    else git failure
      Creator-->>CLI: commit output (error)
      CLI->>User: print error and fail
    end
  else
    Creator-->>CLI: generate message (interactive/default flow)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Cli interface #46 — Modifies same CLI command and CreateCommitMsg signature; directly related to flag/signature changes.
  • Feature: Dry-Run Added #96 — Contains prior changes around --dry-run and CLI behavior that this change builds upon.

Suggested reviewers

  • DFanso

Poem

I nibble keys at break of dawn,
A flag named "auto" — hop! — is drawn.
Messages penned, then commits spawn,
Dry-run peeks, then those bonds gone.
A rabbit cheers, the code moves on. 🐰

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The modifications in internal/groq/groq.go introduce a new package‐level HTTP client and initialization logic that are unrelated to the auto‐commit flag feature defined in issue #88. These changes fall outside the scope of the linked feature request and do not contribute to the direct commit functionality. Consider moving the groq.go HTTP client refactoring into a separate pull request or clearly documenting its purpose and relevance to maintain focused feature development.
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “Feature: Auto Commit Flag” accurately and concisely describes the primary change of adding a new auto‐commit flag, directly reflecting the main functionality introduced in this pull request. It is clear, specific, and focused on the key enhancement without unnecessary detail or noise.
Linked Issues Check ✅ Passed The pull request fully implements the requirements of issue #88 by adding the --auto flag to trigger an automatic commit after message generation, enforcing mutual exclusion with --dry-run, and updating the CLI invocation accordingly. The documentation, command handling, and underlying function signature changes all align with the linked issue’s objectives.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f38168 and 8631741.

📒 Files selected for processing (1)
  • cmd/cli/root.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
cmd/cli/root.go (1)
cmd/cli/createMsg.go (1)
  • CreateCommitMsg (30-211)
🪛 GitHub Actions: Build and Release
cmd/cli/root.go

[error] 65-65: too many arguments in call to CreateCommitMsg.

🪛 GitHub Check: Build Go Binary (ubuntu-latest)
cmd/cli/root.go

[failure] 65-65:
too many arguments in call to CreateCommitMsg

// Add --dry-run flag to the commit command
creatCommitMsg.Flags().Bool("dry-run", false, "Preview the prompt that would be sent to the LLM without making an API call")

// Add --auto flag to the commid command
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix typo in comment.

"commid" should be "commit".

Apply this diff:

-	// Add --auto flag to the commid command
+	// Add --auto flag to the commit command
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Add --auto flag to the commid command
// Add --auto flag to the commit command
🤖 Prompt for AI Agents
In cmd/cli/root.go around line 84, the inline comment contains a typo: "commid"
should read "commit"; update the comment text to "Add --auto flag to the commit
command" (or equivalent) ensuring only the spelling is corrected and no other
code or formatting is changed.

@DFanso
Copy link
Owner

DFanso commented Oct 8, 2025

hey can we remove the emojis
and build is failing

@aneeshsunganahalli
Copy link
Contributor Author

Yea Im working on it

@DFanso DFanso added enhancement New feature or request hacktoberfest Eligible for Hacktoberfest go Pull requests that update go code labels Oct 8, 2025
@aneeshsunganahalli
Copy link
Contributor Author

Also, there was an issue in the groq folder, I fixed it, should I just include it in this PR?

@DFanso
Copy link
Owner

DFanso commented Oct 8, 2025

sure include that also

@DFanso DFanso self-requested a review October 8, 2025 17:57
@DFanso DFanso added bug Something isn't working hacktoberfest-accepted Approved Hacktoberfest contribution labels Oct 8, 2025
Copy link
Owner

@DFanso DFanso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎊

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8631741 and 8a1b592.

📒 Files selected for processing (3)
  • README.md (1 hunks)
  • cmd/cli/createMsg.go (3 hunks)
  • internal/groq/groq.go (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
internal/groq/groq.go (1)
internal/http/client.go (1)
  • GetClient (32-40)
🔇 Additional comments (3)
internal/groq/groq.go (1)

11-11: LGTM! Good refactor for testability.

The initialization of a package-level httpClient in init() eliminates repeated GetClient() calls and provides a clean override point for tests. Since *http.Client is safe for concurrent use, storing it at package level is appropriate.

Also applies to: 42-48, 91-91

cmd/cli/createMsg.go (2)

212-242: Auto-commit implementation looks solid.

The implementation correctly:

  • Gates auto-commit with autoCommit && !dryRun (line 213)
  • Uses exec.Command with separate arguments (safe from shell injection)
  • Sets working directory and environment for cross-platform compatibility (lines 224, 226)
  • Captures and reports errors appropriately (lines 228-236)
  • Only executes after finalMessage is set through user acceptance (lines 143, 205-207)

The !dryRun check at line 213 is redundant from a pure control-flow perspective (since line 102 returns early if dryRun is true), but it serves as good defensive programming and makes the intent explicit.

Note: The implementation requires user acceptance in the interactive loop before auto-committing, which differs from the README documentation that suggests the interactive review is skipped entirely. This is actually safer behavior, but the documentation should be updated to match (see review comment on README.md).


30-30: Breaking-change verified: All calls to CreateCommitMsg now include the new autoCommit parameter; no further updates required.

Comment on lines +137 to +166
### Auto Commit Mode

Automatically commit with the generated message without manual confirmation:

```bash
commit . --auto
```

This will:
- Generate the commit message using your configured LLM
- Automatically execute `git commit` with the generated message
- Skip the interactive review and manual confirmation step

**Note**: The `--auto` flag cannot be combined with `--dry-run`. Dry run mode takes precedence and will only preview without committing.

**Platform Support**: Works on Linux, macOS, and Windows.

### Combining Flags

```bash
# Preview only (no commit, no API call)
commit . --dry-run

# Generate and auto-commit
commit . --auto

# Generate with interactive review (default behavior)
commit .
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Clarify auto-commit behavior regarding interactive review.

The documentation states that --auto will "Skip the interactive review and manual confirmation step" (line 148), but the implementation in cmd/cli/createMsg.go still presents the interactive loop (accept/regenerate/edit/exit) and only auto-commits after the user accepts the message.

The actual behavior is:

  1. Generate commit message
  2. Present interactive review (user must accept, regenerate, edit, or exit)
  3. If user accepts, copy to clipboard AND auto-commit (if --auto was passed)

This is safer than skipping review entirely, but the documentation should accurately reflect this flow.

Consider revising the documentation to clarify:

 ### Auto Commit Mode
 
 Automatically commit with the generated message without manual confirmation:
 
 ```bash
 commit . --auto

This will:

  • Generate the commit message using your configured LLM
    +- Present the interactive review for you to accept, regenerate, or edit
  • Automatically execute git commit with the generated message
    -- Skip the interactive review and manual confirmation step
    +- Skip the manual git commit step after acceptance

<details>
<summary>🤖 Prompt for AI Agents</summary>

In README.md around lines 137 to 166, the docs incorrectly state that --auto
skips the interactive review; update the text to reflect the actual flow:
generate the commit message, present the interactive review
(accept/regenerate/edit/exit), and if the user accepts, automatically run git commit (i.e., skip the manual git commit step only after acceptance). Replace
the line that says "Skip the interactive review and manual confirmation step"
with wording that clarifies the interactive review is still shown and that
--auto only bypasses the manual git commit after acceptance; keep the note
about --dry-run precedence and platform support as-is.


</details>

<!-- This is an auto-generated comment by CodeRabbit -->

@DFanso DFanso merged commit 2c50506 into DFanso:main Oct 8, 2025
8 checks passed
@aneeshsunganahalli aneeshsunganahalli deleted the feat/auto-commit branch October 8, 2025 18:15
@coderabbitai coderabbitai bot mentioned this pull request Oct 9, 2025
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request go Pull requests that update go code hacktoberfest Eligible for Hacktoberfest hacktoberfest-accepted Approved Hacktoberfest contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add Direct Commit Functionality

2 participants