Share vendor-dir extraction logic between extractor and configure-baseline script

This commit is contained in:
Chris Smowton
2024-08-19 17:55:42 +01:00
parent 22802fd41f
commit f1f6f9b580
3 changed files with 13 additions and 2 deletions

View File

@@ -6,6 +6,8 @@ import (
"os"
"path"
"path/filepath"
"github.com/github/codeql-go/extractor/util"
)
func fileExists(path string) bool {
@@ -26,7 +28,7 @@ type BaselineConfig struct {
func GetConfigBaselineAsJSON(rootDir string) ([]byte, error) {
vendorDirs := make([]string, 0)
if os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS") == "true" {
if util.IsVendorDirExtractionEnabled() {
// The user wants vendor directories scanned; emit an empty report.
} else {
filepath.WalkDir(rootDir, func(dirPath string, d fs.DirEntry, err error) error {

View File

@@ -199,7 +199,7 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
// If CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS is "true", we extract `vendor` directories;
// otherwise (the default) is to exclude them from extraction
includeVendor := os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS") == "true"
includeVendor := util.IsVendorDirExtractionEnabled()
if !includeVendor {
excludedDirs = append(excludedDirs, "vendor")
}

View File

@@ -0,0 +1,9 @@
package util
import (
"os"
)
func IsVendorDirExtractionEnabled() bool {
return os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS") == "true"
}