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;
}
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();
}
}
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();
}
}
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;
}
Aggregations