Skip to content

Commit e9af129

Browse files
committed
CM-40909 Add sum-mod extension check for restoring
1 parent bd6a581 commit e9af129

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

cycode/cli/files_collector/sca/base_restore_dependencies.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def execute_commands(
3131
# Write all collected outputs to the file if dependencies_file_name is provided
3232
if dependencies_file_name:
3333
with open(dependencies_file_name, 'w') as output_file: # Open once in 'w' mode to start fresh
34-
for dependencies in all_dependencies:
35-
output_file.write(dependencies + '\n')
34+
dependencies = '\n'.join(all_dependencies)
35+
output_file.writelines(dependencies)
3636
except Exception as e:
3737
logger.debug('Failed to restore dependencies via shell command, %s', {'filename': file_name}, exc_info=e)
3838
return None
@@ -92,7 +92,7 @@ def is_project(self, document: Document) -> bool:
9292
pass
9393

9494
@abstractmethod
95-
def get_commands(self, manifest_file_path: str) -> List[str]:
95+
def get_commands(self, manifest_file_path: str) -> List[List[str]]:
9696
pass
9797

9898
@abstractmethod

cycode/cli/files_collector/sca/go/restore_go_dependencies.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import os
23
from typing import List, Optional
34

@@ -6,15 +7,30 @@
67
from cycode.cli.files_collector.sca.base_restore_dependencies import BaseRestoreDependencies
78
from cycode.cli.models import Document
89

9-
GO_PROJECT_FILE_EXTENSIONS = ['.mod']
10+
GO_PROJECT_FILE_EXTENSIONS = ['.mod', '.sum']
1011
GO_RESTORE_FILE_NAME = 'go.mod.graph'
1112
BUILD_GO_FILE_NAME = 'go.mod'
13+
BUILD_GO_LOCK_FILE_NAME = 'go.sum'
1214

1315

1416
class RestoreGoDependencies(BaseRestoreDependencies):
1517
def __init__(self, context: click.Context, is_git_diff: bool, command_timeout: int) -> None:
1618
super().__init__(context, is_git_diff, command_timeout, create_output_file_manually=True)
1719

20+
def try_restore_dependencies(self, document: Document) -> Optional[Document]:
21+
manifest_exists = os.path.isfile(self.get_working_directory(document) + os.sep + BUILD_GO_FILE_NAME)
22+
lock_exists = os.path.isfile(self.get_working_directory(document) + os.sep + BUILD_GO_LOCK_FILE_NAME)
23+
24+
if not manifest_exists or not lock_exists:
25+
logging.info('No manifest go.mod file found' if not manifest_exists else 'No manifest go.sum file found')
26+
27+
manifest_files_exists = manifest_exists & lock_exists
28+
29+
if not manifest_files_exists:
30+
return None
31+
32+
return super().try_restore_dependencies(document)
33+
1834
def is_project(self, document: Document) -> bool:
1935
return any(document.path.endswith(ext) for ext in GO_PROJECT_FILE_EXTENSIONS)
2036

cycode/cli/utils/shell_executor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import subprocess
2-
from typing import List, Optional
2+
from typing import List, Optional, Union
33

44
import click
55

@@ -9,7 +9,7 @@
99

1010

1111
def shell(
12-
command: List[List[str]],
12+
command: Union[str, List[str]],
1313
timeout: int = _SUBPROCESS_DEFAULT_TIMEOUT_SEC,
1414
working_directory: Optional[str] = None,
1515
) -> Optional[str]:

0 commit comments

Comments
 (0)