-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CM-42771 - Add support of
.gitignore
files for a file excluding fro…
…m scans (#272)
- Loading branch information
Showing
10 changed files
with
887 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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 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 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 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): | ||
logger.debug('Apply top level ignore file: %s', ignore_file_path) | ||
ignore_files.append(ignore_file_path) | ||
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.