Search in sources :

Example 1 with GHCreateRepositoryBuilder

use of org.kohsuke.github.GHCreateRepositoryBuilder in project blueocean-plugin by jenkinsci.

the class GithubHelper method createEmptyRepository.

public String createEmptyRepository() throws IOException {
    GitHub github = getGitHub();
    String repositoryName = !useRandomSuffix ? this.repositoryName : this.repositoryName + "-" + getRandomSuffix();
    try {
        String repositoryFullname = organizationOrUsername + "/" + repositoryName;
        GHRepository repositoryToDelete = github.getRepository(repositoryFullname);
        repositoryToDelete.delete();
        logger.info("Deleted repository " + repositoryFullname);
    } catch (FileNotFoundException e) {
    // fine to ignore error if the repo doesn't exist
    }
    GHCreateRepositoryBuilder builder;
    if (organizationOrUsername.equals(github.getMyself().getLogin())) {
        builder = github.createRepository(repositoryName);
    } else {
        try {
            builder = github.getOrganization(organizationOrUsername).createRepository(repositoryName);
        } catch (FileNotFoundException e) {
            logger.error("found not find organization " + organizationOrUsername);
            throw e;
        }
    }
    githubRepository = builder.autoInit(true).create();
    logger.info("Created repository " + githubRepository.getFullName());
    return repositoryName;
}
Also used : GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) FileNotFoundException(java.io.FileNotFoundException) GHCreateRepositoryBuilder(org.kohsuke.github.GHCreateRepositoryBuilder)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 GHCreateRepositoryBuilder (org.kohsuke.github.GHCreateRepositoryBuilder)1 GHRepository (org.kohsuke.github.GHRepository)1 GitHub (org.kohsuke.github.GitHub)1