From 711a38845698d43e633855138bdf1d88447e443e Mon Sep 17 00:00:00 2001 From: Zlatko Bratkovic Date: Mon, 7 Oct 2024 13:31:31 +0200 Subject: [PATCH] MINOR: fragments: add support for git fragments --- .aspell.yml | 2 ++ aspell/aspell.go | 20 +++++++++++-- aspell/aspell_test.go | 69 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 88 insertions(+), 3 deletions(-) diff --git a/.aspell.yml b/.aspell.yml index b9d4240..83f1e10 100644 --- a/.aspell.yml +++ b/.aspell.yml @@ -28,3 +28,5 @@ allowed: - runnumber - LLC - devel + - ioutil + - defaultconf diff --git a/aspell/aspell.go b/aspell/aspell.go index 05bb6bf..f2087a8 100644 --- a/aspell/aspell.go +++ b/aspell/aspell.go @@ -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 { @@ -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 { @@ -146,7 +162,7 @@ func (a Aspell) Check(subjects []string, commitsFull []string, content []map[str } } } - checks = commitsFull + checks = commitsFullData default: checks = subjects } diff --git a/aspell/aspell_test.go b/aspell/aspell_test.go index 1dd475c..1b41fd7 100644 --- a/aspell/aspell_test.go +++ b/aspell/aspell_test.go @@ -1,6 +1,8 @@ package aspell -import "testing" +import ( + "testing" +) func Test_checkWithAspell(t *testing.T) { aspell := Aspell{ @@ -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 "}, + 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 "}, + 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) + } + }) + } +}