@@ -75,19 +75,49 @@ def main_code():
75
75
log .debug ("loaded client" )
76
76
core = Core (socket_config , sdk )
77
77
log .debug ("loaded core" )
78
- # Load files - files defaults to "[]" in CliConfig
78
+ # Parse files argument
79
79
try :
80
- files = json .loads (config .files ) # Will always succeed with empty list by default
81
- is_repo = True # FIXME: This is misleading - JSON parsing success doesn't indicate repo status
80
+ if isinstance (config .files , list ):
81
+ # Already a list, use as-is
82
+ specified_files = config .files
83
+ elif isinstance (config .files , str ):
84
+ # Handle different string formats
85
+ files_str = config .files .strip ()
86
+
87
+ # If the string is wrapped in extra quotes, strip them
88
+ if ((files_str .startswith ('"' ) and files_str .endswith ('"' )) or
89
+ (files_str .startswith ("'" ) and files_str .endswith ("'" ))):
90
+ # Check if the inner content looks like JSON
91
+ inner_str = files_str [1 :- 1 ]
92
+ if inner_str .startswith ('[' ) and inner_str .endswith (']' ):
93
+ files_str = inner_str
94
+
95
+ # Try to parse as JSON
96
+ try :
97
+ specified_files = json .loads (files_str )
98
+ except json .JSONDecodeError :
99
+ # If JSON parsing fails, try replacing single quotes with double quotes
100
+ files_str = files_str .replace ("'" , '"' )
101
+ specified_files = json .loads (files_str )
102
+ else :
103
+ # Default to empty list
104
+ specified_files = []
82
105
except Exception as error :
83
- # Only hits this if files was manually set to invalid JSON
84
- log .error (f"Unable to parse { config .files } " )
85
- log .error (error )
106
+ log .error (f"Unable to parse files argument: { config .files } " )
107
+ log .error (f"Error details: { error } " )
108
+ log .debug (f"Files type: { type (config .files )} " )
109
+ log .debug (f"Files repr: { repr (config .files )} " )
86
110
sys .exit (3 )
87
111
112
+ # Determine if files were explicitly specified
113
+ files_explicitly_specified = config .files != "[]" and len (specified_files ) > 0
114
+
88
115
# Git setup
116
+ is_repo = False
117
+ git_repo = None
89
118
try :
90
119
git_repo = Git (config .target_path )
120
+ is_repo = True
91
121
if not config .repo :
92
122
config .repo = git_repo .repo_name
93
123
if not config .commit_sha :
@@ -98,12 +128,10 @@ def main_code():
98
128
config .committers = [git_repo .committer ]
99
129
if not config .commit_message :
100
130
config .commit_message = git_repo .commit_message
101
- if files and not config .ignore_commit_files : # files is empty by default, so this is False unless files manually specified
102
- files = git_repo .changed_files # Only gets git's changed files if files were manually specified
103
- is_repo = True # Redundant since already True
104
131
except InvalidGitRepositoryError :
105
- is_repo = False # Overwrites previous True - this is the REAL repo status
106
- config .ignore_commit_files = True # Silently changes config - should log this
132
+ is_repo = False
133
+ log .debug ("Not a git repository, setting ignore_commit_files=True" )
134
+ config .ignore_commit_files = True
107
135
except NoSuchPathError :
108
136
raise Exception (f"Unable to find path { config .target_path } " )
109
137
@@ -125,26 +153,43 @@ def main_code():
125
153
if scm is not None :
126
154
config .default_branch = scm .config .is_default_branch
127
155
156
+ # Determine files to check based on the new logic
157
+ files_to_check = []
158
+ force_api_mode = False
159
+
160
+ if files_explicitly_specified :
161
+ # Case 2: Files are specified - use them and don't check commit details
162
+ files_to_check = specified_files
163
+ log .debug (f"Using explicitly specified files: { files_to_check } " )
164
+ elif not config .ignore_commit_files and is_repo :
165
+ # Case 1: Files not specified and --ignore-commit-files not set - try to find changed files from commit
166
+ files_to_check = git_repo .changed_files
167
+ log .debug (f"Using changed files from commit: { files_to_check } " )
168
+ else :
169
+ # ignore_commit_files is set or not a repo - scan everything but force API mode if no supported files
170
+ files_to_check = []
171
+ log .debug ("No files to check from commit (ignore_commit_files=True or not a repo)" )
128
172
129
- # Combine manually specified files with git changes if applicable
130
- files_to_check = set (json .loads (config .files )) # Start with manually specified files
131
-
132
- # Add git changes if this is a repo and we're not ignoring commit files
133
- if is_repo and not config .ignore_commit_files and not files_to_check :
134
- files_to_check .update (git_repo .changed_files )
135
-
136
- # Determine if we need to scan based on manifest files
137
- should_skip_scan = True # Default to skipping
138
- if config .ignore_commit_files :
139
- should_skip_scan = False # Force scan if ignoring commit files
140
- elif files_to_check : # If we have any files to check
141
- should_skip_scan = not core .has_manifest_files (list (files_to_check ))
142
- log .debug (f"in elif, should_skip_scan: { should_skip_scan } " )
143
-
144
- if should_skip_scan :
145
- log .debug ("No manifest files found in changes, skipping scan" )
173
+ # Check if we have supported manifest files
174
+ has_supported_files = files_to_check and core .has_manifest_files (files_to_check )
175
+
176
+ # Case 3: If no supported files or files are empty, force API mode (no PR comments)
177
+ if not has_supported_files :
178
+ force_api_mode = True
179
+ log .debug ("No supported manifest files found, forcing API mode" )
180
+
181
+ # Determine scan behavior
182
+ should_skip_scan = False # Always perform scan, but behavior changes based on supported files
183
+ if config .ignore_commit_files and not files_explicitly_specified :
184
+ # Force full scan when ignoring commit files and no explicit files
185
+ should_skip_scan = False
186
+ log .debug ("Forcing full scan due to ignore_commit_files" )
187
+ elif not has_supported_files :
188
+ # No supported files - still scan but in API mode
189
+ should_skip_scan = False
190
+ log .debug ("No supported files but will scan in API mode" )
146
191
else :
147
- log .debug ("Found manifest files or forced scan, proceeding " )
192
+ log .debug ("Found supported manifest files, proceeding with normal scan " )
148
193
149
194
org_slug = core .config .org_slug
150
195
if config .repo_is_public :
@@ -177,6 +222,8 @@ def main_code():
177
222
# Initialize diff
178
223
diff = Diff ()
179
224
diff .id = "NO_DIFF_RAN"
225
+ diff .diff_url = ""
226
+ diff .report_url = ""
180
227
181
228
# Handle SCM-specific flows
182
229
if scm is not None and scm .check_event_type () == "comment" :
@@ -192,11 +239,9 @@ def main_code():
192
239
log .debug ("Removing comment alerts" )
193
240
scm .remove_comment_alerts (comments )
194
241
195
- elif scm is not None and scm .check_event_type () != "comment" :
242
+ elif scm is not None and scm .check_event_type () != "comment" and not force_api_mode :
196
243
log .info ("Push initiated flow" )
197
- if should_skip_scan :
198
- log .info ("No manifest files changes, skipping scan" )
199
- elif scm .check_event_type () == "diff" :
244
+ if scm .check_event_type () == "diff" :
200
245
log .info ("Starting comment logic for PR/MR event" )
201
246
diff = core .create_new_diff (config .target_path , params , no_change = should_skip_scan )
202
247
comments = scm .get_comments_for_pr ()
@@ -255,12 +300,24 @@ def main_code():
255
300
256
301
output_handler .handle_output (diff )
257
302
else :
258
- log .info ("API Mode" )
259
- diff = core .create_new_diff (config .target_path , params , no_change = should_skip_scan )
260
- output_handler .handle_output (diff )
303
+ if force_api_mode :
304
+ log .info ("No Manifest files changed, creating Socket Report" )
305
+ else :
306
+ log .info ("API Mode" )
307
+ full_scan_result = core .create_full_scan_with_report_url (config .target_path , params , no_change = should_skip_scan )
308
+ log .info (f"Full scan created with ID: { full_scan_result ['id' ]} " )
309
+ log .info (f"Full scan report URL: { full_scan_result ['html_report_url' ]} " )
310
+
311
+ # Create a minimal diff-like object for compatibility with downstream code
312
+ diff = Diff ()
313
+ diff .id = full_scan_result ['id' ]
314
+ diff .report_url = full_scan_result ['html_report_url' ]
315
+ diff .diff_url = full_scan_result ['html_report_url' ]
316
+ diff .packages = {} # No package data needed for API mode
317
+ # No output handling needed for API mode - just creating the scan
261
318
262
319
# Handle license generation
263
- if not should_skip_scan and diff .id != "no_diff_id " and config .generate_license :
320
+ if not should_skip_scan and diff .id != "NO_DIFF_RAN" and diff . id != "NO_SCAN_RAN " and config .generate_license :
264
321
all_packages = {}
265
322
for purl in diff .packages :
266
323
package = diff .packages [purl ]
@@ -279,6 +336,11 @@ def main_code():
279
336
all_packages [package .id ] = output
280
337
core .save_file (config .license_file_name , json .dumps (all_packages ))
281
338
339
+ # If we forced API mode due to no supported files, behave as if --disable-blocking was set
340
+ if force_api_mode and not config .disable_blocking :
341
+ log .debug ("Temporarily enabling disable_blocking due to no supported manifest files" )
342
+ config .disable_blocking = True
343
+
282
344
sys .exit (output_handler .return_exit_code (diff ))
283
345
284
346
0 commit comments