@NonNull @Override protected Type type() throws IOException, InterruptedException { Object metadata = metadata(); if (metadata instanceof List) { return Type.DIRECTORY; } if (metadata instanceof GHContent) { GHContent content = (GHContent) metadata; if ("symlink".equals(content.getType())) { return Type.LINK; } if (content.isFile()) { return Type.REGULAR_FILE; } return Type.OTHER; } return Type.NONEXISTENT; }
private void listRepo(final List<String> documents, final GitHubLocation location, final GHRepository repo, final GHBranch branch, final String path) throws IOException { final List<GHContent> content = repo.getDirectoryContent(path, branch.getName()); for (final GHContent c : content) { switch (c.getType()) { case "file": handleFile(documents, location, c); break; case "dir": handleDir(documents, location, repo, branch, c); break; default: log.info("ignoring {}", c.getName()); } } }
@NonNull @Override public SCMProbeStat stat(@NonNull String path) throws IOException { checkOpen(); try { int index = path.lastIndexOf('/') + 1; List<GHContent> directoryContent = repo.getDirectoryContent(path.substring(0, index), ref); for (GHContent content : directoryContent) { if (content.getPath().equals(path)) { if (content.isFile()) { return SCMProbeStat.fromType(SCMFile.Type.REGULAR_FILE); } else if (content.isDirectory()) { return SCMProbeStat.fromType(SCMFile.Type.DIRECTORY); } else if ("symlink".equals(content.getType())) { return SCMProbeStat.fromType(SCMFile.Type.LINK); } else { return SCMProbeStat.fromType(SCMFile.Type.OTHER); } } if (content.getPath().equalsIgnoreCase(path)) { return SCMProbeStat.fromAlternativePath(content.getPath()); } } } catch (FileNotFoundException fnf) { // means that does not exist and this is handled below this try/catch block. } return SCMProbeStat.fromType(SCMFile.Type.NONEXISTENT); }