feat: vendor gitea 1.16.2
This commit is contained in:
@@ -4,12 +4,13 @@
|
||||
package analyze
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"path"
|
||||
|
||||
"github.com/go-enry/go-enry/v2"
|
||||
)
|
||||
|
||||
// GetCodeLanguage detects code language based on file name and content
|
||||
// It can be slow when the content is used for detection
|
||||
func GetCodeLanguage(filename string, content []byte) string {
|
||||
if language, ok := enry.GetLanguageByExtension(filename); ok {
|
||||
return language
|
||||
@@ -23,5 +24,5 @@ func GetCodeLanguage(filename string, content []byte) string {
|
||||
return enry.OtherLanguage
|
||||
}
|
||||
|
||||
return enry.GetLanguage(filepath.Base(filename), content)
|
||||
return enry.GetLanguage(path.Base(filename), content)
|
||||
}
|
||||
|
||||
@@ -4,10 +4,28 @@
|
||||
package analyze
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/go-enry/go-enry/v2"
|
||||
)
|
||||
|
||||
// IsVendor returns whether or not path is a vendor path.
|
||||
func IsVendor(path string) bool {
|
||||
return enry.IsVendor(path)
|
||||
// IsVendor returns whether the path is a vendor path.
|
||||
// It uses go-enry's IsVendor function but overrides its detection for certain
|
||||
// special cases that shouldn't be marked as vendored in the diff view.
|
||||
func IsVendor(treePath string) bool {
|
||||
if !enry.IsVendor(treePath) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Override detection for single files
|
||||
basename := path.Base(treePath)
|
||||
switch basename {
|
||||
case ".gitignore", ".gitattributes", ".gitmodules":
|
||||
return false
|
||||
}
|
||||
if strings.HasPrefix(treePath, ".github/") || strings.HasPrefix(treePath, ".gitea/") {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ func TestIsVendor(t *testing.T) {
|
||||
path string
|
||||
want bool
|
||||
}{
|
||||
// Original go-enry test cases
|
||||
{"cache/", true},
|
||||
{"random/cache/", true},
|
||||
{"cache", false},
|
||||
@@ -34,6 +35,14 @@ func TestIsVendor(t *testing.T) {
|
||||
{"a/docs/_build/", true},
|
||||
{"a/dasdocs/_build-vsdoc.js", true},
|
||||
{"a/dasdocs/_build-vsdoc.j", false},
|
||||
|
||||
// Override: Git/GitHub/Gitea-related paths should NOT be detected as vendored
|
||||
{".gitignore", false},
|
||||
{".gitattributes", false},
|
||||
{".gitmodules", false},
|
||||
{"src/.gitignore", false},
|
||||
{".github/workflows/ci.yml", false},
|
||||
{".gitea/workflows/ci.yml", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.path, func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user