Search in sources :

Example 11 with GitHub

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

the class GitTest method connectTest.

@Test
public void connectTest() throws IOException {
    GitHub github = GitHub.connect();
    github.checkApiUrlValidity();
}
Also used : GitHub(org.kohsuke.github.GitHub) Test(org.junit.Test)

Example 12 with GitHub

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

Example 13 with GitHub

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

the class UpdateUtils method isAvailable.

public static boolean isAvailable() {
    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 false;
        } else {
            Logger.info("detected new version");
            Logger.info("current version: " + CONSTANTS.VERSION);
            Logger.info("latest version: " + latest.getTagName().replaceAll("v", ""));
            return true;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}
Also used : GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) IOException(java.io.IOException) Semver(com.vdurmont.semver4j.Semver) GHRelease(org.kohsuke.github.GHRelease)

Example 14 with GitHub

use of org.kohsuke.github.GitHub in project nextprot-api by calipho-sib.

the class GitHubServiceImpl method getTree.

@Override
@Cacheable(value = "github-tree")
public GHTree getTree() {
    try {
        GitHub github = getGitHubConnection();
        GHRepository repo = github.getRepository("calipho-sib/nextprot-docs");
        return repo.getTreeRecursive(githubDocBranch, 1);
    } catch (IOException e) {
        e.printStackTrace();
        throw new NextProtException("Documentation not available, sorry for the inconvenience");
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) IOException(java.io.IOException) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 15 with GitHub

use of org.kohsuke.github.GitHub in project nextprot-api by calipho-sib.

the class GitHubServiceImpl method getPage.

@Override
@Cacheable(value = "github-pages")
public String getPage(String folder, String page) {
    String finalPage = page;
    if ("news".equalsIgnoreCase(folder)) {
        finalPage = getCorrespondingPageForNews(page);
    }
    try {
        GitHub github = getGitHubConnection();
        GHRepository repo = github.getRepository("calipho-sib/nextprot-docs");
        GHContent content = null;
        String extension = ".md";
        if (folder.contains("json")) {
            // if folder contains json
            extension = ".json";
        }
        content = repo.getFileContent(folder + "/" + finalPage + extension, githubDocBranch);
        return content.getContent();
    } catch (IOException e) {
        e.printStackTrace();
        throw new NextProtException("Documentation not available, sorry for the inconvenience");
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) GHContent(org.kohsuke.github.GHContent) IOException(java.io.IOException) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

GitHub (org.kohsuke.github.GitHub)21 GHRepository (org.kohsuke.github.GHRepository)17 IOException (java.io.IOException)10 Test (org.junit.Test)5 GHRelease (org.kohsuke.github.GHRelease)5 Semver (com.vdurmont.semver4j.Semver)4 File (java.io.File)3 ArrayList (java.util.ArrayList)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 FileInputStream (java.io.FileInputStream)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 GHAsset (org.kohsuke.github.GHAsset)2 GHUser (org.kohsuke.github.GHUser)2 HttpException (org.kohsuke.github.HttpException)2 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)1 ServiceException (io.jenkins.blueocean.commons.ServiceException)1