Java Code Examples for org.kohsuke.github.GHRepository#createContent()

The following examples show how to use org.kohsuke.github.GHRepository#createContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCommon.java    From dockerfile-image-update with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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());
    }
}
 
Example 2
Source File: AllCommandTest.java    From dockerfile-image-update with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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();
    gitHubUtil = new GitHubUtil(github);

    cleanBefore(REPOS, DUPLICATES_CREATED_BY_GIT_HUB, STORE_NAME, github);

    GHOrganization org = github.getOrganization(ORGS.get(0));
    initializeRepos(org, REPOS, IMAGE_1, createdRepos, gitHubUtil);

    GHRepository store = github.createRepository(STORE_NAME)
            .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" +
            "  }\n" +
            "}",
            "Integration Testing", "store.json");
    createdRepos.add(store);

    for (String s: ORGS) {
        org = github.getOrganization(s);
        initializeRepos(org, DUPLICATES, IMAGE_2, createdRepos, gitHubUtil);
    }
    /* We need to wait because there is a delay on the search API used in the all command; it takes time
     * for the search API to pick up recently created repositories.
     */
    checkIfSearchUpToDate("image1", IMAGE_1, REPOS.size(), github);
    checkIfSearchUpToDate("image2", IMAGE_2, DUPLICATES.size() * ORGS.size(), github);
}