feat(healthcheck/nonascii): ignore content in gitattributes
Some checks failed
build / build (push) Failing after 48s
build / trigger-build-image (push) Has been skipped

This commit is contained in:
zzjc1234 2024-10-21 15:18:43 +08:00
parent 55e2b38583
commit 348eaa247c

View File

@ -9,7 +9,6 @@ import (
"strings"
"unicode"
"github.com/go-git/go-billy/v5/memfs"
"github.com/go-git/go-git/v5/plumbing/format/gitattributes"
)
@ -17,11 +16,13 @@ import (
// It searches for non-ASCII characters in each file's content and returns a list of paths to files containing non-ASCII characters.
func getNonAscii(root string) ([]string, error) {
var nonAscii []string
fs := memfs.New()
rootPath := []string{"./"}
var emptyStr []string
fs := os.DirFS(".")
f, err := fs.Open(".gitattributes")
if err != nil {
return nil, err
}
attribute, err := gitattributes.ReadPatterns(fs, rootPath)
attribute, err := gitattributes.ReadAttributes(f, nil, true)
if err != nil {
return nil, err
}
@ -45,7 +46,13 @@ func getNonAscii(root string) ([]string, error) {
return nil
}
if _, ret := matcher.Match(rootPath, append(emptyStr, info.Name())); ret {
relPath, err := filepath.Rel(root, path)
if err != nil {
return err
}
str := strings.Split(relPath, "/")
_, ret := matcher.Match(str, nil)
if ret {
return nil
}