mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-29 08:21:24 +00:00
115 lines
4.8 KiB
HTML
115 lines
4.8 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>GHContentBuilder.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">GHContentBuilder.java</span></div><h1>GHContentBuilder.java</h1><pre class="source lang-java linenums">package org.kohsuke.github;
|
|
|
|
import java.io.IOException;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.Base64;
|
|
|
|
/**
|
|
* Used to create/update content.
|
|
*
|
|
* <p>
|
|
* Call various methods to build up parameters, then call {@link #commit()} to make the change effective.
|
|
*
|
|
* @author Kohsuke Kawaguchi
|
|
* @see GHRepository#createContent() GHRepository#createContent()
|
|
*/
|
|
public final class GHContentBuilder {
|
|
private final GHRepository repo;
|
|
private final Requester req;
|
|
private String path;
|
|
|
|
<span class="fc" id="L21"> GHContentBuilder(GHRepository repo) {</span>
|
|
<span class="fc" id="L22"> this.repo = repo;</span>
|
|
<span class="fc" id="L23"> this.req = repo.root.createRequest().method("PUT");</span>
|
|
<span class="fc" id="L24"> }</span>
|
|
|
|
/**
|
|
* Path gh content builder.
|
|
*
|
|
* @param path
|
|
* the path
|
|
* @return the gh content builder
|
|
*/
|
|
public GHContentBuilder path(String path) {
|
|
<span class="fc" id="L34"> this.path = path;</span>
|
|
<span class="fc" id="L35"> req.with("path", path);</span>
|
|
<span class="fc" id="L36"> return this;</span>
|
|
}
|
|
|
|
/**
|
|
* Branch gh content builder.
|
|
*
|
|
* @param branch
|
|
* the branch
|
|
* @return the gh content builder
|
|
*/
|
|
public GHContentBuilder branch(String branch) {
|
|
<span class="fc" id="L47"> req.with("branch", branch);</span>
|
|
<span class="fc" id="L48"> return this;</span>
|
|
}
|
|
|
|
/**
|
|
* Used when updating (but not creating a new content) to specify the blob SHA of the file being replaced.
|
|
*
|
|
* @param sha
|
|
* the sha
|
|
* @return the gh content builder
|
|
*/
|
|
public GHContentBuilder sha(String sha) {
|
|
<span class="fc" id="L59"> req.with("sha", sha);</span>
|
|
<span class="fc" id="L60"> return this;</span>
|
|
}
|
|
|
|
/**
|
|
* Content gh content builder.
|
|
*
|
|
* @param content
|
|
* the content
|
|
* @return the gh content builder
|
|
*/
|
|
public GHContentBuilder content(byte[] content) {
|
|
<span class="fc" id="L71"> req.with("content", Base64.getEncoder().encodeToString(content));</span>
|
|
<span class="fc" id="L72"> return this;</span>
|
|
}
|
|
|
|
/**
|
|
* Content gh content builder.
|
|
*
|
|
* @param content
|
|
* the content
|
|
* @return the gh content builder
|
|
*/
|
|
public GHContentBuilder content(String content) {
|
|
<span class="fc" id="L83"> return content(content.getBytes(StandardCharsets.UTF_8));</span>
|
|
}
|
|
|
|
/**
|
|
* Message gh content builder.
|
|
*
|
|
* @param commitMessage
|
|
* the commit message
|
|
* @return the gh content builder
|
|
*/
|
|
public GHContentBuilder message(String commitMessage) {
|
|
<span class="fc" id="L94"> req.with("message", commitMessage);</span>
|
|
<span class="fc" id="L95"> return this;</span>
|
|
}
|
|
|
|
/**
|
|
* Commits a new content.
|
|
*
|
|
* @return the gh content update response
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHContentUpdateResponse commit() throws IOException {
|
|
<span class="fc" id="L106"> GHContentUpdateResponse response = req.withUrlPath(GHContent.getApiRoute(repo, path))</span>
|
|
<span class="fc" id="L107"> .fetch(GHContentUpdateResponse.class);</span>
|
|
|
|
<span class="fc" id="L109"> response.getContent().wrap(repo);</span>
|
|
<span class="fc" id="L110"> response.getCommit().wrapUp(repo);</span>
|
|
|
|
<span class="fc" id="L112"> return response;</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> |