@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; }
protected void updateStoreOnGithub(GHRepository repo, String path, String img, String tag) throws IOException { try { repo.getFileContent(path); } catch (IOException e) { repo.createContent("", "initializing store", path); } String latestCommit = repo.getBranches().get(repo.getDefaultBranch()).getSHA1(); log.info("Loading image store at commit {}", latestCommit); GHContent content = repo.getFileContent(path, latestCommit); if (content.isFile()) { JsonElement json; try (InputStream stream = content.read(); InputStreamReader streamR = new InputStreamReader(stream)) { try { json = new JsonParser().parse(streamR); } catch (JsonParseException e) { log.warn("Not a JSON format store. Clearing and rewriting as JSON..."); json = JsonNull.INSTANCE; } } String jsonOutput = getAndModifyJsonString(json, img, tag); content.update(jsonOutput, String.format("Updated image %s with tag %s.\n@rev none@", img, tag), repo.getDefaultBranch()); } }
protected void updateStoreOnGithub(GHRepository repo, String path, String img, String tag) throws IOException { try { repo.getFileContent(path); } catch (IOException e) { repo.createContent("", "initializing store", path); } String latestCommit = repo.getBranches().get(repo.getDefaultBranch()).getSHA1(); log.info("Loading image store at commit {}", latestCommit); GHContent content = repo.getFileContent(path, latestCommit); if (content.isFile()) { JsonElement json; try (InputStream stream = content.read(); InputStreamReader streamR = new InputStreamReader(stream)) { try { json = new JsonParser().parse(streamR); } catch (JsonParseException e) { log.warn("Not a JSON format store. Clearing and rewriting as JSON..."); json = JsonNull.INSTANCE; } } String jsonOutput = getAndModifyJsonString(json, img, tag); content.update(jsonOutput, String.format("Updated image %s with tag %s.\n@rev none@", img, tag), repo.getDefaultBranch()); } }
protected void modifyOnGithubRecursive(GHRepository repo, GHContent content, String branch, String img, String tag) throws IOException { /* If we have a submodule; we want to skip. Content is submodule when the type is file, but content.getDownloadUrl() is null. */ if (content.isFile() && content.getDownloadUrl() != null) { modifyOnGithub(content, branch, img, tag, ""); } else if(content.isDirectory()) { for (GHContent newContent : repo.getDirectoryContent(content.getPath(), branch)) { modifyOnGithubRecursive(repo, newContent, branch, img, tag); } } else { // The only other case is if we have a file, but content.getDownloadUrl() is null log.info("Skipping submodule {}", content.getName()); } }
protected void modifyOnGithubRecursive(GHRepository repo, GHContent content, String branch, String img, String tag) throws IOException { /* If we have a submodule; we want to skip. Content is submodule when the type is file, but content.getDownloadUrl() is null. */ if (content.isFile() && content.getDownloadUrl() != null) { modifyOnGithub(content, branch, img, tag, ""); } else if(content.isDirectory()) { for (GHContent newContent : repo.getDirectoryContent(content.getPath(), branch)) { modifyOnGithubRecursive(repo, newContent, branch, img, tag); } } else { // The only other case is if we have a file, but content.getDownloadUrl() is null log.info("Skipping submodule {}", content.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); }