-
Notifications
You must be signed in to change notification settings - Fork 59
CM-42771 - Add support of .gitignore files for a file excluding from scans
#272
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 all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3cdb459
CM-42771 - Support `.gitignore` and `.cycodeignore` files for a file …
MarshalX 747950a
fix ruff
MarshalX 51522ba
make test deterministic
MarshalX 8438f2f
fix tests on Windows
MarshalX 1e9de19
perf optimization; code refactor
MarshalX 7cb0f15
fix ignoring; simplify global ignoring patterns
MarshalX 5813c91
add inheriting of ignore patterns
MarshalX 0724e5e
cover walk_ignore generator with tests
MarshalX 7a96e3c
Merge branch 'main' into CM-42771-support-ignore-files
MarshalX 0c6ff01
fix lock after merge with main
MarshalX 6612402
drop poetry cache
MarshalX 1041135
fix CI crashes on Windows (Python 3.12 & 3.13) https://github.com/pyt…
MarshalX 9b9ab86
add ignorelib as is with copyright notice
MarshalX cd0852a
fix and format ignorelib
MarshalX 266bcfe
align codebase of ignorelib with dulwich
MarshalX 85993ff
fix inefficient subfolders filtering
MarshalX 4fbf23b
migrate to ignore_utils; add tests; remove unused pathspec; remove .c…
MarshalX 5c819e3
Merge branch 'main' into CM-42771-support-ignore-files
MarshalX 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
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 |
|---|---|---|
|
|
@@ -50,4 +50,4 @@ jobs: | |
| run: poetry install | ||
|
|
||
| - name: Run Tests | ||
| run: poetry run pytest | ||
| run: poetry run python -m pytest | ||
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,42 @@ | ||
| import os | ||
| from typing import Generator, Iterable, List, Tuple | ||
|
|
||
| from cycode.cli.utils.ignore_utils import IgnoreFilterManager | ||
| from cycode.cyclient import logger | ||
|
|
||
| _SUPPORTED_IGNORE_PATTERN_FILES = { # oneday we will bring .cycodeignore or something like that | ||
| '.gitignore', | ||
| } | ||
| _DEFAULT_GLOBAL_IGNORE_PATTERNS = [ | ||
| '.git', | ||
| '.cycode', | ||
| ] | ||
|
|
||
|
|
||
| def _walk_to_top(path: str) -> Iterable[str]: | ||
| while os.path.dirname(path) != path: | ||
| yield path | ||
| path = os.path.dirname(path) | ||
|
|
||
| if path: | ||
| yield path # Include the top-level directory | ||
|
|
||
|
|
||
| def _collect_top_level_ignore_files(path: str) -> List[str]: | ||
| ignore_files = [] | ||
| for dir_path in _walk_to_top(path): | ||
| for ignore_file in _SUPPORTED_IGNORE_PATTERN_FILES: | ||
| ignore_file_path = os.path.join(dir_path, ignore_file) | ||
| if os.path.exists(ignore_file_path): | ||
cycode-security[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| logger.debug('Apply top level ignore file: %s', ignore_file_path) | ||
| ignore_files.append(ignore_file_path) | ||
cycode-security[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return ignore_files | ||
|
|
||
|
|
||
| def walk_ignore(path: str) -> Generator[Tuple[str, List[str], List[str]], None, None]: | ||
| ignore_filter_manager = IgnoreFilterManager.build( | ||
| path=path, | ||
| global_ignore_file_paths=_collect_top_level_ignore_files(path), | ||
| global_patterns=_DEFAULT_GLOBAL_IGNORE_PATTERNS, | ||
| ) | ||
| yield from ignore_filter_manager.walk() | ||
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.