Skip to content

Commit 6d416a5

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

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

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

0 commit comments

Comments
 (0)