-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
78 lines (66 loc) · 1.84 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
package main
import (
"fmt"
"log"
"os"
"path"
"github.com/haproxytech/check-commit/v5/aspell"
"github.com/haproxytech/check-commit/v5/version"
)
func main() {
err := version.Set()
if err != nil {
log.Fatal(err)
}
if len(os.Args) == 2 {
for _, arg := range os.Args[1:] {
if arg == "version" {
fmt.Println("check-commit", version.Version)
fmt.Println("built from:", version.Repo)
fmt.Println("commit date:", version.CommitDate)
os.Exit(0)
}
if arg == "tag" {
fmt.Println(version.Tag)
os.Exit(0)
}
}
}
log.SetFlags(log.LstdFlags | log.Lshortfile)
var repoPath string
if len(os.Args) < requiredCmdlineArgs {
repoPath = "."
} else {
repoPath = os.Args[1]
}
aspellCheck, err := aspell.New(path.Join(repoPath, ".aspell.yml"))
if err != nil {
log.Fatalf("error reading aspell exceptions: %s", err)
}
commitPolicy, err := LoadCommitPolicy(path.Join(repoPath, ".check-commit.yml"))
if err != nil {
log.Fatalf("error reading configuration: %s", err)
}
if commitPolicy.IsEmpty() {
log.Printf("WARNING: using empty configuration (i.e. no verification)")
}
gitEnv, err := readGitEnvironment()
if err != nil {
log.Fatalf("couldn't auto-detect running environment, please set GITHUB_REF and GITHUB_BASE_REF manually: %s", err)
}
subjects, messages, content, err := getCommitData(gitEnv)
if err != nil {
log.Fatalf("error getting commit data: %s", err)
}
if err := commitPolicy.CheckSubjectList(subjects); err != nil {
log.Printf("encountered one or more commit message errors\n")
log.Fatalf("%s\n", commitPolicy.HelpText)
}
err = aspellCheck.Check(subjects, messages, content)
if err != nil {
log.Printf("encountered one or more commit message spelling errors\n")
// log.Fatalf("%s\n", err)
log.Fatalf("%s\n", aspellCheck.HelpText)
}
log.Printf("check completed without errors\n")
}