Skip to content

Conversation

@adeeshperera
Copy link
Contributor

@adeeshperera adeeshperera commented Oct 4, 2025

  • Replaced if-else with switch statement to explicitly handle all providers (gemini, chatgpt, claude, grok)
  • Used existing commitLLM variable instead of multiple os.Getenv calls

Summary by CodeRabbit

  • Refactor
    • Streamlined how the tool selects the AI provider for commit message generation for clearer, more maintainable behavior.
    • Added explicit handling for several popular provider options while preserving the existing fallback when unspecified or unrecognized.
    • No user configuration changes; outputs and performance remain consistent.

adeeshperera and others added 2 commits October 4, 2025 23:21
- Replaced if-else with switch statement to explicitly handle all providers (gemini, chatgpt, claude, grok)
- Used existing commitLLM variable instead of multiple os.Getenv calls
…tch-statement

fix DFanso#22 : convert LLM provider selection to switch statement
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 4, 2025

Walkthrough

Refactors commit message generation dispatch in cmd/commit-msg/main.go from chained environment checks to a switch on the commitLLM variable. Adds explicit cases for "gemini", "chatgpt", and "claude", with a default to "grok". Per-LLM API key retrieval and behavior are preserved.

Changes

Cohort / File(s) Summary
Dispatch refactor: LLM selection
cmd/commit-msg/main.go
Replace environment-based if/else chain with a switch on commitLLM. Add cases for "gemini", "chatgpt", "claude", and a default to "grok". Keep per-provider API key retrieval and generation calls; no exported API changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant CLI as commit-msg CLI
  participant Gemini as Gemini Provider
  participant ChatGPT as ChatGPT Provider
  participant Claude as Claude Provider
  participant Grok as Grok Provider

  Dev->>CLI: Run commit message generation
  CLI->>CLI: Read COMMIT_LLM -> commitLLM
  alt commitLLM == "gemini"
    CLI->>Gemini: Generate message (Gemini API key)
    Gemini-->>CLI: Commit message
  else commitLLM == "chatgpt"
    CLI->>ChatGPT: Generate message (OpenAI API key)
    ChatGPT-->>CLI: Commit message
  else commitLLM == "claude"
    CLI->>Claude: Generate message (Anthropic API key)
    Claude-->>CLI: Commit message
  else
    CLI->>Grok: Generate message (Grok API key)
    Grok-->>CLI: Commit message
  end
  CLI-->>Dev: Output commit message
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • DFanso

Poem

Thump-thump goes my coder heart, hop-hop through the switch I dart,
Ifs to cases, neat and snug, fallback cozy with Grok’s hug.
Keys in paws, I route with cheer,
Commit notes crisp and clear.
(_/) ✨

Pre-merge checks and finishing touches

✅ 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 succinctly describes the primary change—converting the LLM provider selection logic to a switch statement—and directly references the associated issue, making it clear and relevant to the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce1d73e and 4934d22.

📒 Files selected for processing (1)
  • cmd/commit-msg/main.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/commit-msg/main.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build Go Binary (windows-latest)

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

@DFanso DFanso added enhancement New feature or request hacktoberfest Eligible for Hacktoberfest go Pull requests that update go code hacktoberfest-accepted Approved Hacktoberfest contribution labels Oct 4, 2025
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cmd/commit-msg/main.go (1)

50-152: Fix inconsistent indentation.

The code block from line 50 onwards has extra indentation (appears to use tabs where it shouldn't). This is inconsistent with the indentation of the switch statements above and affects code readability.

Run gofmt or your IDE's formatter to correct the indentation:

#!/bin/bash
# Format the Go code
gofmt -w cmd/commit-msg/main.go
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e4248b2 and ce1d73e.

📒 Files selected for processing (1)
  • cmd/commit-msg/main.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
cmd/commit-msg/main.go (4)
internal/claude/claude.go (1)
  • GenerateCommitMessage (33-85)
internal/chatgpt/chatgpt.go (1)
  • GenerateCommitMessage (13-32)
internal/gemini/gemini.go (1)
  • GenerateCommitMessage (13-44)
internal/grok/grok.go (1)
  • GenerateCommitMessage (15-87)
🔇 Additional comments (1)
cmd/commit-msg/main.go (1)

25-48: LGTM with a caveat.

The switch statement correctly validates the LLM provider and retrieves the appropriate API key. However, note that the default case (line 47) will exit the program for any unrecognized or empty COMMIT_LLM value, which impacts the second switch statement's default case (see next comment).

@DFanso DFanso self-requested a review October 4, 2025 18:00
@DFanso DFanso linked an issue Oct 4, 2025 that may be closed by this pull request
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.

@adeeshperera can u check the suggestion and fix the issue

adeeshperera and others added 2 commits October 5, 2025 00:04
Removed the explicit Grok case, keeping Grok as the default fallback provider
refactor: remove explicit Grok case from LLM provider switch
@DFanso DFanso self-requested a review October 4, 2025 18:38
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 🎊

@DFanso DFanso merged commit d1929fe into DFanso:main Oct 4, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

[BUG] Missing Claude provider in message generation switch.

2 participants