Skip to content

Commit 9360e13

Browse files
authored
CM-11974 - make exclude by path work for all scan command types (#19)
* make exclude by path work for commit_history and repository scans * remove debug test
1 parent f82ba4e commit 9360e13

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

cli/code_scanner.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def scan_repository(context: click.Context, path, branch):
3939
try:
4040
logger.debug('Starting repository scan process, %s', {'path': path, 'branch': branch})
4141
documents_to_scan = [
42-
Document(get_path_by_os(obj.path), obj.data_stream.read().decode('utf-8', errors='replace'))
42+
Document(get_path_by_os(os.path.join(path, obj.path)), obj.data_stream.read().decode('utf-8', errors='replace'))
4343
for obj
4444
in get_git_repository_tree_file_entries(path, branch)]
4545
documents_to_scan = exclude_irrelevant_documents_to_scan(context, documents_to_scan)
@@ -82,12 +82,13 @@ def scan_commit_range(context: click.Context, path: str, commit_range: str):
8282
parent = commit.parents[0] if commit.parents else NULL_TREE
8383
diff = commit.diff(parent, create_patch=True, R=True)
8484
for blob in diff:
85-
doc = Document(get_path_by_os(get_diff_file_path(blob)),
85+
doc = Document(get_path_by_os(os.path.join(path, get_diff_file_path(blob))),
8686
blob.diff.decode('utf-8', errors='replace'), True, commit_id)
8787
documents_to_scan.append(doc)
8888

8989
documents_to_scan = exclude_irrelevant_documents_to_scan(context, documents_to_scan)
90-
logger.debug('Found all relevant files for scanning %s', {'path': path, 'commit_range': commit_range})
90+
logger.debug('Found all relevant files in commit %s',
91+
{'path': path, 'commit_range': commit_range, 'commit_id': commit_id})
9192
return scan_documents(context, documents_to_scan, is_git_diff=True, is_commit_range=True)
9293

9394

tests/utils/test_path_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from cli.utils.path_utils import is_sub_path
44

55

6-
test_files_path = path = Path(__file__).parent.absolute()
6+
test_files_path = Path(__file__).parent.absolute()
77

88

99
def test_is_sub_path_both_paths_are_same():
@@ -33,4 +33,4 @@ def test_is_sub_path_path_not_exists():
3333
def test_is_sub_path_subpath_not_exists():
3434
path = os.path.join(test_files_path, 'hello', 'random.txt')
3535
sub_path = os.path.join(test_files_path, 'goodbye')
36-
assert is_sub_path(path, sub_path) is False
36+
assert is_sub_path(path, sub_path) is False

0 commit comments

Comments
 (0)