-
Notifications
You must be signed in to change notification settings - Fork 4
Add paths-ignore support to CDS extractor and update dependencies
#327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
341d55d
CDS extractor support paths-ignore CodeQL config
data-douser bf529e1
Minor version bump of CDS extractor node deps
data-douser fbb3dd3
Merge branch 'main' into dd/paths-ignore/1
data-douser 055c579
Address PR review comments
data-douser 166baa1
Merge branch 'main' into dd/paths-ignore/1
data-douser 83d3680
Merge branch 'main' into dd/paths-ignore/1
data-douser 4e35e5e
CDS extractor support for CODEQL_CONFIG_PATH env
data-douser 054faa1
Merge branch 'main' into dd/paths-ignore/1
data-douser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5,052 changes: 4,801 additions & 251 deletions
5,052
extractors/cds/tools/dist/cds-extractor.bundle.js
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
4,496 changes: 4,450 additions & 46 deletions
4,496
extractors/cds/tools/dist/compile-test-cds-lib.cjs
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| import { existsSync, readFileSync } from 'fs'; | ||
| import { join } from 'path'; | ||
|
|
||
| import jsYaml from 'js-yaml'; | ||
| import { minimatch } from 'minimatch'; | ||
|
|
||
| import { cdsExtractorLog } from './logging'; | ||
|
|
||
| /** | ||
| * Well-known paths where a CodeQL configuration file may be located, | ||
| * relative to the source root directory. Checked in order of priority. | ||
| */ | ||
| const CODEQL_CONFIG_PATHS = [ | ||
| '.github/codeql/codeql-config.yml', | ||
| '.github/codeql/codeql-config.yaml', | ||
| ]; | ||
|
|
||
| /** | ||
| * Cache for parsed paths-ignore patterns, keyed by source root. | ||
| * Avoids re-reading and re-parsing the config file on every call. | ||
| */ | ||
| const patternsCache = new Map<string, string[]>(); | ||
|
|
||
| /** | ||
| * Shape of the subset of a CodeQL configuration file that we care about. | ||
| */ | ||
| interface CodeqlConfig { | ||
| 'paths-ignore'?: string[]; | ||
| } | ||
|
|
||
| /** | ||
| * Finds the CodeQL configuration file in the source root directory by | ||
| * checking the well-known paths in order. | ||
| * | ||
| * @param sourceRoot - The source root directory | ||
| * @returns The absolute path to the config file, or undefined if not found | ||
| */ | ||
| export function findCodeqlConfigFile(sourceRoot: string): string | undefined { | ||
| for (const configPath of CODEQL_CONFIG_PATHS) { | ||
| const fullPath = join(sourceRoot, configPath); | ||
| if (existsSync(fullPath)) { | ||
| return fullPath; | ||
| } | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| /** | ||
| * Reads the CodeQL configuration file and extracts the `paths-ignore` | ||
| * patterns list. | ||
| * | ||
| * @param sourceRoot - The source root directory | ||
| * @returns Array of paths-ignore glob patterns, or empty array if none | ||
| */ | ||
| export function getPathsIgnorePatterns(sourceRoot: string): string[] { | ||
| const cached = patternsCache.get(sourceRoot); | ||
| if (cached !== undefined) { | ||
| return cached; | ||
| } | ||
|
|
||
| const configPath = findCodeqlConfigFile(sourceRoot); | ||
| if (!configPath) { | ||
| patternsCache.set(sourceRoot, []); | ||
| return []; | ||
| } | ||
|
|
||
| try { | ||
| const content = readFileSync(configPath, 'utf8'); | ||
| const config = jsYaml.load(content) as CodeqlConfig | null; | ||
|
|
||
| if (!config || !Array.isArray(config['paths-ignore'])) { | ||
|
data-douser marked this conversation as resolved.
|
||
| return []; | ||
| } | ||
|
|
||
| const patterns = config['paths-ignore'].filter( | ||
| (p): p is string => typeof p === 'string' && p.length > 0, | ||
| ); | ||
|
|
||
| if (patterns.length > 0) { | ||
| cdsExtractorLog( | ||
| 'info', | ||
| `Found ${patterns.length} paths-ignore pattern(s) in ${configPath}: ${patterns.join(', ')}`, | ||
| ); | ||
| } | ||
|
|
||
| patternsCache.set(sourceRoot, patterns); | ||
| return patterns; | ||
| } catch (error) { | ||
| cdsExtractorLog('warn', `Failed to read CodeQL config file at ${configPath}: ${String(error)}`); | ||
| patternsCache.set(sourceRoot, []); | ||
| return []; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Tests whether a single relative file path matches any of the given | ||
| * paths-ignore patterns. | ||
| * | ||
| * Pattern matching follows the CodeQL `paths-ignore` semantics: | ||
| * - A bare directory name `vendor` matches anything under `vendor/` | ||
| * - `**` matches across directory boundaries | ||
| * - `*` matches within a single path segment | ||
| * | ||
| * @param relativePath - File path relative to the source root | ||
| * @param patterns - Array of paths-ignore glob patterns | ||
| * @returns true if the path should be ignored | ||
| */ | ||
| export function shouldIgnorePath(relativePath: string, patterns: string[]): boolean { | ||
| for (const raw of patterns) { | ||
| // Strip trailing slashes so `vendor/` is treated the same as `vendor` | ||
| const pattern = raw.replace(/\/+$/, ''); | ||
|
|
||
| // Direct minimatch check | ||
| if (minimatch(relativePath, pattern, { dot: true })) { | ||
| return true; | ||
| } | ||
|
|
||
| // Also match as a directory prefix: pattern `vendor` should | ||
| // match `vendor/lib/foo.cds` (i.e. anything nested underneath). | ||
| if (minimatch(relativePath, `${pattern}/**`, { dot: true })) { | ||
| return true; | ||
|
data-douser marked this conversation as resolved.
|
||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Filters a list of relative file paths, removing any that match the | ||
| * given paths-ignore patterns. | ||
| * | ||
| * @param relativePaths - File paths relative to the source root | ||
| * @param patterns - Array of paths-ignore glob patterns | ||
| * @returns Filtered list of paths that do NOT match any ignore pattern | ||
| */ | ||
| export function filterIgnoredPaths(relativePaths: string[], patterns: string[]): string[] { | ||
| if (patterns.length === 0) { | ||
| return relativePaths; | ||
| } | ||
| return relativePaths.filter(p => !shouldIgnorePath(p, patterns)); | ||
| } | ||
|
|
||
| /** | ||
| * Clears the internal patterns cache. Intended for testing only. | ||
| */ | ||
| export function clearPathsIgnoreCache(): void { | ||
| patternsCache.clear(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.