Search in sources :

Example 1 with GHRelease

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

the class UpdateUtils method getVersion.

public static String getVersion() {
    try {
        GitHub gitHub = GitHub.connectAnonymously();
        GHRepository repository = gitHub.getRepository(CONSTANTS.GITHUB_URI);
        GHRelease latest = repository.getLatestRelease();
        return latest.getTagName().replaceAll("v", "");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) IOException(java.io.IOException) GHRelease(org.kohsuke.github.GHRelease)

Example 2 with GHRelease

use of org.kohsuke.github.GHRelease in project zaproxy by zaproxy.

the class CreateGitHubRelease method createRelease.

@TaskAction
public void createRelease() throws IOException {
    if (bodyFile.isPresent() && body.isPresent()) {
        throw new InvalidUserDataException("Only one type of body property must be set.");
    }
    if (checksumAlgorithm.get().isEmpty()) {
        throw new IllegalArgumentException("The checksum algorithm must not be empty.");
    }
    GitHubUser ghUser = getUser().get();
    GHRepository ghRepo = GitHub.connect(ghUser.getName(), ghUser.getAuthToken()).getRepository(repo.get());
    validateTagExists(ghRepo, tag.get());
    validateReleaseDoesNotExist(ghRepo, tag.get());
    StringBuilder releaseBody = new StringBuilder(250);
    releaseBody.append(bodyFile.isPresent() ? readContents(bodyFile.getAsFile().get().toPath()) : body.getOrElse(""));
    if (addChecksums.get()) {
        if (releaseBody.length() != 0) {
            releaseBody.append("\n\n---\n");
        }
        appendChecksumsTable(releaseBody);
    }
    GHRelease release = ghRepo.createRelease(tag.get()).name(title.get()).body(releaseBody.toString()).prerelease(prerelease.get()).draft(true).create();
    for (Asset asset : assets) {
        release.uploadAsset(asset.getFile().getAsFile().get(), asset.getContentType().get());
    }
    if (!draft.get()) {
        release.update().draft(false).update();
    }
}
Also used : GitHubUser(org.zaproxy.zap.GitHubUser) GHRepository(org.kohsuke.github.GHRepository) InvalidUserDataException(org.gradle.api.InvalidUserDataException) GHRelease(org.kohsuke.github.GHRelease) TaskAction(org.gradle.api.tasks.TaskAction)

Example 3 with GHRelease

use of org.kohsuke.github.GHRelease 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 4 with GHRelease

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

Aggregations

GHRelease (org.kohsuke.github.GHRelease)4 GHRepository (org.kohsuke.github.GHRepository)4 IOException (java.io.IOException)3 GitHub (org.kohsuke.github.GitHub)3 Semver (com.vdurmont.semver4j.Semver)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 URL (java.net.URL)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 TaskAction (org.gradle.api.tasks.TaskAction)1 GHAsset (org.kohsuke.github.GHAsset)1 GitHubUser (org.zaproxy.zap.GitHubUser)1