@@ -237,22 +237,55 @@ public List<String> listFolders(String owner, String repo, String branch, String
237237 // return listFilesRecursive(u.owner, u.repo, u.ref, u.path);
238238 //}
239239
240- public List <String > listFilesRecursive (String startDirUrl ) throws IOException {
241- URLHelper u = URLHelper .parseGitHubUrl (startDirUrl );
240+ // public List<String> listFilesRecursive(String startDirUrl) throws IOException {
241+ // URLHelper u = URLHelper.parseGitHubUrl(startDirUrl);
242242
243243 // If the user just gave "https://github.com/owner/repo" (no /tree/ or /blob/)
244244 // assume branch "main" at repo root.
245- if (!u .isBlob && (u .ref == null || u .ref .isBlank ())) {
246- return listFilesRecursive (u .owner , u .repo , "main" , "" );
245+ // if (!u.isBlob && (u.ref == null || u.ref.isBlank())) {
246+ // return listFilesRecursive(u.owner, u.repo, "main", "");
247+ // }
248+
249+ // if (u.isBlob) {
250+ // throw new IllegalArgumentException("URL points to a file, not a directory: " + startDirUrl);
251+ // }
252+
253+ // return listFilesRecursive(u.owner, u.repo, u.ref, u.path);
254+ //}
255+
256+
257+ // URL-based: recursively list all files under a directory URL (or entire repo if root).
258+ public List <String > listFilesRecursive (String startDirUrl ) throws IOException {
259+ // normalize trailing slash
260+ String url = startDirUrl .endsWith ("/" ) ? startDirUrl .substring (0 , startDirUrl .length () - 1 ) : startDirUrl ;
261+
262+ // If the URL does NOT contain /tree/ or /blob/, it's probably just:
263+ // https://github.com/{owner}/{repo}[/...]
264+ if (!url .contains ("/tree/" ) && !url .contains ("/blob/" )) {
265+ // split into pieces
266+ // e.g. https://github.com/javiergs/ADASIM -> ["https:", "", "github.com", "javiergs", "ADASIM"]
267+ String [] parts = url .split ("/" , 6 );
268+ if (parts .length < 5 ) {
269+ throw new IllegalArgumentException ("Cannot recognize GitHub repo from URL: " + startDirUrl );
270+ }
271+ String owner = parts [3 ];
272+ String repo = parts [4 ];
273+ // if there is more after repo (rare in this case), grab it as path
274+ String path = (parts .length == 6 ) ? parts [5 ] : "" ;
275+ // assume default branch "main"
276+ return listFilesRecursive (owner , repo , "main" , path );
247277 }
248278
279+ // original behavior for proper /tree/... URLs
280+ URLHelper u = URLHelper .parseGitHubUrl (startDirUrl );
249281 if (u .isBlob ) {
250282 throw new IllegalArgumentException ("URL points to a file, not a directory: " + startDirUrl );
251283 }
252-
253284 return listFilesRecursive (u .owner , u .repo , u .ref , u .path );
254285 }
255286
287+
288+
256289 /** Recursively list all file paths (relative to repo root) under owner/repo/branch/path.
257290 *
258291 * @param owner the repository owner (user or organization) must not be null/blank
0 commit comments