private GHRelease findRelease(GHRepository repository, String releaseNameToFind) throws IOException { PagedIterable<GHRelease> releases = repository.listReleases(); for (GHRelease ghRelease : releases) { if (releaseNameToFind.equals(ghRelease.getName())) { return ghRelease; } } return null; }
private String getAssetToDownload(GHRelease release) throws IOException { return release.getAssets().stream().filter(ghAsset -> ghAsset.getName().endsWith("assembly.zip")).map(GHAsset::getBrowserDownloadUrl).findFirst().orElse(null); }
GHAsset wrap(GHRelease release) { this.owner = release.getOwner(); this.root = owner.root; return this; }
static GHRelease[] wrap(GHRelease[] releases, GHRepository owner) { for (GHRelease release : releases) { release.wrap(owner); } return releases; }
private void uploadAsset(GHRelease release, File asset) throws IOException { getLog().info("Processing asset "+asset.getPath()); List<GHAsset> existingAssets = release.getAssets(); for ( GHAsset a : existingAssets ){ if (a.getName().equals( asset.getName() )){ if(overwriteArtifact) { getLog().info(" Deleting existing asset"); a.delete(); } else { getLog().warn("Asset "+asset.getName()+" already exists. Skipping"); return; } } } getLog().info(" Upload asset"); // for some reason this doesn't work currently release.uploadAsset(asset, "application/zip"); }
public List<GHAsset> getAssets() throws IOException { Requester builder = new Requester(owner.root); GHAsset[] assets = builder .method("GET") .to(getApiTailUrl("assets"), GHAsset[].class); return Arrays.asList(GHAsset.wrap(assets, this)); }
/** * Because github relies on SNI (http://en.wikipedia.org/wiki/Server_Name_Indication) this method will only work on * Java 7 or greater. Options for fixing this for earlier JVMs can be found here * http://stackoverflow.com/questions/12361090/server-name-indication-sni-on-java but involve more complicated * handling of the HTTP requests to github's API. * * @throws IOException */ public GHAsset uploadAsset(File file, String contentType) throws IOException { Requester builder = new Requester(owner.root); String url = format("https://uploads.github.com%s/releases/%d/assets?name=%s", owner.getApiTailUrl(""), getId(), file.getName()); return builder.contentType(contentType) .with(new FileInputStream(file)) .to(url, GHAsset.class).wrap(this); }
/** * Because github relies on SNI (http://en.wikipedia.org/wiki/Server_Name_Indication) this method will only work on * Java 7 or greater. Options for fixing this for earlier JVMs can be found here * http://stackoverflow.com/questions/12361090/server-name-indication-sni-on-java but involve more complicated * handling of the HTTP requests to github's API. */ public GHAsset uploadAsset(File file, String contentType) throws IOException { FileInputStream s = new FileInputStream(file); try { return uploadAsset(file.getName(), s, contentType); } finally { s.close(); } }
/** * @deprecated * Use {@link #update()} */ public GHRelease setDraft(boolean draft) throws IOException { return update().draft(draft).update(); }
static GHRelease[] wrap(GHRelease[] releases, GHRepository owner) { for (GHRelease release : releases) { release.wrap(owner); } return releases; }
public List<GHAsset> getAssets() throws IOException { Requester builder = new Requester(owner.root); GHAsset[] assets = builder .method("GET") .to(getApiTailUrl("assets"), GHAsset[].class); return Arrays.asList(GHAsset.wrap(assets, this)); }
public GHAsset uploadAsset(String filename, InputStream stream, String contentType) throws IOException { Requester builder = new Requester(owner.root); String url = format("https://uploads.github.com%s/releases/%d/assets?name=%s", owner.getApiTailUrl(""), getId(), filename); return builder.contentType(contentType) .with(stream) .to(url, GHAsset.class).wrap(this); }
/** * Because github relies on SNI (http://en.wikipedia.org/wiki/Server_Name_Indication) this method will only work on * Java 7 or greater. Options for fixing this for earlier JVMs can be found here * http://stackoverflow.com/questions/12361090/server-name-indication-sni-on-java but involve more complicated * handling of the HTTP requests to github's API. */ public GHAsset uploadAsset(File file, String contentType) throws IOException { FileInputStream s = new FileInputStream(file); try { return uploadAsset(file.getName(), s, contentType); } finally { s.close(); } }
/** * @deprecated * Use {@link #update()} */ public GHRelease setDraft(boolean draft) throws IOException { return update().draft(draft).update(); }
static GHRelease[] wrap(GHRelease[] releases, GHRepository owner) { for (GHRelease release : releases) { release.wrap(owner); } return releases; }
/** * auto updating process */ public static void main(String[] args) throws IOException, ZipException { if (args.length == 2) { Updater updater = new Updater(); GHRelease latestVersion = updater.getLatestVersion(); logger.info("Updating homedash to version:" + latestVersion.getName()); String downloadPath = args[INDEX_DOWNLOAD_PATH]; String installPath = args[INDEX_INSTALL_PATH]; try { updater.doUpdate(downloadPath, installPath); System.exit(0); } catch (FileNotFoundException e) { logger.info("One or both the path given don't exist"); logger.info("Download Path:" + downloadPath); logger.info("Install Path:" + installPath); System.exit(ERROR_WRONG_PATHS_GIVEN); } catch (WrongInstallPathStructure wrongInstallPathStructure) { logger.info("The install path structure doesn't match what is expected"); System.exit(ERROR_INSTALL_PATH_WRONG_STRUCTURE); } } else { logger.info("Missing arguments, arguments given:" + Stream.of(args).collect(Collectors.joining("],[", "[", "]"))); logger.info("Expected: [downloadPath], [installPath]"); System.exit(ERROR_ARGUMENTS); } }
GHAsset wrap(GHRelease release) { this.owner = release.getOwner(); this.root = owner.root; return this; }
public List<GHAsset> getAssets() throws IOException { Requester builder = new Requester(owner.root); GHAsset[] assets = builder .method("GET") .to(getApiTailUrl("assets"), GHAsset[].class); return Arrays.asList(GHAsset.wrap(assets, this)); }
public GHAsset uploadAsset(String filename, InputStream stream, String contentType) throws IOException { Requester builder = new Requester(owner.root); String url = format("https://uploads.github.com%s/releases/%d/assets?name=%s", owner.getApiTailUrl(""), getId(), filename); return builder.contentType(contentType) .with(stream) .to(url, GHAsset.class).wrap(this); }