@@ -17,30 +17,34 @@ import (
1717
1818// main is the entry point of the commit message generator
1919func 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- }
20+ // Validate COMMIT_LLM and required API keys
21+ commitLLM := os .Getenv ("COMMIT_LLM" )
22+ var apiKey string
23+
24+ switch commitLLM {
25+ case "google" :
26+ apiKey = os .Getenv ("GOOGLE_API_KEY" )
27+ if apiKey == "" {
28+ log .Fatalf ("GOOGLE_API_KEY is not set" )
29+ }
30+ case "grok" :
31+ apiKey = os .Getenv ("GROK_API_KEY" )
32+ if apiKey == "" {
33+ log .Fatalf ("GROK_API_KEY is not set" )
34+ }
35+ case "chatgpt" :
36+ apiKey = os .Getenv ("OPENAI_API_KEY" )
37+ if apiKey == "" {
38+ log .Fatalf ("OPENAI_API_KEY is not set" )
39+ }
40+ case "claude" :
41+ apiKey = os .Getenv ("CLAUDE_API_KEY" )
42+ if apiKey == "" {
43+ log .Fatalf ("CLAUDE_API_KEY is not set" )
44+ }
45+ default :
46+ log .Fatalf ("Invalid COMMIT_LLM value: %s" , commitLLM )
47+ }
4448
4549 // Get current directory
4650 currentDir , err := os .Getwd ()
@@ -139,5 +143,4 @@ func main() {
139143
140144 // Display changes preview
141145 display .ShowChangesPreview (fileStats )
142- }
143146}
0 commit comments