-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
73 lines (61 loc) · 1.67 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"context"
"os"
"github.com/workflowkit/issue-assistant/internal/helper"
"github.com/workflowkit/issue-assistant/pkg/logger"
)
func main() {
ctx := context.Background()
logger.SetLogger(logger.ZapLogger)
logger.Log.Info("starting issue assistant")
token := os.Getenv("GITHUB_TOKEN")
if token == "" {
logger.Log.Fatal("GITHUB_TOKEN is required")
}
aiType := os.Getenv("AI_TYPE")
if aiType == "" {
logger.Log.Fatal("AI_TYPE is required")
}
var apiKey string
if aiType == "openai" {
openAIKey := os.Getenv("OPENAI_API_KEY")
if openAIKey == "" {
logger.Log.Fatal("OPENAI_API_KEY is required when using OpenAI")
}
apiKey = openAIKey
} else if aiType == "claude" {
claudeKey := os.Getenv("CLAUDE_API_KEY")
if claudeKey == "" {
logger.Log.Fatal("CLAUDE_API_KEY is required when using Claude")
}
apiKey = claudeKey
} else {
logger.Log.Fatal("AI_TYPE must be either 'openai' or 'claude'")
}
eventPath := os.Getenv("GITHUB_EVENT_PATH")
if eventPath == "" {
logger.Log.Fatal("GITHUB_EVENT_PATH is required")
}
// Convert boolean flags to feature array
var features []helper.Feature
if os.Getenv("ENABLE_COMMENT") == "true" {
features = append(features, helper.FeatureComment)
}
if os.Getenv("ENABLE_LABEL") == "true" {
features = append(features, helper.FeatureLabel)
}
if len(features) == 0 {
logger.Log.Fatal("at least one feature must be enabled")
}
hpr, err := helper.NewHelper(
helper.WithGitHubClient(token),
helper.WithAIService(aiType, apiKey),
helper.WithGitHubEventPath(eventPath),
helper.WithFeatures(features),
)
if err != nil {
logger.Log.Fatalf("failed to create helper: %v", err)
}
hpr.Help(ctx)
}