-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
85 lines (69 loc) · 2.04 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
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"os"
"strconv"
"strings"
"github.com/flagship-io/codebase-analyzer/pkg/config"
"github.com/flagship-io/codebase-analyzer/pkg/handler"
"github.com/joho/godotenv"
log "github.com/sirupsen/logrus"
)
func extractConfig() *config.Config {
cfg := &config.Config{
FlagshipAPIURL: "https://api.flagship.io",
FlagshipAuthAPIURL: "https://auth.flagship.io",
FlagshipClientID: os.Getenv("FLAGSHIP_CLIENT_ID"),
FlagshipClientSecret: os.Getenv("FLAGSHIP_CLIENT_SECRET"),
FlagshipAPIToken: os.Getenv("FS_AUTH_ACCESS_TOKEN"),
FlagshipAccountID: os.Getenv("ACCOUNT_ID"),
FlagshipEnvironmentID: os.Getenv("ENVIRONMENT_ID"),
Directory: ".",
RepositoryURL: os.Getenv("REPOSITORY_URL"),
RepositoryBranch: "master",
FilesToExclude: []string{".git"},
NbLineCodeEdges: 1,
SearchCustomRegex: os.Getenv("CUSTOM_REGEX_JSON"),
}
if os.Getenv("FS_API") != "" {
cfg.FlagshipAPIURL = os.Getenv("FS_API")
}
if os.Getenv("FS_AUTH_API") != "" {
cfg.FlagshipAuthAPIURL = os.Getenv("FS_AUTH_API")
}
if os.Getenv("REPOSITORY_BRANCH") != "" {
cfg.RepositoryBranch = os.Getenv("REPOSITORY_BRANCH")
}
if os.Getenv("FILES_TO_EXCLUDE") != "" {
cfg.FilesToExclude = strings.Split(os.Getenv("FILES_TO_EXCLUDE"), ",")
}
if os.Getenv("DIRECTORY") != "" {
cfg.Directory = os.Getenv("DIRECTORY")
}
if os.Getenv("NB_CODE_LINES_EDGES") != "" {
cfg.NbLineCodeEdges, _ = strconv.Atoi(os.Getenv("NB_CODE_LINES_EDGES"))
}
return cfg
}
func main() {
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
})
log.SetLevel(log.WarnLevel)
if err := godotenv.Load(); err != nil {
log.Info("Fail to load .env file")
}
levelString := os.Getenv("LOG_LEVEL")
if levelString != "" {
lvl, err := log.ParseLevel(levelString)
if err != nil {
log.Fatalf("log level %s is invalid", levelString)
}
log.SetLevel(lvl)
}
cfg := extractConfig()
cfg.Validate()
err := handler.AnalyzeCode(cfg)
if err != nil {
log.Fatalf("Analyser failed with error: %v", err)
}
}