Skip to content

Commit e8458cd

Browse files
committed
refactor: move the configs into config.go
1 parent 8c9376f commit e8458cd

2 files changed

Lines changed: 94 additions & 93 deletions

File tree

commit-msg.go

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
10411
func logAndExit(state MsgState, v ...interface{}) {
10512
a := append([]interface{}{state.Name()}, v...)
10613
if state <= Merge {

config.go

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

0 commit comments

Comments
 (0)