@@ -8,99 +8,6 @@ import (
88 "strings"
99)
1010
11- const (
12- MERGE_PATTERN = `^Merge `
13- HEADER_PATTERN = `^((fixup! |squash! )?(\w+)(?:\(([^\)\s]+)\))?: (.+))(?:\n|$)`
14- LINE_LIMIT = 80
15- BODY_REQUIRED = false
16- )
17-
18- type MsgState int
19-
20- const (
21- // normal state
22- Validated MsgState = iota
23- Merge
24- // non format error
25- ArgumentMissing
26- FileMissing
27- ReadError
28- // format error
29- EmptyMessage
30- EmptyHeader
31- BadHeaderFormat
32- WrongType
33- BodyMissing
34- NoBlankLineBeforeBody
35- LineOverLong
36- UndefindedError
37- )
38-
39- var (
40- msgStates = [... ]string {
41- "Validated" ,
42- "Merge" ,
43- "ArgumentMissing" ,
44- "FileMissing" ,
45- "ReadError" ,
46- "EmptyMessage" ,
47- "EmptyHeader" ,
48- "BadHeaderFormat" ,
49- "WrongType" ,
50- "BodyMissing" ,
51- "NoBlankLineBeforeBody" ,
52- "LineOverLong" ,
53- "UndefindedError" ,
54- }
55- stateHint = [... ]string {
56- "%s: commit message meet the rule.\n " ,
57- "%s: merge commit detected,skip check.\n " ,
58- "Error %s: commit message file argument missing.\n " ,
59- "Error %s: file %s not exists.\n " ,
60- "Error %s: read file %s error.\n " ,
61- "Error %s: commit message has no content except whitespaces.\n " ,
62- "Error %s: header (first line) has no content except whitespaces.\n " ,
63- `Error %s: header (first line) not following the rule:
64- %s
65- if you can not find any error after check, maybe you use Chinese colon, or lack of whitespace after the colon.` ,
66- "Error %s: %s, should be one of the keywords:\n %s\n " ,
67- "Error %s: body has no content except whitespaces.\n " ,
68- "Error %s: no empty line between header and body.\n " ,
69- "Error %s: the length of line is %d, exceed %d:\n %s\n " ,
70- "Error %s: unexpected error occurs, please raise an issue." ,
71- }
72- typeList = [... ]string {
73- "feat" , // new feature 新功能
74- "fix" , // fix bug 修复
75- "docs" , // documentation 文档
76- "style" , // changes not affect logic 格式(不影响代码运行的变动)
77- "refactor" , // 重构(既不是新增功能,也不是修改bug的代码变动)
78- "perf" , // performance 提升性能
79- "test" , // 增加测试
80- "chore" , // 构建过程或辅助工具的变动'
81- "revert" , // 撤销以前的 commit
82- "Revert" , // 有些工具生成的 revert 首字母大写
83- }
84- ruleHint = `Commit message rule as follow:
85- <type>(<scope>): <subject>
86- // empty line
87- <body>
88- // empty line
89- <footer>
90-
91- (<scope>), <body> and <footer> are optional
92- <type> must be one of %s
93- more specific instructions, please refer to https://github.com/JayceChant/commit-msg.go`
94- )
95-
96- func (state MsgState ) Name () string {
97- return msgStates [state ]
98- }
99-
100- func (state MsgState ) Hint () string {
101- return stateHint [state ]
102- }
103-
10411func logAndExit (state MsgState , v ... interface {}) {
10512 a := append ([]interface {}{state .Name ()}, v ... )
10613 if state <= Merge {
0 commit comments