fix(healthcheck/nonasciifile): no gitattributes
Some checks failed
build / build (push) Failing after 1m30s
build / trigger-build-image (push) Has been skipped

This commit is contained in:
zzjc1234 2024-10-21 15:42:20 +08:00
parent c8f377245f
commit decadeaef1
2 changed files with 28 additions and 17 deletions

2
go.mod
View File

@ -5,7 +5,6 @@ go 1.23.1
require (
github.com/criyle/go-judge v1.8.5
github.com/denormal/go-gitignore v0.0.0-20180930084346-ae8ad1d07817
github.com/go-git/go-billy/v5 v5.5.0
github.com/go-git/go-git/v5 v5.12.0
github.com/jinzhu/copier v0.4.0
github.com/koding/multiconfig v0.0.0-20171124222453-69c27309b2d7
@ -28,6 +27,7 @@ require (
github.com/fatih/camelcase v1.0.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect

View File

@ -16,18 +16,27 @@ 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 := os.DirFS(".")
f, err := fs.Open(".gitattributes")
if err != nil {
noAttri := false
var matcher gitattributes.Matcher
_, err := os.Stat(".gitattributes")
if os.IsNotExist(err) {
noAttri = true
return nil, err
}
attribute, err := gitattributes.ReadAttributes(f, nil, true)
if err != nil {
return nil, err
}
if !noAttri {
fs := os.DirFS(".")
f, err := fs.Open(".gitattributes")
if err != nil {
return nil, err
}
matcher := gitattributes.NewMatcher(attribute)
attribute, err := gitattributes.ReadAttributes(f, nil, true)
if err != nil {
return nil, err
}
matcher = gitattributes.NewMatcher(attribute)
}
err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
@ -46,14 +55,16 @@ func getNonAscii(root string) ([]string, error) {
return nil
}
relPath, err := filepath.Rel(root, path)
if err != nil {
return err
}
str := strings.Split(relPath, "/")
_, ret := matcher.Match(str, nil)
if ret {
return nil
if !noAttri {
relPath, err := filepath.Rel(root, path)
if err != nil {
return err
}
str := strings.Split(relPath, "/")
_, ret := matcher.Match(str, nil)
if ret {
return nil
}
}
file, err := os.Open(path)