mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Go: Move IsGolangVendorDirectory to util package
This commit is contained in:
@@ -3,24 +3,12 @@ package configurebaseline
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/github/codeql-go/extractor/util"
|
"github.com/github/codeql-go/extractor/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func fileExists(path string) bool {
|
|
||||||
stat, err := os.Stat(path)
|
|
||||||
return err == nil && stat.Mode().IsRegular()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decides if `dirPath` is a vendor directory by testing whether it is called `vendor`
|
|
||||||
// and contains a `modules.txt` file.
|
|
||||||
func isGolangVendorDirectory(dirPath string) bool {
|
|
||||||
return filepath.Base(dirPath) == "vendor" && fileExists(filepath.Join(dirPath, "modules.txt"))
|
|
||||||
}
|
|
||||||
|
|
||||||
type BaselineConfig struct {
|
type BaselineConfig struct {
|
||||||
PathsIgnore []string `json:"paths-ignore"`
|
PathsIgnore []string `json:"paths-ignore"`
|
||||||
}
|
}
|
||||||
@@ -38,7 +26,7 @@ func GetConfigBaselineAsJSON(rootDir string) ([]byte, error) {
|
|||||||
// it will not be extracted either.
|
// it will not be extracted either.
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if isGolangVendorDirectory(dirPath) {
|
if util.IsGolangVendorDirectory(dirPath) {
|
||||||
// Note that CodeQL expects a forward-slash-separated path, even on Windows.
|
// Note that CodeQL expects a forward-slash-separated path, even on Windows.
|
||||||
vendorDirs = append(vendorDirs, path.Join(filepath.ToSlash(dirPath), "**"))
|
vendorDirs = append(vendorDirs, path.Join(filepath.ToSlash(dirPath), "**"))
|
||||||
return filepath.SkipDir
|
return filepath.SkipDir
|
||||||
|
|||||||
@@ -287,3 +287,15 @@ func getImportPathFromRepoURL(repourl string) string {
|
|||||||
path = regexp.MustCompile(`^/+|\.git$`).ReplaceAllString(path, "")
|
path = regexp.MustCompile(`^/+|\.git$`).ReplaceAllString(path, "")
|
||||||
return host + "/" + path
|
return host + "/" + path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decides if `path` refers to a file that exists.
|
||||||
|
func fileExists(path string) bool {
|
||||||
|
stat, err := os.Stat(path)
|
||||||
|
return err == nil && stat.Mode().IsRegular()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decides if `dirPath` is a vendor directory by testing whether it is called `vendor`
|
||||||
|
// and contains a `modules.txt` file.
|
||||||
|
func IsGolangVendorDirectory(dirPath string) bool {
|
||||||
|
return filepath.Base(dirPath) == "vendor" && fileExists(filepath.Join(dirPath, "modules.txt"))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user