Skip to content

Commit 711a388

Browse files
committed
MINOR: fragments: add support for git fragments
1 parent 6c6d3dc commit 711a388

File tree

3 files changed

+88
-3
lines changed

3 files changed

+88
-3
lines changed

.aspell.yml

+2
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ allowed:
2828
- runnumber
2929
- LLC
3030
- devel
31+
- ioutil
32+
- defaultconf

aspell/aspell.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ func (a Aspell) checkSingle(data string, allowedWords []string) error {
113113
}
114114

115115
func (a Aspell) Check(subjects []string, commitsFull []string, content []map[string]string) error {
116+
var commitsFullData []string
117+
for _, c := range commitsFull {
118+
c2 := strings.TrimSpace(c)
119+
if c2 == "" ||
120+
strings.HasPrefix(c2, "Signed-off-by:") ||
121+
strings.HasPrefix(c2, "Reviewed-by:") ||
122+
strings.HasPrefix(c2, "Tested-by:") ||
123+
strings.HasPrefix(c2, "Helped-by:") ||
124+
strings.HasPrefix(c2, "Reported-by:") ||
125+
strings.HasPrefix(c2, "Author:") ||
126+
strings.HasPrefix(c2, "Co-authored-by:") {
127+
continue
128+
}
129+
commitsFullData = append(commitsFullData, c)
130+
}
131+
116132
var response string
117133
var checks []string
118134
switch a.Mode {
@@ -121,7 +137,7 @@ func (a Aspell) Check(subjects []string, commitsFull []string, content []map[str
121137
case modeSubject:
122138
checks = subjects
123139
case modeCommit:
124-
checks = commitsFull
140+
checks = commitsFullData
125141
case modeAll:
126142
for _, file := range content {
127143
for name, v := range file {
@@ -146,7 +162,7 @@ func (a Aspell) Check(subjects []string, commitsFull []string, content []map[str
146162
}
147163
}
148164
}
149-
checks = commitsFull
165+
checks = commitsFullData
150166
default:
151167
checks = subjects
152168
}

aspell/aspell_test.go

+68-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package aspell
22

3-
import "testing"
3+
import (
4+
"testing"
5+
)
46

57
func Test_checkWithAspell(t *testing.T) {
68
aspell := Aspell{
@@ -31,3 +33,68 @@ func Test_checkWithAspell(t *testing.T) {
3133
})
3234
}
3335
}
36+
37+
func TestAspell_Check(t *testing.T) {
38+
type fields struct {
39+
Mode mode
40+
MinLength int
41+
IgnoreFiles []string
42+
AllowedWords []string
43+
HelpText string
44+
}
45+
type args struct {
46+
subjects []string
47+
commitsFull []string
48+
content []map[string]string
49+
}
50+
tests := []struct {
51+
name string
52+
fields fields
53+
args args
54+
wantErr bool
55+
}{{
56+
"Signed off",
57+
fields{
58+
Mode: modeCommit,
59+
MinLength: 3,
60+
IgnoreFiles: []string{"config"},
61+
AllowedWords: []string{"config"},
62+
HelpText: "test",
63+
},
64+
args{
65+
subjects: []string{"BUG/MEDIUM: config: add default location of path to the configuration file"},
66+
commitsFull: []string{" Signed-off-by: Author: A locatoin <[email protected]>"},
67+
content: []map[string]string{{"test": "test"}},
68+
},
69+
false,
70+
}, {
71+
"Signed off",
72+
fields{
73+
Mode: modeCommit,
74+
MinLength: 3,
75+
IgnoreFiles: []string{"config"},
76+
AllowedWords: []string{"config"},
77+
HelpText: "test",
78+
},
79+
args{
80+
subjects: []string{"BUG/MEDIUM: config: add default location of path to the configuration file"},
81+
commitsFull: []string{"mitsake", " Signed-off-by: Author: A locatoin <[email protected]>"},
82+
content: []map[string]string{{"test": "test"}},
83+
},
84+
true,
85+
}}
86+
for _, tt := range tests {
87+
t.Run(tt.name, func(t *testing.T) {
88+
a := Aspell{
89+
Mode: tt.fields.Mode,
90+
MinLength: tt.fields.MinLength,
91+
IgnoreFiles: tt.fields.IgnoreFiles,
92+
AllowedWords: tt.fields.AllowedWords,
93+
HelpText: tt.fields.HelpText,
94+
}
95+
if err := a.Check(tt.args.subjects, tt.args.commitsFull, tt.args.content); (err != nil) != tt.wantErr {
96+
t.Errorf("Aspell.Check() error = %v, wantErr %v", err, tt.wantErr)
97+
}
98+
})
99+
}
100+
}

0 commit comments

Comments
 (0)