Skip to content

Commit 7f00f40

Browse files
authored
updated load_files to omit the path to workspace if specified (#16)
1 parent 0f39e43 commit 7f00f40

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

socketdev/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
__author__ = "socket.dev"
23-
__version__ = "1.0.14"
23+
__version__ = "1.0.15"
2424
__all__ = ["socketdev"]
2525

2626

socketdev/fullscans/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def get(org_slug: str, params: dict) -> dict:
4141
return result
4242

4343
@staticmethod
44-
def post(files: list, params: dict) -> dict:
44+
def post(files: list, params: dict, workspace: str = None) -> dict:
4545
loaded_files = []
46-
loaded_files = load_files(files, loaded_files)
46+
loaded_files = load_files(files, loaded_files, workspace)
4747

4848
params_arg = FullScans.create_params_string(params)
4949

socketdev/tools/__init__.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,29 @@ def fix_file_path(files) -> list:
2121
fixed_files.append(file)
2222
return fixed_files
2323

24+
2425

25-
def load_files(files: list, loaded_files: list) -> list:
26+
27+
def load_files(files: list, loaded_files: list, workspace: str = None) -> list:
2628
for file in files:
2729
if platform.system() == "Windows":
2830
file = file.replace("\\", "/")
2931
if "/" in file:
3032
path, name = file.rsplit("/", 1)
33+
else:
34+
path = "."
35+
name = file
3136
full_path = f"{path}/{name}"
32-
payload = (full_path, (name, open(full_path, "rb")))
37+
38+
# Calculate key based on workspace if provided
39+
if workspace and full_path.startswith(workspace):
40+
key = full_path[len(workspace):]
41+
key = key.lstrip("/")
42+
key = key.lstrip("./")
43+
else:
44+
key = full_path
45+
46+
payload = (key, (name, open(full_path, "rb")))
3347
loaded_files.append(payload)
3448
return loaded_files
3549

0 commit comments

Comments
 (0)