public GHContent getFileContent(String path) throws IOException { return getFileContent(path, null); }
public GHContent getFileContent(String path) throws IOException { return getFileContent(path, null); }
public GHContent getFileContent(String path) throws IOException { return getFileContent(path, null); }
public GHContent tryRetrievingContent(GHRepository repo, String path, String branch) throws InterruptedException { /* There are issues with the Github api returning that the Github repository exists, but has no content, * when we try to pull on it the moment it is created. The system must wait a short time before we can move on. */ GHContent content = null; for (int i = 0; i < 10; i++) { try { content = repo.getFileContent(path, branch); break; } catch (IOException e1) { log.warn("Content in repository not created yet. Retrying connection to fork..."); Thread.sleep(1000); } } return content; }
public GHContent tryRetrievingContent(GHRepository repo, String path, String branch) throws InterruptedException { /* There are issues with the Github api returning that the Github repository exists, but has no content, * when we try to pull on it the moment it is created. The system must wait a short time before we can move on. */ GHContent content = null; for (int i = 0; i < 10; i++) { try { content = repo.getFileContent(path, branch); break; } catch (IOException e1) { log.warn("Content in repository not created yet. Retrying connection to fork..."); Thread.sleep(1000); } } return content; }
/** * Changes content of the file * * @param pathToFile path to specified file * @param content content to change * @param commitMessage message to commit * @throws IOException */ public void changeFileContent(String pathToFile, String content, String commitMessage) throws IOException { ghRepo.getFileContent(String.format("/%s", pathToFile)).update(content, commitMessage); }
public GHContent getGHFile(final String fileName, final String sha) throws IOException { return getGithubRepository().getFileContent(fileName, sha); }
public InputStream getFileContent(String path) throws IOException { return repository.getFileContent(path).read(); }
public String getFileContent(String pathToFile) throws IOException { return IOUtils.toString(ghRepo.getFileContent(pathToFile).read(), "UTF-8"); }
public void deleteFile(String pathToFile) throws IOException { ghRepo.getFileContent(pathToFile).delete("Delete file " + pathToFile); }
@Test(dependsOnMethods = {"testIdempotency", "testSameNameAcrossDifferentOrgs"}) public void testStoreUpdate() throws Exception { String user = github.getMyself().getLogin(); GHRepository storeRepo = github.getRepository(Paths.get(user, STORE_NAME).toString()); String latestCommit = storeRepo.getBranches().get(storeRepo.getDefaultBranch()).getSHA1(); GHContent store = storeRepo.getFileContent("store.json", latestCommit); try (InputStream stream = store.read(); InputStreamReader streamR = new InputStreamReader(stream)) { JsonElement json = new JsonParser().parse(streamR); assertNotNull(json); JsonElement images = json.getAsJsonObject().get("images"); assertNotNull(images); Object image1 = images.getAsJsonObject().get(IMAGE_1); assertNotNull(image1); Object image2 = images.getAsJsonObject().get(IMAGE_2); assertNotNull(image2); assertEquals(images.getAsJsonObject().get(IMAGE_1).getAsString(), TAG); assertEquals(images.getAsJsonObject().get(IMAGE_2).getAsString(), TAG); } }
String user = github.getMyself().getLogin(); GHRepository storeRepo = github.getRepository(Paths.get(user, STORE_NAME).toString()); GHContent store = storeRepo.getFileContent("store.json"); try (InputStream stream = store.read(); InputStreamReader streamR = new InputStreamReader(stream)) { json = new JsonParser().parse(streamR);
@Test(dependsOnMethods = "testStoreUpdate") public void testAsUser() throws Exception { GHRepository repo = github.getOrganization(ORG).getRepository(NAME); List<GHPullRequest> prs = repo.getPullRequests(GHIssueState.OPEN); Assert.assertTrue(prs.size() == 1); for (GHPullRequest pr : prs) { pr.merge("Automatic merge through itests."); pr.close(); } try (InputStream stream = repo.getFileContent("Dockerfile").read(); InputStreamReader streamR = new InputStreamReader(stream); BufferedReader reader = new BufferedReader(streamR)) { String line; while ((line = reader.readLine()) != null) { if (line.contains("FROM")) { Assert.assertTrue(line.contains(IMAGE)); Assert.assertTrue(line.endsWith(TAG)); } } } }
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()); } }
@Override protected void readDocumentsFromListingFile(GitHubLocation location, List<String> documents, String listingFileName) { try { final GHRepository repo = openRepo(location); final GHBranch branch = selectBranch(location, repo); try { final GHContent content = repo.getFileContent(listingFileName, branch.getName()); final byte[] data = Base64.decodeBase64(content .getEncodedContent().getBytes()); try (Reader in = new InputStreamReader( new ByteArrayInputStream(data))) { final Listing listing = parser.parse(in); for (final String file : listing.getFiles()) { documents.add(MountPointUtil.apply(location, file)); } } } catch (Exception e) { log.debug( "Could not read listing file. That's propably ok if it's missing. msg={}, file={}", e.getMessage(), listingFileName); } } catch (final Exception e) { log.error("failed", e); } }
InputStream load(GHRepository repo, String revision) throws IOException { if (isNull(cachedContent)) { synchronized (this) { if (cachedContent == null) { GHContent content = repo.getFileContent(path, revision); long size = content.getSize(); if (size > CONTENT_THRESHOLD) { // don't cache return content.read(); } byte[] buf = new byte[(int) size]; try (InputStream in = content.read()) { IOUtils.readFully(in, buf); } cachedContent = buf; } } } return new ByteArrayInputStream(cachedContent); }
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()); } }
@Override protected ResourceInfo getResource(final GitHubLocation location, final String path) throws FileNotFoundException { GitHub github = null; GHRepository repo = null; GHBranch branch = null; try { github = location.open(); repo = github.getRepository(location.getRepoName()); log.debug("Using branch={}", location.getBranch()); branch = repo.getBranches().get(location.getBranch()); final GHContent content = repo.getFileContent(path, branch.getName()); final byte[] data = Base64.decodeBase64(content.getEncodedContent() .getBytes()); return new ResourceInfo(path, location, new ByteArrayInputStream( data)); } catch (final FileNotFoundException e) { throw e; } catch (final IOException e) { if (e.getMessage().contains("too_large")) { return getLargeResource(github, repo, branch, location, path); } throw new FileNotFoundException( "Could not locate the file at path " + path + ". e"); } }
break; case NON_DIRECTORY_CONFIRMED: metadata = repo.getFileContent(getPath(), ref); resolved = true; break; checkOpen(); try { metadata = repo.getFileContent(getPath(), ref); info = TypeInfo.NON_DIRECTORY_CONFIRMED; resolved = true;
/** * Creates ".gitmodules" file or updates if it already exist. * * @see <a href="https://git-scm.com/docs/gitmodules">gitmodules </a> */ private void setupSubmoduleConfig(TestGitHubRepository submodule, String pathToSubmoduleContent) throws IOException { final String gitmodulesFileName = ".gitmodules"; String submoduleConfig = getSubmoduleConfig(submodule, pathToSubmoduleContent); if (isGitmodulesFileExist()) { GHContent submoduleFileContent = ghRepo.getFileContent(gitmodulesFileName); String newFileContent = getFileContent(gitmodulesFileName) + "\n" + submoduleConfig; submoduleFileContent.update(newFileContent, "Update " + gitmodulesFileName); return; } ghRepo.createContent(submoduleConfig, "Add " + gitmodulesFileName, gitmodulesFileName); }