2
2
from typing import TYPE_CHECKING , Dict , List , Optional
3
3
4
4
import click
5
- from git import GitCommandError , Repo
6
5
7
6
from cycode .cli import consts
8
7
from cycode .cli .files_collector .sca .maven .restore_gradle_dependencies import RestoreGradleDependencies
9
8
from cycode .cli .files_collector .sca .maven .restore_maven_dependencies import RestoreMavenDependencies
10
9
from cycode .cli .models import Document
10
+ from cycode .cli .utils .git_proxy import git_proxy
11
11
from cycode .cli .utils .path_utils import get_file_content , get_file_dir , join_paths
12
12
from cycode .cyclient import logger
13
13
14
14
if TYPE_CHECKING :
15
+ from git import Repo
16
+
15
17
from cycode .cli .files_collector .sca .maven .base_restore_maven_dependencies import BaseRestoreMavenDependencies
16
18
17
19
BUILD_GRADLE_FILE_NAME = 'build.gradle'
@@ -27,21 +29,21 @@ def perform_pre_commit_range_scan_actions(
27
29
to_commit_documents : List [Document ],
28
30
to_commit_rev : str ,
29
31
) -> None :
30
- repo = Repo (path )
32
+ repo = git_proxy . get_repo (path )
31
33
add_ecosystem_related_files_if_exists (from_commit_documents , repo , from_commit_rev )
32
34
add_ecosystem_related_files_if_exists (to_commit_documents , repo , to_commit_rev )
33
35
34
36
35
37
def perform_pre_hook_range_scan_actions (
36
38
git_head_documents : List [Document ], pre_committed_documents : List [Document ]
37
39
) -> None :
38
- repo = Repo (os .getcwd ())
40
+ repo = git_proxy . get_repo (os .getcwd ())
39
41
add_ecosystem_related_files_if_exists (git_head_documents , repo , consts .GIT_HEAD_COMMIT_REV )
40
42
add_ecosystem_related_files_if_exists (pre_committed_documents )
41
43
42
44
43
45
def add_ecosystem_related_files_if_exists (
44
- documents : List [Document ], repo : Optional [Repo ] = None , commit_rev : Optional [str ] = None
46
+ documents : List [Document ], repo : Optional [' Repo' ] = None , commit_rev : Optional [str ] = None
45
47
) -> None :
46
48
documents_to_add : List [Document ] = []
47
49
for doc in documents :
@@ -56,7 +58,7 @@ def add_ecosystem_related_files_if_exists(
56
58
57
59
58
60
def get_doc_ecosystem_related_project_files (
59
- doc : Document , documents : List [Document ], ecosystem : str , commit_rev : Optional [str ], repo : Optional [Repo ]
61
+ doc : Document , documents : List [Document ], ecosystem : str , commit_rev : Optional [str ], repo : Optional [' Repo' ]
60
62
) -> List [Document ]:
61
63
documents_to_add : List [Document ] = []
62
64
for ecosystem_project_file in consts .PROJECT_FILES_BY_ECOSYSTEM_MAP .get (ecosystem ):
@@ -136,10 +138,10 @@ def get_manifest_file_path(document: Document, is_monitor_action: bool, project_
136
138
return join_paths (project_path , document .path ) if is_monitor_action else document .path
137
139
138
140
139
- def get_file_content_from_commit (repo : Repo , commit : str , file_path : str ) -> Optional [str ]:
141
+ def get_file_content_from_commit (repo : ' Repo' , commit : str , file_path : str ) -> Optional [str ]:
140
142
try :
141
143
return repo .git .show (f'{ commit } :{ file_path } ' )
142
- except GitCommandError :
144
+ except git_proxy . get_git_command_error () :
143
145
return None
144
146
145
147
0 commit comments