mirror of
https://github.com/jlengrand/github-api.git
synced 2026-04-07 15:51:01 +00:00
131 lines
5.0 KiB
HTML
131 lines
5.0 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>GHRef.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">GHRef.java</span></div><h1>GHRef.java</h1><pre class="source lang-java linenums">package org.kohsuke.github;
|
|
|
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|
|
|
import java.io.IOException;
|
|
import java.net.URL;
|
|
|
|
/**
|
|
* Provides information on a Git ref from GitHub.
|
|
*
|
|
* @author Michael Clarke
|
|
*/
|
|
<span class="fc" id="L13">public class GHRef {</span>
|
|
/* package almost final */ GitHub root;
|
|
|
|
private String ref, url;
|
|
private GHObject object;
|
|
|
|
/**
|
|
* Name of the ref, such as "refs/tags/abc"
|
|
*
|
|
* @return the ref
|
|
*/
|
|
public String getRef() {
|
|
<span class="fc" id="L25"> return ref;</span>
|
|
}
|
|
|
|
/**
|
|
* The API URL of this tag, such as https://api.github.com/repos/jenkinsci/jenkins/git/refs/tags/1.312
|
|
*
|
|
* @return the url
|
|
*/
|
|
public URL getUrl() {
|
|
<span class="fc" id="L34"> return GitHubClient.parseURL(url);</span>
|
|
}
|
|
|
|
/**
|
|
* The object that this ref points to.
|
|
*
|
|
* @return the object
|
|
*/
|
|
public GHObject getObject() {
|
|
<span class="fc" id="L43"> return object;</span>
|
|
}
|
|
|
|
/**
|
|
* Updates this ref to the specified commit.
|
|
*
|
|
* @param sha
|
|
* The SHA1 value to set this reference to
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void updateTo(String sha) throws IOException {
|
|
<span class="fc" id="L55"> updateTo(sha, false);</span>
|
|
<span class="fc" id="L56"> }</span>
|
|
|
|
/**
|
|
* Updates this ref to the specified commit.
|
|
*
|
|
* @param sha
|
|
* The SHA1 value to set this reference to
|
|
* @param force
|
|
* Whether or not to force this ref update.
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void updateTo(String sha, Boolean force) throws IOException {
|
|
<span class="fc" id="L69"> root.createRequest()</span>
|
|
<span class="fc" id="L70"> .method("PATCH")</span>
|
|
<span class="fc" id="L71"> .with("sha", sha)</span>
|
|
<span class="fc" id="L72"> .with("force", force)</span>
|
|
<span class="fc" id="L73"> .withUrlPath(url)</span>
|
|
<span class="fc" id="L74"> .fetch(GHRef.class)</span>
|
|
<span class="fc" id="L75"> .wrap(root);</span>
|
|
<span class="fc" id="L76"> }</span>
|
|
|
|
/**
|
|
* Deletes this ref from the repository using the GitHub API.
|
|
*
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void delete() throws IOException {
|
|
<span class="fc" id="L85"> root.createRequest().method("DELETE").withUrlPath(url).send();</span>
|
|
<span class="fc" id="L86"> }</span>
|
|
|
|
GHRef wrap(GitHub root) {
|
|
<span class="fc" id="L89"> this.root = root;</span>
|
|
<span class="fc" id="L90"> return this;</span>
|
|
}
|
|
|
|
/**
|
|
* The type GHObject.
|
|
*/
|
|
@SuppressFBWarnings(
|
|
value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
|
|
justification = "JSON API")
|
|
<span class="fc" id="L99"> public static class GHObject {</span>
|
|
private String type, sha, url;
|
|
|
|
/**
|
|
* Type of the object, such as "commit"
|
|
*
|
|
* @return the type
|
|
*/
|
|
public String getType() {
|
|
<span class="nc" id="L108"> return type;</span>
|
|
}
|
|
|
|
/**
|
|
* SHA1 of this object.
|
|
*
|
|
* @return the sha
|
|
*/
|
|
public String getSha() {
|
|
<span class="fc" id="L117"> return sha;</span>
|
|
}
|
|
|
|
/**
|
|
* API URL to this Git data, such as
|
|
* https://api.github.com/repos/jenkinsci/jenkins/git/commits/b72322675eb0114363a9a86e9ad5a170d1d07ac0
|
|
*
|
|
* @return the url
|
|
*/
|
|
public URL getUrl() {
|
|
<span class="nc" id="L127"> return GitHubClient.parseURL(url);</span>
|
|
}
|
|
}
|
|
}
|
|
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.5.201910111838</span></div></body></html> |