Skip to content

Commit 8a1263f

Browse files
authored
Merge pull request #31 from aneeshsunganahalli/fix-inverted-else-clause
Fixed Inverted else clause
2 parents f93c76b + c3eaaf6 commit 8a1263f

2 files changed

Lines changed: 31 additions & 26 deletions

File tree

src/claude/claude.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ func GenerateCommitMessage(config *types.Config, changes string, apiKey string)
6060
req.Header.Set("x-api-key", apiKey)
6161
req.Header.Set("anthropic-version", "2023-06-01")
6262

63-
client := &http.Client{}
6463
client := &http.Client{}
6564
resp, err := client.Do(req)
6665
if err != nil {

src/main.go

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/atotto/clipboard"
88
"github.com/dfanso/commit-msg/src/chatgpt"
9+
"github.com/dfanso/commit-msg/src/claude"
910
"github.com/dfanso/commit-msg/src/gemini"
1011
"github.com/dfanso/commit-msg/src/grok"
1112
"github.com/dfanso/commit-msg/src/internal/display"
@@ -17,30 +18,34 @@ import (
1718

1819
// main is the entry point of the commit message generator
1920
func main() {
20-
// Get API key from environment variables
21-
var apiKey string
22-
if os.Getenv("COMMIT_LLM") == "google" {
23-
apiKey = os.Getenv("GOOGLE_API_KEY")
24-
if apiKey == "" {
25-
log.Fatalf("GOOGLE_API_KEY is not set")
26-
}
27-
} else if os.Getenv("COMMIT_LLM") == "grok" {
28-
apiKey = os.Getenv("GROK_API_KEY")
29-
if apiKey == "" {
30-
log.Fatalf("GROK_API_KEY is not set")
31-
}
32-
} else if os.Getenv("COMMIT_LLM") == "chatgpt" {
33-
apiKey = os.Getenv("OPENAI_API_KEY")
34-
if apiKey == "" {
35-
log.Fatalf("OPENAI_API_KEY is not set")
36-
}
37-
} else if os.Getenv("COMMIT_LLM") == "claude" {
38-
apiKey = os.Getenv("CLAUDE_API_KEY")
39-
if apiKey == "" {
40-
log.Fatalf("CLAUDE_API_KEY is not set")
41-
} else {
42-
log.Fatalf("Invalid COMMIT_LLM value: %s", os.Getenv("COMMIT_LLM"))
43-
}
21+
// Validate COMMIT_LLM and required API keys
22+
commitLLM := os.Getenv("COMMIT_LLM")
23+
var apiKey string
24+
25+
switch commitLLM {
26+
case "google":
27+
apiKey = os.Getenv("GOOGLE_API_KEY")
28+
if apiKey == "" {
29+
log.Fatalf("GOOGLE_API_KEY is not set")
30+
}
31+
case "grok":
32+
apiKey = os.Getenv("GROK_API_KEY")
33+
if apiKey == "" {
34+
log.Fatalf("GROK_API_KEY is not set")
35+
}
36+
case "chatgpt":
37+
apiKey = os.Getenv("OPENAI_API_KEY")
38+
if apiKey == "" {
39+
log.Fatalf("OPENAI_API_KEY is not set")
40+
}
41+
case "claude":
42+
apiKey = os.Getenv("CLAUDE_API_KEY")
43+
if apiKey == "" {
44+
log.Fatalf("CLAUDE_API_KEY is not set")
45+
}
46+
default:
47+
log.Fatalf("Invalid COMMIT_LLM value: %s", commitLLM)
48+
}
4449

4550
// Get current directory
4651
currentDir, err := os.Getwd()
@@ -111,6 +116,8 @@ func main() {
111116
commitMsg, err = gemini.GenerateCommitMessage(config, changes, apiKey)
112117
} else if os.Getenv("COMMIT_LLM") == "chatgpt" {
113118
commitMsg, err = chatgpt.GenerateCommitMessage(config, changes, apiKey)
119+
} else if os.Getenv("COMMIT_LLM") == "claude" {
120+
commitMsg, err = claude.GenerateCommitMessage(config, changes, apiKey)
114121
} else {
115122
commitMsg, err = grok.GenerateCommitMessage(config, changes, apiKey)
116123
}
@@ -139,5 +146,4 @@ func main() {
139146

140147
// Display changes preview
141148
display.ShowChangesPreview(fileStats)
142-
}
143149
}

0 commit comments

Comments
 (0)