77from typing import List , Literal , Optional , Union , overload
88
99from decouple import Config , RepositoryEnv
10+ from requests import Session
1011
1112from codeplag .consts import (
1213 ALL_EXTENSIONS ,
1819from codeplag .logger import get_logger
1920from codeplag .types import ASTFeatures , Extension , Extensions
2021from webparsers .github_parser import GitHubParser
22+ from webparsers .types import WorkInfo
2123
2224
2325def get_files_path_from_directory (
@@ -101,7 +103,7 @@ def _set_access_token(self, env_path: Optional[Path]) -> None:
101103 self ._access_token : str = os .environ .get ('ACCESS_TOKEN' , '' )
102104 else :
103105 env_config = Config (RepositoryEnv (env_path ))
104- self ._access_token : str = env_config .get ('ACCESS_TOKEN' , default = '' )
106+ self ._access_token : str = env_config .get ('ACCESS_TOKEN' , default = '' ) # type: ignore
105107
106108 if not self ._access_token :
107109 self .logger .warning ('GitHub access token is not defined.' )
@@ -111,11 +113,12 @@ def _set_github_parser(self, branch_policy: bool) -> None:
111113 file_extensions = SUPPORTED_EXTENSIONS [self .extension ],
112114 check_all = branch_policy ,
113115 access_token = self ._access_token ,
114- logger = get_logger ('webparsers' , LOG_PATH )
116+ logger = get_logger ('webparsers' , LOG_PATH ),
117+ session = Session ()
115118 )
116119
117120 @abstractmethod
118- def get_from_content (self , file_content : str , url_to_file : str ) -> Optional [ASTFeatures ]:
121+ def get_from_content (self , work_info : WorkInfo ) -> Optional [ASTFeatures ]:
119122 ...
120123
121124 @abstractmethod
@@ -165,8 +168,8 @@ def get_from_github_files(self, github_files: List[str]) -> List[ASTFeatures]:
165168
166169 self .logger .debug (f"{ GET_FRAZE } GitHub urls" )
167170 for github_file in github_files :
168- file_content = self .github_parser .get_file_from_url (github_file )[ 0 ]
169- features = self .get_from_content (file_content , github_file )
171+ work_info = self .github_parser .get_file_from_url (github_file )
172+ features = self .get_from_content (work_info )
170173 if features :
171174 works .append (features )
172175
@@ -200,8 +203,8 @@ def get_from_github_project_folders(
200203 gh_prj_files = self .github_parser .get_files_generator_from_dir_url (
201204 github_project , path_regexp = self .path_regexp
202205 )
203- for file_content , url_file in gh_prj_files :
204- features = self .get_from_content (file_content , url_file )
206+ for work_info in gh_prj_files :
207+ features = self .get_from_content (work_info )
205208 if features is None :
206209 continue
207210
@@ -251,8 +254,8 @@ def get_from_users_repos(
251254 files = self .github_parser .get_files_generator_from_repo_url (
252255 repo .html_url , path_regexp = self .path_regexp
253256 )
254- for file_content , url_file in files :
255- features = self .get_from_content (file_content , url_file )
257+ for work_info in files :
258+ features = self .get_from_content (work_info )
256259 if features is None :
257260 continue
258261
0 commit comments