-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
86 lines (78 loc) · 2.53 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
86
package main
import (
"fmt"
"log"
"os"
"path"
"github.com/BurntSushi/toml"
)
type analyzerTomlConfig struct {
Category string `toml:"category"`
Name string `toml:"name"`
Shortcode string `toml:"shortcode"`
Version string `toml:"version"`
Description string `toml:"description"`
Logo string `toml:"logo"`
DocumentationURL string `toml:"documentation_url"`
DiscussURL string `toml:"discuss_url"`
AnalysisCommand string `toml:"analysis_command"`
AutofixCommand string `toml:"autofix_command"`
Trigger string `toml:"trigger"`
Processors []string `toml:"processors"`
MinCPULimit int `toml:"min_cpu_limit"`
MaxCPULimit int `toml:"max_cpu_limit"`
MinMemoryLimit int `toml:"min_memory_limit"`
MaxMemoryLimit int `toml:"max_memory_limit"`
MetaSchemaPath string `toml:"meta_schema_path"`
SupportedFiles string `toml:"supported_files"`
DefaultTestPatterns []string `toml:"default_test_patterns"`
Metrics []string `toml:"metrics"`
ExampleConfig string `toml:"example_config"`
IssuesMeta string `toml:"issues_meta"`
StarIssues []string `toml:"star_issues"`
}
func main() {
githubWorkspacePath := os.Getenv("GITHUB_WORKSPACE")
analyzerTomlPath := path.Join(githubWorkspacePath, "analyzer.toml")
var config analyzerTomlConfig
if _, err := toml.DecodeFile(analyzerTomlPath, &config); err != nil {
fmt.Println(err)
return
}
log.Println("Analyzer TOML Parsed.")
// checking the category field
switch config.Category {
case "lang":
case "conf":
case "covg":
default:
log.Fatalln("Error in the \"category\" Field of analyzer.toml")
}
// checking the triggers
switch config.Trigger {
case "code":
case "data":
default:
log.Fatalln("Error in the \"trigger\" Field of analyzer.toml. Acceptable values are - \"code\" and \"data\"")
}
// checking the processors
for _, processor := range config.Processors {
switch processor {
case "source_code_load":
case "skip_cq":
default:
log.Fatalln("Error in the \"processors\" Field of analyzer.toml. Acceptable values are - \"source_code_load\" and \"skip_cq\"")
}
}
// checking the metrics
for _, metric := range config.Metrics {
switch metric {
case "DCV":
case "DDP":
case "IDP":
case "TCV":
default:
log.Fatalln("Error in the \"metrics\" Field of analyzer.toml. Acceptable values are - \"DCV\", \"DDP\", \"IDP\" and \"TCV\"")
}
}
}