mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-27 15:50:41 +00:00
316 lines
10 KiB
HTML
316 lines
10 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>GHRelease.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">GitHub API for Java</a> > <a href="index.source.html" class="el_package">org.kohsuke.github</a> > <span class="el_source">GHRelease.java</span></div><h1>GHRelease.java</h1><pre class="source lang-java linenums">package org.kohsuke.github;
|
|
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.net.URL;
|
|
import java.net.URLEncoder;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
import static java.lang.String.*;
|
|
|
|
/**
|
|
* Release in a github repository.
|
|
*
|
|
* @see GHRepository#getReleases() GHRepository#getReleases()
|
|
* @see GHRepository#listReleases() () GHRepository#listReleases()
|
|
* @see GHRepository#createRelease(String) GHRepository#createRelease(String)
|
|
*/
|
|
<span class="fc" id="L21">public class GHRelease extends GHObject {</span>
|
|
GHRepository owner;
|
|
|
|
private String html_url;
|
|
private String assets_url;
|
|
private List<GHAsset> assets;
|
|
private String upload_url;
|
|
private String tag_name;
|
|
private String target_commitish;
|
|
private String name;
|
|
private String body;
|
|
private boolean draft;
|
|
private boolean prerelease;
|
|
private Date published_at;
|
|
private String tarball_url;
|
|
private String zipball_url;
|
|
|
|
/**
|
|
* Gets assets url.
|
|
*
|
|
* @return the assets url
|
|
*/
|
|
public String getAssetsUrl() {
|
|
<span class="nc" id="L44"> return assets_url;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets body.
|
|
*
|
|
* @return the body
|
|
*/
|
|
public String getBody() {
|
|
<span class="fc" id="L53"> return body;</span>
|
|
}
|
|
|
|
/**
|
|
* Is draft boolean.
|
|
*
|
|
* @return the boolean
|
|
*/
|
|
public boolean isDraft() {
|
|
<span class="nc" id="L62"> return draft;</span>
|
|
}
|
|
|
|
/**
|
|
* Sets draft.
|
|
*
|
|
* @param draft
|
|
* the draft
|
|
* @return the draft
|
|
* @throws IOException
|
|
* the io exception
|
|
* @deprecated Use {@link #update()}
|
|
*/
|
|
@Deprecated
|
|
public GHRelease setDraft(boolean draft) throws IOException {
|
|
<span class="nc" id="L77"> return update().draft(draft).update();</span>
|
|
}
|
|
|
|
public URL getHtmlUrl() {
|
|
<span class="fc" id="L81"> return GitHubClient.parseURL(html_url);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets name.
|
|
*
|
|
* @return the name
|
|
*/
|
|
public String getName() {
|
|
<span class="fc" id="L90"> return name;</span>
|
|
}
|
|
|
|
/**
|
|
* Sets name.
|
|
*
|
|
* @param name
|
|
* the name
|
|
*/
|
|
public void setName(String name) {
|
|
<span class="nc" id="L100"> this.name = name;</span>
|
|
<span class="nc" id="L101"> }</span>
|
|
|
|
/**
|
|
* Gets owner.
|
|
*
|
|
* @return the owner
|
|
*/
|
|
public GHRepository getOwner() {
|
|
<span class="fc" id="L109"> return owner;</span>
|
|
}
|
|
|
|
/**
|
|
* Sets owner.
|
|
*
|
|
* @param owner
|
|
* the owner
|
|
*/
|
|
public void setOwner(GHRepository owner) {
|
|
<span class="nc" id="L119"> this.owner = owner;</span>
|
|
<span class="nc" id="L120"> }</span>
|
|
|
|
/**
|
|
* Is prerelease boolean.
|
|
*
|
|
* @return the boolean
|
|
*/
|
|
public boolean isPrerelease() {
|
|
<span class="nc" id="L128"> return prerelease;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets published at.
|
|
*
|
|
* @return the published at
|
|
*/
|
|
public Date getPublished_at() {
|
|
<span class="nc" id="L137"> return new Date(published_at.getTime());</span>
|
|
}
|
|
|
|
/**
|
|
* Gets root.
|
|
*
|
|
* @return the root
|
|
*/
|
|
public GitHub getRoot() {
|
|
<span class="nc" id="L146"> return root;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets tag name.
|
|
*
|
|
* @return the tag name
|
|
*/
|
|
public String getTagName() {
|
|
<span class="fc" id="L155"> return tag_name;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets target commitish.
|
|
*
|
|
* @return the target commitish
|
|
*/
|
|
public String getTargetCommitish() {
|
|
<span class="fc" id="L164"> return target_commitish;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets upload url.
|
|
*
|
|
* @return the upload url
|
|
*/
|
|
public String getUploadUrl() {
|
|
<span class="fc" id="L173"> return upload_url;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets zipball url.
|
|
*
|
|
* @return the zipball url
|
|
*/
|
|
public String getZipballUrl() {
|
|
<span class="fc" id="L182"> return zipball_url;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets tarball url.
|
|
*
|
|
* @return the tarball url
|
|
*/
|
|
public String getTarballUrl() {
|
|
<span class="fc" id="L191"> return tarball_url;</span>
|
|
}
|
|
|
|
GHRelease wrap(GHRepository owner) {
|
|
<span class="fc" id="L195"> this.owner = owner;</span>
|
|
<span class="fc" id="L196"> this.root = owner.root;</span>
|
|
<span class="fc" id="L197"> return this;</span>
|
|
}
|
|
|
|
static GHRelease[] wrap(GHRelease[] releases, GHRepository owner) {
|
|
<span class="nc bnc" id="L201" title="All 2 branches missed."> for (GHRelease release : releases) {</span>
|
|
<span class="nc" id="L202"> release.wrap(owner);</span>
|
|
}
|
|
<span class="nc" id="L204"> return releases;</span>
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
*
|
|
* @param file
|
|
* the file
|
|
* @param contentType
|
|
* the content type
|
|
* @return the gh asset
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHAsset uploadAsset(File file, String contentType) throws IOException {
|
|
<span class="fc" id="L222"> FileInputStream s = new FileInputStream(file);</span>
|
|
try {
|
|
<span class="fc" id="L224"> return uploadAsset(file.getName(), s, contentType);</span>
|
|
} finally {
|
|
<span class="fc" id="L226"> s.close();</span>
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Upload asset gh asset.
|
|
*
|
|
* @param filename
|
|
* the filename
|
|
* @param stream
|
|
* the stream
|
|
* @param contentType
|
|
* the content type
|
|
* @return the gh asset
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHAsset uploadAsset(String filename, InputStream stream, String contentType) throws IOException {
|
|
<span class="fc" id="L244"> Requester builder = owner.root.createRequest().method("POST");</span>
|
|
<span class="fc" id="L245"> String url = getUploadUrl();</span>
|
|
// strip the helpful garbage from the url
|
|
<span class="fc" id="L247"> url = url.substring(0, url.indexOf('{'));</span>
|
|
<span class="fc" id="L248"> url += "?name=" + URLEncoder.encode(filename, "UTF-8");</span>
|
|
<span class="fc" id="L249"> return builder.contentType(contentType).with(stream).withUrlPath(url).fetch(GHAsset.class).wrap(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Get the cached assets.
|
|
*
|
|
* @return the assets
|
|
*
|
|
* @deprecated This should be the default behavior of {@link #getAssets()} in a future release. This method is
|
|
* introduced in addition to enable a transition to using cached asset information while keeping the
|
|
* existing logic in place for backwards compatibility.
|
|
*/
|
|
@Deprecated
|
|
public List<GHAsset> assets() {
|
|
<span class="fc" id="L263"> return assets;</span>
|
|
}
|
|
|
|
/**
|
|
* Re-fetch the assets of this release.
|
|
*
|
|
* @return the assets
|
|
* @throws IOException
|
|
* the io exception
|
|
* @deprecated The behavior of this method will change in a future release. It will then provide cached assets as
|
|
* provided by {@link #assets()}. Use {@link #listAssets()} instead to fetch up-to-date information of
|
|
* assets.
|
|
*/
|
|
@Deprecated
|
|
public List<GHAsset> getAssets() throws IOException {
|
|
<span class="fc" id="L278"> return listAssets().toList();</span>
|
|
}
|
|
|
|
/**
|
|
* Re-fetch the assets of this release.
|
|
*
|
|
* @return the assets
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public PagedIterable<GHAsset> listAssets() throws IOException {
|
|
<span class="fc" id="L289"> Requester builder = owner.root.createRequest();</span>
|
|
<span class="fc" id="L290"> return builder.withUrlPath(getApiTailUrl("assets")).toIterable(GHAsset[].class, item -> item.wrap(this));</span>
|
|
}
|
|
|
|
/**
|
|
* Deletes this release.
|
|
*
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void delete() throws IOException {
|
|
<span class="nc" id="L300"> root.createRequest().method("DELETE").withUrlPath(owner.getApiTailUrl("releases/" + getId())).send();</span>
|
|
<span class="nc" id="L301"> }</span>
|
|
|
|
/**
|
|
* Updates this release via a builder.
|
|
*
|
|
* @return the gh release updater
|
|
*/
|
|
public GHReleaseUpdater update() {
|
|
<span class="nc" id="L309"> return new GHReleaseUpdater(this);</span>
|
|
}
|
|
|
|
private String getApiTailUrl(String end) {
|
|
<span class="fc" id="L313"> return owner.getApiTailUrl(format("releases/%s/%s", getId(), end));</span>
|
|
}
|
|
}
|
|
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html> |