Skip to content

Commit

Permalink
MINOR: fragments: add support for git fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
oktalz committed Oct 7, 2024
1 parent 6c6d3dc commit 711a388
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .aspell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ allowed:
- runnumber
- LLC
- devel
- ioutil
- defaultconf
20 changes: 18 additions & 2 deletions aspell/aspell.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ func (a Aspell) checkSingle(data string, allowedWords []string) error {
}

func (a Aspell) Check(subjects []string, commitsFull []string, content []map[string]string) error {
var commitsFullData []string
for _, c := range commitsFull {
c2 := strings.TrimSpace(c)
if c2 == "" ||
strings.HasPrefix(c2, "Signed-off-by:") ||
strings.HasPrefix(c2, "Reviewed-by:") ||
strings.HasPrefix(c2, "Tested-by:") ||
strings.HasPrefix(c2, "Helped-by:") ||
strings.HasPrefix(c2, "Reported-by:") ||
strings.HasPrefix(c2, "Author:") ||
strings.HasPrefix(c2, "Co-authored-by:") {
continue
}
commitsFullData = append(commitsFullData, c)
}

var response string
var checks []string
switch a.Mode {
Expand All @@ -121,7 +137,7 @@ func (a Aspell) Check(subjects []string, commitsFull []string, content []map[str
case modeSubject:
checks = subjects
case modeCommit:
checks = commitsFull
checks = commitsFullData
case modeAll:
for _, file := range content {
for name, v := range file {
Expand All @@ -146,7 +162,7 @@ func (a Aspell) Check(subjects []string, commitsFull []string, content []map[str
}
}
}
checks = commitsFull
checks = commitsFullData
default:
checks = subjects
}
Expand Down
69 changes: 68 additions & 1 deletion aspell/aspell_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package aspell

import "testing"
import (
"testing"
)

func Test_checkWithAspell(t *testing.T) {
aspell := Aspell{
Expand Down Expand Up @@ -31,3 +33,68 @@ func Test_checkWithAspell(t *testing.T) {
})
}
}

func TestAspell_Check(t *testing.T) {
type fields struct {
Mode mode
MinLength int
IgnoreFiles []string
AllowedWords []string
HelpText string
}
type args struct {
subjects []string
commitsFull []string
content []map[string]string
}
tests := []struct {
name string
fields fields
args args
wantErr bool
}{{
"Signed off",
fields{
Mode: modeCommit,
MinLength: 3,
IgnoreFiles: []string{"config"},
AllowedWords: []string{"config"},
HelpText: "test",
},
args{
subjects: []string{"BUG/MEDIUM: config: add default location of path to the configuration file"},
commitsFull: []string{" Signed-off-by: Author: A locatoin <[email protected]>"},
content: []map[string]string{{"test": "test"}},
},
false,
}, {
"Signed off",
fields{
Mode: modeCommit,
MinLength: 3,
IgnoreFiles: []string{"config"},
AllowedWords: []string{"config"},
HelpText: "test",
},
args{
subjects: []string{"BUG/MEDIUM: config: add default location of path to the configuration file"},
commitsFull: []string{"mitsake", " Signed-off-by: Author: A locatoin <[email protected]>"},
content: []map[string]string{{"test": "test"}},
},
true,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := Aspell{
Mode: tt.fields.Mode,
MinLength: tt.fields.MinLength,
IgnoreFiles: tt.fields.IgnoreFiles,
AllowedWords: tt.fields.AllowedWords,
HelpText: tt.fields.HelpText,
}
if err := a.Check(tt.args.subjects, tt.args.commitsFull, tt.args.content); (err != nil) != tt.wantErr {
t.Errorf("Aspell.Check() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

0 comments on commit 711a388

Please sign in to comment.