public GHContentUpdateResponse createContent(byte[] contentBytes, String commitMessage, String path) throws IOException { return createContent(contentBytes, commitMessage, path, null); }
public GHContentUpdateResponse createContent(String content, String commitMessage, String path, String branch) throws IOException { return createContent(content.getBytes(), commitMessage, path, branch); }
public GHContentUpdateResponse createContent(String content, String commitMessage, String path) throws IOException { return createContent(content.getBytes(), commitMessage, path, null); }
/** * Creates file in GitHub repository in the specified {@code branch}. * * @param pathToRootContentDirectory path to the root directory of file locally * @param pathToFile path to file locally * @param branch name of the target branch * @throws IOException */ private void createFile(Path pathToRootContentDirectory, Path pathToFile, String branch) throws IOException { byte[] contentBytes = Files.readAllBytes(pathToFile); String relativePath = pathToRootContentDirectory.relativize(pathToFile).toString(); String commitMessage = String.format("Add file %s", relativePath); try { ghRepo.createContent(contentBytes, commitMessage, relativePath, branch); } catch (GHFileNotFoundException e) { // try to create content once again LOG.warn( "Error of creation of {} occurred. Is trying to create it once again...", ghRepo.getHtmlUrl() + "/" + relativePath); sleepQuietly(GITHUB_OPERATION_TIMEOUT_SEC); ghRepo.createContent(contentBytes, commitMessage, relativePath); } }
/** * Use {@link #createContent()}. */ @Deprecated public GHContentUpdateResponse createContent(byte[] contentBytes, String commitMessage, String path) throws IOException { return createContent().content(contentBytes).message(commitMessage).path(path).commit(); }
/** * Use {@link #createContent()}. */ @Deprecated public GHContentUpdateResponse createContent(byte[] contentBytes, String commitMessage, String path) throws IOException { return createContent().content(contentBytes).message(commitMessage).path(path).commit(); }
/** * Use {@link #createContent()}. */ @Deprecated public GHContentUpdateResponse createContent(String content, String commitMessage, String path) throws IOException { return createContent().content(content).message(commitMessage).path(path).commit(); }
/** * Use {@link #createContent()}. */ @Deprecated public GHContentUpdateResponse createContent(String content, String commitMessage, String path) throws IOException { return createContent().content(content).message(commitMessage).path(path).commit(); }
/** * Use {@link #createContent()}. */ @Deprecated public GHContentUpdateResponse createContent(String content, String commitMessage, String path, String branch) throws IOException { return createContent().content(content).message(commitMessage).path(path).branch(branch).commit(); }
/** * Use {@link #createContent()}. */ @Deprecated public GHContentUpdateResponse createContent(byte[] contentBytes, String commitMessage, String path, String branch) throws IOException { return createContent().content(contentBytes).message(commitMessage).path(path).branch(branch).commit(); }
/** * Use {@link #createContent()}. */ @Deprecated public GHContentUpdateResponse createContent(byte[] contentBytes, String commitMessage, String path, String branch) throws IOException { return createContent().content(contentBytes).message(commitMessage).path(path).branch(branch).commit(); }
/** * Use {@link #createContent()}. */ @Deprecated public GHContentUpdateResponse createContent(String content, String commitMessage, String path, String branch) throws IOException { return createContent().content(content).message(commitMessage).path(path).branch(branch).commit(); }
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()); } }
public static void initializeRepos(GHOrganization org, List<String> repos, String image, List<GHRepository> createdRepos, GitHubUtil gitHubUtil) throws Exception { for (String repoName : repos) { GHRepository repo = org.createRepository(repoName) .description("Delete if this exists. If it exists, then an integration test crashed somewhere.") .private_(false) .create(); // Ensure that repository exists for (int attempts = 0; attempts < 5; attempts++) { try { repo = gitHubUtil.getRepo(repo.getFullName()); break; } catch (Exception e) { log.info("Waiting for {} to be created", repo.getFullName()); Thread.sleep(TimeUnit.SECONDS.toMillis(1)); } } repo.createContent("FROM " + image + ":test", "Integration Testing", "Dockerfile"); createdRepos.add(repo); log.info("Initializing {}/{}", org.getLogin(), repoName); gitHubUtil.tryRetrievingContent(repo, "Dockerfile", repo.getDefaultBranch()); } }
@BeforeClass public void setUp() throws Exception { String gitApiUrl = System.getenv("git_api_url"); String token = System.getenv("git_api_token"); github = new GitHubBuilder().withEndpoint(gitApiUrl) .withOAuthToken(token) .build(); github.checkApiUrlValidity(); cleanBefore(); gitHubUtil = new GitHubUtil(github); GHOrganization org = github.getOrganization(ORG); GHRepository repo = org.createRepository(NAME) .description("Delete if this exists. If it exists, then an integration test crashed somewhere.") .private_(false) .create(); log.info("Initializing {}", repo.getFullName()); createdRepos.add(repo); repo.createContent("FROM " + IMAGE + ":test", "Integration Testing", "Dockerfile"); }
/** * 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); }
.description("Delete if this exists. If it exists, then an integration test crashed somewhere.") .create(); store.createContent("{\n \"images\": {\n" + " \"" + IMAGE_1 + "\": \"" + TEST_TAG + "\",\n" + " \"" + IMAGE_2 + "\": \"" + TEST_TAG + "\"\n" +