Search in sources :

Example 11 with GHRepository

use of org.kohsuke.github.GHRepository in project Gargoyle by callakrsos.

the class GitTest method readContent.

@Test
public void readContent() throws IOException {
    GitHub github = GitHub.connect();
    GHUser user = github.getUser("callakrsos");
    //Gargoyle Repository 정보 출력
    GHRepository repository = user.getRepository("Gargoyle");
    System.out.println(repository);
    GHContent fileContent = repository.getFileContent(".project", "master");
    String string = fileContent.toString();
    System.out.println(string);
    String downloadUrl = fileContent.getDownloadUrl();
    System.out.println(downloadUrl);
    String gitUrl = fileContent.getGitUrl();
    System.out.println(gitUrl);
    try (BufferedReader br = new BufferedReader(new InputStreamReader(fileContent.read()))) {
        String readLine = null;
        while ((readLine = br.readLine()) != null) {
            System.out.println(readLine);
        }
    }
}
Also used : GHRepository(org.kohsuke.github.GHRepository) InputStreamReader(java.io.InputStreamReader) GitHub(org.kohsuke.github.GitHub) GHContent(org.kohsuke.github.GHContent) BufferedReader(java.io.BufferedReader) GHUser(org.kohsuke.github.GHUser) Test(org.junit.Test)

Example 12 with GHRepository

use of org.kohsuke.github.GHRepository in project Gargoyle by callakrsos.

the class GitTest method listRepositories.

@Test
public void listRepositories() throws IOException {
    GitHub github = GitHub.connect();
    PagedIterable<GHRepository> listAllPublicRepositories = github.listAllPublicRepositories();
    PagedIterator<GHRepository> iterator = listAllPublicRepositories.iterator();
    while (iterator.hasNext()) {
        GHRepository next = iterator.next();
        System.out.println(next);
    }
}
Also used : GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) Test(org.junit.Test)

Example 13 with GHRepository

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

the class GithubEditorTest method deleteRepository.

/**
 * Cleans up repository after the test has completed.
 *
 * @throws IOException
 */
@After
public void deleteRepository() throws IOException {
    if (deleteRepo) {
        try {
            GHRepository repositoryToDelete = github.getRepository(organization + "/" + repo);
            repositoryToDelete.delete();
            logger.info("Deleted repository " + repo);
        } catch (FileNotFoundException e) {
        }
    }
}
Also used : GHRepository(org.kohsuke.github.GHRepository) FileNotFoundException(java.io.FileNotFoundException) After(org.junit.After)

Example 14 with GHRepository

use of org.kohsuke.github.GHRepository 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)

Example 15 with GHRepository

use of org.kohsuke.github.GHRepository in project Robot by fo0.

the class UpdateUtils method doUpdate.

public static void doUpdate() {
    try {
        GitHub gitHub = GitHub.connectAnonymously();
        GHRepository repository = gitHub.getRepository(CONSTANTS.GITHUB_URI);
        GHRelease latest = repository.getLatestRelease();
        boolean newerVersionAvailable = new Semver(latest.getTagName().replaceAll("v", "")).isGreaterThan(new Semver(CONSTANTS.VERSION));
        if (!newerVersionAvailable) {
            Logger.info("no newer version available, skipping now");
            Logger.info("current version: " + CONSTANTS.VERSION);
            Logger.info("latest version: " + latest.getTagName().replaceAll("v", ""));
            return;
        } else {
            Logger.info("detected new version");
            Logger.info("current version: " + CONSTANTS.VERSION);
            Logger.info("latest version: " + latest.getTagName().replaceAll("v", ""));
        }
        GHAsset asset = latest.getAssets().get(0);
        Logger.info("downloading file from github: " + asset.getBrowserDownloadUrl());
        File latestFile = File.createTempFile(Random.alphanumeric(10), ".patch");
        latestFile.deleteOnExit();
        FileUtils.copyToFile(new URL(asset.getBrowserDownloadUrl()).openStream(), latestFile);
        Logger.info("download finished");
        Logger.info("applying patch...");
        File currentPath = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath());
        Utils.writeBytesToFile(IOUtils.toByteArray(new FileInputStream(latestFile)), currentPath);
        // FileUtils.moveFile(latestFile, currentPath);
        try {
            latestFile.delete();
        } catch (Exception e) {
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) Semver(com.vdurmont.semver4j.Semver) File(java.io.File) GHAsset(org.kohsuke.github.GHAsset) URL(java.net.URL) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) GHRelease(org.kohsuke.github.GHRelease)

Aggregations

GHRepository (org.kohsuke.github.GHRepository)23 GitHub (org.kohsuke.github.GitHub)15 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)4 GHRelease (org.kohsuke.github.GHRelease)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 Test (org.junit.Test)3 GHContent (org.kohsuke.github.GHContent)3 GHIssue (org.kohsuke.github.GHIssue)3 NextProtException (org.nextprot.api.commons.exception.NextProtException)3 Cacheable (org.springframework.cache.annotation.Cacheable)3 Semver (com.vdurmont.semver4j.Semver)2 HashMap (java.util.HashMap)2 TaskAction (org.gradle.api.tasks.TaskAction)2 GHPullRequest (org.kohsuke.github.GHPullRequest)2 GHTree (org.kohsuke.github.GHTree)2 GHUser (org.kohsuke.github.GHUser)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 BufferedReader (java.io.BufferedReader)1