Skip to content

Commit 4b7bc8c

Browse files
authored
CM-25340 - Fix list modification while in a for loop (#143)
1 parent db748c4 commit 4b7bc8c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

cycode/cli/helpers/sca_code_scanner.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,16 @@ def perform_pre_hook_range_scan_actions(
4343
def add_ecosystem_related_files_if_exists(
4444
documents: List[Document], repo: Optional[Repo] = None, commit_rev: Optional[str] = None
4545
) -> None:
46+
documents_to_add: List[Document] = []
4647
for doc in documents:
4748
ecosystem = get_project_file_ecosystem(doc)
4849
if ecosystem is None:
4950
logger.debug('failed to resolve project file ecosystem: %s', doc.path)
5051
continue
51-
documents_to_add = get_doc_ecosystem_related_project_files(doc, documents, ecosystem, commit_rev, repo)
52-
documents.extend(documents_to_add)
52+
53+
documents_to_add.extend(get_doc_ecosystem_related_project_files(doc, documents, ecosystem, commit_rev, repo))
54+
55+
documents.extend(documents_to_add)
5356

5457

5558
def get_doc_ecosystem_related_project_files(
@@ -59,11 +62,10 @@ def get_doc_ecosystem_related_project_files(
5962
for ecosystem_project_file in consts.PROJECT_FILES_BY_ECOSYSTEM_MAP.get(ecosystem):
6063
file_to_search = join_paths(get_file_dir(doc.path), ecosystem_project_file)
6164
if not is_project_file_exists_in_documents(documents, file_to_search):
62-
file_content = (
63-
get_file_content_from_commit(repo, commit_rev, file_to_search)
64-
if repo
65-
else get_file_content(file_to_search)
66-
)
65+
if repo:
66+
file_content = get_file_content_from_commit(repo, commit_rev, file_to_search)
67+
else:
68+
file_content = get_file_content(file_to_search)
6769

6870
if file_content is not None:
6971
documents_to_add.append(Document(file_to_search, file_content))

0 commit comments

Comments
 (0)