mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-30 08:21:23 +00:00
2796 lines
108 KiB
HTML
2796 lines
108 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>GHRepository.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">GHRepository.java</span></div><h1>GHRepository.java</h1><pre class="source lang-java linenums">/*
|
|
* The MIT License
|
|
*
|
|
* Copyright (c) 2010, Kohsuke Kawaguchi
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
* THE SOFTWARE.
|
|
*/
|
|
package org.kohsuke.github;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
|
import edu.umd.cs.findbugs.annotations.CheckForNull;
|
|
import edu.umd.cs.findbugs.annotations.NonNull;
|
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStreamReader;
|
|
import java.io.InterruptedIOException;
|
|
import java.io.Reader;
|
|
import java.net.URL;
|
|
import java.util.AbstractSet;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.Collections;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.TreeMap;
|
|
import java.util.WeakHashMap;
|
|
|
|
import static java.util.Arrays.*;
|
|
import static org.kohsuke.github.Previews.*;
|
|
|
|
/**
|
|
* A repository on GitHub.
|
|
*
|
|
* @author Kohsuke Kawaguchi
|
|
*/
|
|
@SuppressWarnings({ "UnusedDeclaration" })
|
|
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
|
|
justification = "JSON API")
|
|
<span class="fc" id="L65">public class GHRepository extends GHObject {</span>
|
|
/* package almost final */ GitHub root;
|
|
|
|
private String description, homepage, name, full_name;
|
|
private String html_url; // this is the UI
|
|
/*
|
|
* The license information makes use of the preview API.
|
|
*
|
|
* See: https://developer.github.com/v3/licenses/
|
|
*/
|
|
private GHLicense license;
|
|
|
|
private String git_url, ssh_url, clone_url, svn_url, mirror_url;
|
|
private GHUser owner; // not fully populated. beware.
|
|
private boolean has_issues, has_wiki, fork, has_downloads, has_pages, archived, has_projects;
|
|
|
|
private boolean allow_squash_merge;
|
|
private boolean allow_merge_commit;
|
|
private boolean allow_rebase_merge;
|
|
|
|
private boolean delete_branch_on_merge;
|
|
|
|
@JsonProperty("private")
|
|
private boolean _private;
|
|
private int forks_count, stargazers_count, watchers_count, size, open_issues_count, subscribers_count;
|
|
private String pushed_at;
|
|
<span class="fc" id="L91"> private Map<Integer, GHMilestone> milestones = new WeakHashMap<Integer, GHMilestone>();</span>
|
|
|
|
private String default_branch, language;
|
|
<span class="fc" id="L94"> private Map<String, GHCommit> commits = new WeakHashMap<String, GHCommit>();</span>
|
|
|
|
@SkipFromToString
|
|
private GHRepoPermission permissions;
|
|
|
|
private GHRepository source, parent;
|
|
|
|
/**
|
|
* Create deployment gh deployment builder.
|
|
*
|
|
* @param ref
|
|
* the ref
|
|
* @return the gh deployment builder
|
|
*/
|
|
public GHDeploymentBuilder createDeployment(String ref) {
|
|
<span class="fc" id="L109"> return new GHDeploymentBuilder(this, ref);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets deployment statuses.
|
|
*
|
|
* @param id
|
|
* the id
|
|
* @return the deployment statuses
|
|
* @throws IOException
|
|
* the io exception
|
|
* @deprecated Use {@code getDeployment(id).listStatuses()}
|
|
*/
|
|
@Deprecated
|
|
public PagedIterable<GHDeploymentStatus> getDeploymentStatuses(final int id) throws IOException {
|
|
<span class="nc" id="L124"> return getDeployment(id).listStatuses();</span>
|
|
}
|
|
|
|
/**
|
|
* List deployments paged iterable.
|
|
*
|
|
* @param sha
|
|
* the sha
|
|
* @param ref
|
|
* the ref
|
|
* @param task
|
|
* the task
|
|
* @param environment
|
|
* the environment
|
|
* @return the paged iterable
|
|
*/
|
|
public PagedIterable<GHDeployment> listDeployments(String sha, String ref, String task, String environment) {
|
|
<span class="fc" id="L141"> return root.createRequest()</span>
|
|
<span class="fc" id="L142"> .with("sha", sha)</span>
|
|
<span class="fc" id="L143"> .with("ref", ref)</span>
|
|
<span class="fc" id="L144"> .with("task", task)</span>
|
|
<span class="fc" id="L145"> .with("environment", environment)</span>
|
|
<span class="fc" id="L146"> .withUrlPath(getApiTailUrl("deployments"))</span>
|
|
<span class="fc" id="L147"> .toIterable(GHDeployment[].class, item -> item.wrap(this));</span>
|
|
}
|
|
|
|
/**
|
|
* Obtains a single {@link GHDeployment} by its ID.
|
|
*
|
|
* @param id
|
|
* the id
|
|
* @return the deployment
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHDeployment getDeployment(long id) throws IOException {
|
|
<span class="fc" id="L160"> return root.createRequest()</span>
|
|
<span class="fc" id="L161"> .withUrlPath(getApiTailUrl("deployments/" + id))</span>
|
|
<span class="fc" id="L162"> .fetch(GHDeployment.class)</span>
|
|
<span class="fc" id="L163"> .wrap(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets deploy status.
|
|
*
|
|
* @param deploymentId
|
|
* the deployment id
|
|
* @param ghDeploymentState
|
|
* the gh deployment state
|
|
* @return the deploy status
|
|
* @throws IOException
|
|
* the io exception
|
|
* @deprecated Use {@code getDeployment(deploymentId).createStatus(ghDeploymentState)}
|
|
*/
|
|
@Deprecated
|
|
public GHDeploymentStatusBuilder createDeployStatus(int deploymentId, GHDeploymentState ghDeploymentState)
|
|
throws IOException {
|
|
<span class="nc" id="L181"> return getDeployment(deploymentId).createStatus(ghDeploymentState);</span>
|
|
}
|
|
|
|
private static class GHRepoPermission {
|
|
boolean pull, push, admin;
|
|
}
|
|
|
|
/**
|
|
* Gets description.
|
|
*
|
|
* @return the description
|
|
*/
|
|
public String getDescription() {
|
|
<span class="fc" id="L194"> return description;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets homepage.
|
|
*
|
|
* @return the homepage
|
|
*/
|
|
public String getHomepage() {
|
|
<span class="nc" id="L203"> return homepage;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the git:// URL to this repository, such as "git://github.com/kohsuke/jenkins.git" This URL is read-only.
|
|
*
|
|
* @return the git transport url
|
|
*/
|
|
public String getGitTransportUrl() {
|
|
<span class="nc" id="L212"> return git_url;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the HTTPS URL to this repository, such as "https://github.com/kohsuke/jenkins.git" This URL is read-only.
|
|
*
|
|
* @return the http transport url
|
|
*/
|
|
public String getHttpTransportUrl() {
|
|
<span class="nc" id="L221"> return clone_url;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the Subversion URL to access this repository: https://github.com/rails/rails
|
|
*
|
|
* @return the svn url
|
|
*/
|
|
public String getSvnUrl() {
|
|
<span class="nc" id="L230"> return svn_url;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the Mirror URL to access this repository: https://github.com/apache/tomee mirrored from
|
|
* git://git.apache.org/tomee.git
|
|
*
|
|
* @return the mirror url
|
|
*/
|
|
public String getMirrorUrl() {
|
|
<span class="nc" id="L240"> return mirror_url;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the SSH URL to access this repository, such as git@github.com:rails/rails.git
|
|
*
|
|
* @return the ssh url
|
|
*/
|
|
public String getSshUrl() {
|
|
<span class="nc" id="L249"> return ssh_url;</span>
|
|
}
|
|
|
|
public URL getHtmlUrl() {
|
|
<span class="nc" id="L253"> return GitHubClient.parseURL(html_url);</span>
|
|
}
|
|
|
|
/**
|
|
* Short repository name without the owner. For example 'jenkins' in case of http://github.com/jenkinsci/jenkins
|
|
*
|
|
* @return the name
|
|
*/
|
|
public String getName() {
|
|
<span class="fc" id="L262"> return name;</span>
|
|
}
|
|
|
|
/**
|
|
* Full repository name including the owner or organization. For example 'jenkinsci/jenkins' in case of
|
|
* http://github.com/jenkinsci/jenkins
|
|
*
|
|
* @return the full name
|
|
*/
|
|
public String getFullName() {
|
|
<span class="fc" id="L272"> return full_name;</span>
|
|
}
|
|
|
|
/**
|
|
* Has pull access boolean.
|
|
*
|
|
* @return the boolean
|
|
*/
|
|
public boolean hasPullAccess() {
|
|
<span class="nc bnc" id="L281" title="All 4 branches missed."> return permissions != null && permissions.pull;</span>
|
|
}
|
|
|
|
/**
|
|
* Has push access boolean.
|
|
*
|
|
* @return the boolean
|
|
*/
|
|
public boolean hasPushAccess() {
|
|
<span class="nc bnc" id="L290" title="All 4 branches missed."> return permissions != null && permissions.push;</span>
|
|
}
|
|
|
|
/**
|
|
* Has admin access boolean.
|
|
*
|
|
* @return the boolean
|
|
*/
|
|
public boolean hasAdminAccess() {
|
|
<span class="nc bnc" id="L299" title="All 4 branches missed."> return permissions != null && permissions.admin;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the primary programming language.
|
|
*
|
|
* @return the language
|
|
*/
|
|
public String getLanguage() {
|
|
<span class="fc" id="L308"> return language;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets owner.
|
|
*
|
|
* @return the owner
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHUser getOwner() throws IOException {
|
|
<span class="fc bfc" id="L319" title="All 2 branches covered."> return root.isOffline() ? owner : root.getUser(getOwnerName()); // because 'owner' isn't fully populated</span>
|
|
}
|
|
|
|
/**
|
|
* Gets issue.
|
|
*
|
|
* @param id
|
|
* the id
|
|
* @return the issue
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHIssue getIssue(int id) throws IOException {
|
|
<span class="fc" id="L332"> return root.createRequest().withUrlPath(getApiTailUrl("issues/" + id)).fetch(GHIssue.class).wrap(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Create issue gh issue builder.
|
|
*
|
|
* @param title
|
|
* the title
|
|
* @return the gh issue builder
|
|
*/
|
|
public GHIssueBuilder createIssue(String title) {
|
|
<span class="fc" id="L343"> return new GHIssueBuilder(this, title);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets issues.
|
|
*
|
|
* @param state
|
|
* the state
|
|
* @return the issues
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public List<GHIssue> getIssues(GHIssueState state) throws IOException {
|
|
<span class="fc" id="L356"> return listIssues(state).toList();</span>
|
|
}
|
|
|
|
/**
|
|
* Gets issues.
|
|
*
|
|
* @param state
|
|
* the state
|
|
* @param milestone
|
|
* the milestone
|
|
* @return the issues
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public List<GHIssue> getIssues(GHIssueState state, GHMilestone milestone) throws IOException {
|
|
<span class="nc" id="L371"> Requester requester = root.createRequest()</span>
|
|
<span class="nc" id="L372"> .with("state", state)</span>
|
|
<span class="nc bnc" id="L373" title="All 2 branches missed."> .with("milestone", milestone == null ? "none" : "" + milestone.getNumber());</span>
|
|
<span class="nc" id="L374"> return requester.withUrlPath(getApiTailUrl("issues"))</span>
|
|
<span class="nc" id="L375"> .toIterable(GHIssue[].class, item -> item.wrap(this))</span>
|
|
<span class="nc" id="L376"> .toList();</span>
|
|
}
|
|
|
|
/**
|
|
* Lists up all the issues in this repository.
|
|
*
|
|
* @param state
|
|
* the state
|
|
* @return the paged iterable
|
|
*/
|
|
public PagedIterable<GHIssue> listIssues(final GHIssueState state) {
|
|
<span class="fc" id="L387"> return root.createRequest()</span>
|
|
<span class="fc" id="L388"> .with("state", state)</span>
|
|
<span class="fc" id="L389"> .withUrlPath(getApiTailUrl("issues"))</span>
|
|
<span class="fc" id="L390"> .toIterable(GHIssue[].class, item -> item.wrap(this));</span>
|
|
}
|
|
|
|
/**
|
|
* Create release gh release builder.
|
|
*
|
|
* @param tag
|
|
* the tag
|
|
* @return the gh release builder
|
|
*/
|
|
public GHReleaseBuilder createRelease(String tag) {
|
|
<span class="fc" id="L401"> return new GHReleaseBuilder(this, tag);</span>
|
|
}
|
|
|
|
/**
|
|
* Creates a named ref, such as tag, branch, etc.
|
|
*
|
|
* @param name
|
|
* The name of the fully qualified reference (ie: refs/heads/master). If it doesn't start with 'refs' and
|
|
* have at least two slashes, it will be rejected.
|
|
* @param sha
|
|
* The SHA1 value to set this reference to
|
|
* @return the gh ref
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHRef createRef(String name, String sha) throws IOException {
|
|
<span class="fc" id="L417"> return root.createRequest()</span>
|
|
<span class="fc" id="L418"> .method("POST")</span>
|
|
<span class="fc" id="L419"> .with("ref", name)</span>
|
|
<span class="fc" id="L420"> .with("sha", sha)</span>
|
|
<span class="fc" id="L421"> .withUrlPath(getApiTailUrl("git/refs"))</span>
|
|
<span class="fc" id="L422"> .fetch(GHRef.class)</span>
|
|
<span class="fc" id="L423"> .wrap(root);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets releases.
|
|
*
|
|
* @return the releases
|
|
* @throws IOException
|
|
* the io exception
|
|
* @deprecated use {@link #listReleases()}
|
|
*/
|
|
public List<GHRelease> getReleases() throws IOException {
|
|
<span class="fc" id="L435"> return listReleases().toList();</span>
|
|
}
|
|
|
|
/**
|
|
* Gets release.
|
|
*
|
|
* @param id
|
|
* the id
|
|
* @return the release
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHRelease getRelease(long id) throws IOException {
|
|
try {
|
|
<span class="fc" id="L449"> return root.createRequest().withUrlPath(getApiTailUrl("releases/" + id)).fetch(GHRelease.class).wrap(this);</span>
|
|
<span class="fc" id="L450"> } catch (FileNotFoundException e) {</span>
|
|
<span class="fc" id="L451"> return null; // no release for this id</span>
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Gets release by tag name.
|
|
*
|
|
* @param tag
|
|
* the tag
|
|
* @return the release by tag name
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHRelease getReleaseByTagName(String tag) throws IOException {
|
|
try {
|
|
<span class="fc" id="L466"> return root.createRequest()</span>
|
|
<span class="fc" id="L467"> .withUrlPath(getApiTailUrl("releases/tags/" + tag))</span>
|
|
<span class="fc" id="L468"> .fetch(GHRelease.class)</span>
|
|
<span class="fc" id="L469"> .wrap(this);</span>
|
|
<span class="fc" id="L470"> } catch (FileNotFoundException e) {</span>
|
|
<span class="fc" id="L471"> return null; // no release for this tag</span>
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Gets latest release.
|
|
*
|
|
* @return the latest release
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHRelease getLatestRelease() throws IOException {
|
|
try {
|
|
<span class="fc" id="L484"> return root.createRequest().withUrlPath(getApiTailUrl("releases/latest")).fetch(GHRelease.class).wrap(this);</span>
|
|
<span class="fc" id="L485"> } catch (FileNotFoundException e) {</span>
|
|
<span class="fc" id="L486"> return null; // no latest release</span>
|
|
}
|
|
}
|
|
|
|
/**
|
|
* List releases paged iterable.
|
|
*
|
|
* @return the paged iterable
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public PagedIterable<GHRelease> listReleases() throws IOException {
|
|
<span class="fc" id="L498"> return root.createRequest()</span>
|
|
<span class="fc" id="L499"> .withUrlPath(getApiTailUrl("releases"))</span>
|
|
<span class="fc" id="L500"> .toIterable(GHRelease[].class, item -> item.wrap(this));</span>
|
|
}
|
|
|
|
/**
|
|
* List tags paged iterable.
|
|
*
|
|
* @return the paged iterable
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public PagedIterable<GHTag> listTags() throws IOException {
|
|
<span class="fc" id="L511"> return root.createRequest()</span>
|
|
<span class="fc" id="L512"> .withUrlPath(getApiTailUrl("tags"))</span>
|
|
<span class="fc" id="L513"> .toIterable(GHTag[].class, item -> item.wrap(this));</span>
|
|
}
|
|
|
|
/**
|
|
* List languages for the specified repository. The value on the right of a language is the number of bytes of code
|
|
* written in that language. { "C": 78769, "Python": 7769 }
|
|
*
|
|
* @return the map
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public Map<String, Long> listLanguages() throws IOException {
|
|
<span class="fc" id="L525"> return root.createRequest().withUrlPath(getApiTailUrl("languages")).fetch(HashMap.class);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets owner name.
|
|
*
|
|
* @return the owner name
|
|
*/
|
|
public String getOwnerName() {
|
|
// consistency of the GitHub API is super... some serialized forms of GHRepository populate
|
|
// a full GHUser while others populate only the owner and email. This later form is super helpful
|
|
// in putting the login in owner.name not owner.login... thankfully we can easily identify this
|
|
// second set because owner.login will be null
|
|
<span class="fc bfc" id="L538" title="All 2 branches covered."> return owner.login != null ? owner.login : owner.name;</span>
|
|
}
|
|
|
|
/**
|
|
* Has issues boolean.
|
|
*
|
|
* @return the boolean
|
|
*/
|
|
public boolean hasIssues() {
|
|
<span class="fc" id="L547"> return has_issues;</span>
|
|
}
|
|
|
|
/**
|
|
* Has projects boolean.
|
|
*
|
|
* @return the boolean
|
|
*/
|
|
public boolean hasProjects() {
|
|
<span class="fc" id="L556"> return has_projects;</span>
|
|
}
|
|
|
|
/**
|
|
* Has wiki boolean.
|
|
*
|
|
* @return the boolean
|
|
*/
|
|
public boolean hasWiki() {
|
|
<span class="fc" id="L565"> return has_wiki;</span>
|
|
}
|
|
|
|
/**
|
|
* Is fork boolean.
|
|
*
|
|
* @return the boolean
|
|
*/
|
|
public boolean isFork() {
|
|
<span class="nc" id="L574"> return fork;</span>
|
|
}
|
|
|
|
/**
|
|
* Is archived boolean.
|
|
*
|
|
* @return the boolean
|
|
*/
|
|
public boolean isArchived() {
|
|
<span class="fc" id="L583"> return archived;</span>
|
|
}
|
|
|
|
/**
|
|
* Is allow squash merge boolean.
|
|
*
|
|
* @return the boolean
|
|
*/
|
|
public boolean isAllowSquashMerge() {
|
|
<span class="fc" id="L592"> return allow_squash_merge;</span>
|
|
}
|
|
|
|
/**
|
|
* Is allow merge commit boolean.
|
|
*
|
|
* @return the boolean
|
|
*/
|
|
public boolean isAllowMergeCommit() {
|
|
<span class="fc" id="L601"> return allow_merge_commit;</span>
|
|
}
|
|
|
|
/**
|
|
* Is allow rebase merge boolean.
|
|
*
|
|
* @return the boolean
|
|
*/
|
|
public boolean isAllowRebaseMerge() {
|
|
<span class="fc" id="L610"> return allow_rebase_merge;</span>
|
|
}
|
|
|
|
/**
|
|
* Automatically deleting head branches when pull requests are merged
|
|
*
|
|
* @return the boolean
|
|
*/
|
|
public boolean isDeleteBranchOnMerge() {
|
|
<span class="fc" id="L619"> return delete_branch_on_merge;</span>
|
|
}
|
|
|
|
/**
|
|
* Returns the number of all forks of this repository. This not only counts direct forks, but also forks of forks,
|
|
* and so on.
|
|
*
|
|
* @return the forks
|
|
* @deprecated use {@link #getForksCount()} instead
|
|
*/
|
|
@Deprecated
|
|
public int getForks() {
|
|
<span class="nc" id="L631"> return getForksCount();</span>
|
|
}
|
|
|
|
/**
|
|
* Returns the number of all forks of this repository. This not only counts direct forks, but also forks of forks,
|
|
* and so on.
|
|
*
|
|
* @return the forks
|
|
*/
|
|
public int getForksCount() {
|
|
<span class="nc" id="L641"> return forks_count;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets stargazers count.
|
|
*
|
|
* @return the stargazers count
|
|
*/
|
|
public int getStargazersCount() {
|
|
<span class="fc" id="L650"> return stargazers_count;</span>
|
|
}
|
|
|
|
/**
|
|
* Is private boolean.
|
|
*
|
|
* @return the boolean
|
|
*/
|
|
public boolean isPrivate() {
|
|
<span class="fc" id="L659"> return _private;</span>
|
|
}
|
|
|
|
/**
|
|
* Has downloads boolean.
|
|
*
|
|
* @return the boolean
|
|
*/
|
|
public boolean hasDownloads() {
|
|
<span class="fc" id="L668"> return has_downloads;</span>
|
|
}
|
|
|
|
/**
|
|
* Has pages boolean.
|
|
*
|
|
* @return the boolean
|
|
*/
|
|
public boolean hasPages() {
|
|
<span class="nc" id="L677"> return has_pages;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets watchers.
|
|
*
|
|
* @return the watchers
|
|
* @deprecated use {@link #getWatchersCount()} instead
|
|
*/
|
|
@Deprecated
|
|
public int getWatchers() {
|
|
<span class="nc" id="L688"> return getWatchersCount();</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the count of watchers.
|
|
*
|
|
* @return the watchers
|
|
*/
|
|
public int getWatchersCount() {
|
|
<span class="fc" id="L697"> return watchers_count;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets open issue count.
|
|
*
|
|
* @return the open issue count
|
|
*/
|
|
public int getOpenIssueCount() {
|
|
<span class="nc" id="L706"> return open_issues_count;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets subscribers count.
|
|
*
|
|
* @return the subscribers count
|
|
*/
|
|
public int getSubscribersCount() {
|
|
<span class="nc" id="L715"> return subscribers_count;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets pushed at.
|
|
*
|
|
* @return null if the repository was never pushed at.
|
|
*/
|
|
public Date getPushedAt() {
|
|
<span class="nc" id="L724"> return GitHubClient.parseDate(pushed_at);</span>
|
|
}
|
|
|
|
/**
|
|
* Returns the primary branch you'll configure in the "Admin &gt; Options" config page.
|
|
*
|
|
* @return This field is null until the user explicitly configures the master branch.
|
|
*/
|
|
public String getDefaultBranch() {
|
|
<span class="nc" id="L733"> return default_branch;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets master branch.
|
|
*
|
|
* @return the master branch
|
|
* @deprecated Renamed to {@link #getDefaultBranch()}
|
|
*/
|
|
@Deprecated
|
|
public String getMasterBranch() {
|
|
<span class="nc" id="L744"> return default_branch;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets size.
|
|
*
|
|
* @return the size
|
|
*/
|
|
public int getSize() {
|
|
<span class="nc" id="L753"> return size;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the collaborators on this repository. This set always appear to include the owner.
|
|
*
|
|
* @return the collaborators
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
@WithBridgeMethods(Set.class)
|
|
public GHPersonSet<GHUser> getCollaborators() throws IOException {
|
|
<span class="fc" id="L765"> return new GHPersonSet<GHUser>(listCollaborators().toList());</span>
|
|
}
|
|
|
|
/**
|
|
* Lists up the collaborators on this repository.
|
|
*
|
|
* @return Users paged iterable
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public PagedIterable<GHUser> listCollaborators() throws IOException {
|
|
<span class="fc" id="L776"> return listUsers("collaborators");</span>
|
|
}
|
|
|
|
/**
|
|
* Lists all
|
|
* <a href="https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users/">the
|
|
* available assignees</a> to which issues may be assigned.
|
|
*
|
|
* @return the paged iterable
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public PagedIterable<GHUser> listAssignees() throws IOException {
|
|
<span class="nc" id="L789"> return listUsers("assignees");</span>
|
|
}
|
|
|
|
/**
|
|
* Checks if the given user is an assignee for this repository.
|
|
*
|
|
* @param u
|
|
* the u
|
|
* @return the boolean
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public boolean hasAssignee(GHUser u) throws IOException {
|
|
<span class="nc bnc" id="L802" title="All 2 branches missed."> return root.createRequest().withUrlPath(getApiTailUrl("assignees/" + u.getLogin())).fetchHttpStatusCode()</span>
|
|
/ 100 == 2;
|
|
}
|
|
|
|
/**
|
|
* Gets the names of the collaborators on this repository. This method deviates from the principle of this library
|
|
* but it works a lot faster than {@link #getCollaborators()}.
|
|
*
|
|
* @return the collaborator names
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public Set<String> getCollaboratorNames() throws IOException {
|
|
<span class="fc" id="L815"> Set<String> r = new HashSet<>();</span>
|
|
// no initializer - we just want to the logins
|
|
<span class="fc" id="L817"> PagedIterable<GHUser> users = root.createRequest()</span>
|
|
<span class="fc" id="L818"> .withUrlPath(getApiTailUrl("collaborators"))</span>
|
|
<span class="fc" id="L819"> .toIterable(GHUser[].class, null);</span>
|
|
<span class="fc bfc" id="L820" title="All 2 branches covered."> for (GHUser u : users.toArray()) {</span>
|
|
<span class="fc" id="L821"> r.add(u.login);</span>
|
|
}
|
|
<span class="fc" id="L823"> return r;</span>
|
|
}
|
|
|
|
/**
|
|
* Obtain permission for a given user in this repository.
|
|
*
|
|
* @param user
|
|
* a {@link GHUser#getLogin}
|
|
* @return the permission
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHPermissionType getPermission(String user) throws IOException {
|
|
<span class="fc" id="L836"> GHPermission perm = root.createRequest()</span>
|
|
<span class="fc" id="L837"> .withUrlPath(getApiTailUrl("collaborators/" + user + "/permission"))</span>
|
|
<span class="fc" id="L838"> .fetch(GHPermission.class);</span>
|
|
<span class="fc" id="L839"> perm.wrapUp(root);</span>
|
|
<span class="fc" id="L840"> return perm.getPermissionType();</span>
|
|
}
|
|
|
|
/**
|
|
* Obtain permission for a given user in this repository.
|
|
*
|
|
* @param u
|
|
* the user
|
|
* @return the permission
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHPermissionType getPermission(GHUser u) throws IOException {
|
|
<span class="nc" id="L853"> return getPermission(u.getLogin());</span>
|
|
}
|
|
|
|
/**
|
|
* If this repository belongs to an organization, return a set of teams.
|
|
*
|
|
* @return the teams
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public Set<GHTeam> getTeams() throws IOException {
|
|
<span class="fc" id="L864"> GHOrganization org = root.getOrganization(getOwnerName());</span>
|
|
<span class="fc" id="L865"> return root.createRequest()</span>
|
|
<span class="fc" id="L866"> .withUrlPath(getApiTailUrl("teams"))</span>
|
|
<span class="fc" id="L867"> .toIterable(GHTeam[].class, item -> item.wrapUp(org))</span>
|
|
<span class="fc" id="L868"> .toSet();</span>
|
|
}
|
|
|
|
/**
|
|
* Add collaborators.
|
|
*
|
|
* @param users
|
|
* the users
|
|
* @param permission
|
|
* the permission level
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void addCollaborators(GHOrganization.Permission permission, GHUser... users) throws IOException {
|
|
<span class="nc" id="L882"> addCollaborators(asList(users), permission);</span>
|
|
<span class="nc" id="L883"> }</span>
|
|
|
|
/**
|
|
* Add collaborators.
|
|
*
|
|
* @param users
|
|
* the users
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void addCollaborators(GHUser... users) throws IOException {
|
|
<span class="nc" id="L894"> addCollaborators(asList(users));</span>
|
|
<span class="nc" id="L895"> }</span>
|
|
|
|
/**
|
|
* Add collaborators.
|
|
*
|
|
* @param users
|
|
* the users
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void addCollaborators(Collection<GHUser> users) throws IOException {
|
|
<span class="nc" id="L906"> modifyCollaborators(users, "PUT", null);</span>
|
|
<span class="nc" id="L907"> }</span>
|
|
|
|
/**
|
|
* Add collaborators.
|
|
*
|
|
* @param users
|
|
* the users
|
|
* @param permission
|
|
* the permission level
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void addCollaborators(Collection<GHUser> users, GHOrganization.Permission permission) throws IOException {
|
|
<span class="fc" id="L920"> modifyCollaborators(users, "PUT", permission);</span>
|
|
<span class="fc" id="L921"> }</span>
|
|
|
|
/**
|
|
* Remove collaborators.
|
|
*
|
|
* @param users
|
|
* the users
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void removeCollaborators(GHUser... users) throws IOException {
|
|
<span class="nc" id="L932"> removeCollaborators(asList(users));</span>
|
|
<span class="nc" id="L933"> }</span>
|
|
|
|
/**
|
|
* Remove collaborators.
|
|
*
|
|
* @param users
|
|
* the users
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void removeCollaborators(Collection<GHUser> users) throws IOException {
|
|
<span class="nc" id="L944"> modifyCollaborators(users, "DELETE", null);</span>
|
|
<span class="nc" id="L945"> }</span>
|
|
|
|
private void modifyCollaborators(@NonNull Collection<GHUser> users,
|
|
@NonNull String method,
|
|
@CheckForNull GHOrganization.Permission permission) throws IOException {
|
|
<span class="fc" id="L950"> Requester requester = root.createRequest().method(method);</span>
|
|
|
|
<span class="pc bpc" id="L952" title="1 of 2 branches missed."> if (permission != null) {</span>
|
|
<span class="fc" id="L953"> requester = requester.with("permission", permission).inBody();</span>
|
|
}
|
|
|
|
<span class="fc bfc" id="L956" title="All 2 branches covered."> for (GHUser user : users) {</span>
|
|
<span class="fc" id="L957"> requester.withUrlPath(getApiTailUrl("collaborators/" + user.getLogin())).send();</span>
|
|
<span class="fc" id="L958"> }</span>
|
|
<span class="fc" id="L959"> }</span>
|
|
|
|
/**
|
|
* Sets email service hook.
|
|
*
|
|
* @param address
|
|
* the address
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void setEmailServiceHook(String address) throws IOException {
|
|
<span class="nc" id="L970"> Map<String, String> config = new HashMap<String, String>();</span>
|
|
<span class="nc" id="L971"> config.put("address", address);</span>
|
|
<span class="nc" id="L972"> root.createRequest()</span>
|
|
<span class="nc" id="L973"> .method("POST")</span>
|
|
<span class="nc" id="L974"> .with("name", "email")</span>
|
|
<span class="nc" id="L975"> .with("config", config)</span>
|
|
<span class="nc" id="L976"> .with("active", true)</span>
|
|
<span class="nc" id="L977"> .withUrlPath(getApiTailUrl("hooks"))</span>
|
|
<span class="nc" id="L978"> .send();</span>
|
|
<span class="nc" id="L979"> }</span>
|
|
|
|
private void edit(String key, String value) throws IOException {
|
|
<span class="fc" id="L982"> Requester requester = root.createRequest();</span>
|
|
<span class="fc bfc" id="L983" title="All 2 branches covered."> if (!key.equals("name"))</span>
|
|
<span class="fc" id="L984"> requester.with("name", name); // even when we don't change the name, we need to send it in</span>
|
|
<span class="fc" id="L985"> requester.with(key, value).method("PATCH").withUrlPath(getApiTailUrl("")).send();</span>
|
|
<span class="fc" id="L986"> }</span>
|
|
|
|
/**
|
|
* Enables or disables the issue tracker for this repository.
|
|
*
|
|
* @param v
|
|
* the v
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void enableIssueTracker(boolean v) throws IOException {
|
|
<span class="fc" id="L997"> edit("has_issues", String.valueOf(v));</span>
|
|
<span class="fc" id="L998"> }</span>
|
|
|
|
/**
|
|
* Enables or disables projects for this repository.
|
|
*
|
|
* @param v
|
|
* the v
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void enableProjects(boolean v) throws IOException {
|
|
<span class="fc" id="L1009"> edit("has_projects", String.valueOf(v));</span>
|
|
<span class="fc" id="L1010"> }</span>
|
|
|
|
/**
|
|
* Enables or disables Wiki for this repository.
|
|
*
|
|
* @param v
|
|
* the v
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void enableWiki(boolean v) throws IOException {
|
|
<span class="fc" id="L1021"> edit("has_wiki", String.valueOf(v));</span>
|
|
<span class="fc" id="L1022"> }</span>
|
|
|
|
/**
|
|
* Enable downloads.
|
|
*
|
|
* @param v
|
|
* the v
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void enableDownloads(boolean v) throws IOException {
|
|
<span class="fc" id="L1033"> edit("has_downloads", String.valueOf(v));</span>
|
|
<span class="fc" id="L1034"> }</span>
|
|
|
|
/**
|
|
* Rename this repository.
|
|
*
|
|
* @param name
|
|
* the name
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void renameTo(String name) throws IOException {
|
|
<span class="fc" id="L1045"> edit("name", name);</span>
|
|
<span class="fc" id="L1046"> }</span>
|
|
|
|
/**
|
|
* Sets description.
|
|
*
|
|
* @param value
|
|
* the value
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void setDescription(String value) throws IOException {
|
|
<span class="fc" id="L1057"> edit("description", value);</span>
|
|
<span class="fc" id="L1058"> }</span>
|
|
|
|
/**
|
|
* Sets homepage.
|
|
*
|
|
* @param value
|
|
* the value
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void setHomepage(String value) throws IOException {
|
|
<span class="nc" id="L1069"> edit("homepage", value);</span>
|
|
<span class="nc" id="L1070"> }</span>
|
|
|
|
/**
|
|
* Sets default branch.
|
|
*
|
|
* @param value
|
|
* the value
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void setDefaultBranch(String value) throws IOException {
|
|
<span class="nc" id="L1081"> edit("default_branch", value);</span>
|
|
<span class="nc" id="L1082"> }</span>
|
|
|
|
/**
|
|
* Sets private.
|
|
*
|
|
* @param value
|
|
* the value
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void setPrivate(boolean value) throws IOException {
|
|
<span class="fc" id="L1093"> edit("private", Boolean.toString(value));</span>
|
|
<span class="fc" id="L1094"> }</span>
|
|
|
|
/**
|
|
* Allow squash merge.
|
|
*
|
|
* @param value
|
|
* the value
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void allowSquashMerge(boolean value) throws IOException {
|
|
<span class="fc" id="L1105"> edit("allow_squash_merge", Boolean.toString(value));</span>
|
|
<span class="fc" id="L1106"> }</span>
|
|
|
|
/**
|
|
* Allow merge commit.
|
|
*
|
|
* @param value
|
|
* the value
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void allowMergeCommit(boolean value) throws IOException {
|
|
<span class="fc" id="L1117"> edit("allow_merge_commit", Boolean.toString(value));</span>
|
|
<span class="fc" id="L1118"> }</span>
|
|
|
|
/**
|
|
* Allow rebase merge.
|
|
*
|
|
* @param value
|
|
* the value
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void allowRebaseMerge(boolean value) throws IOException {
|
|
<span class="fc" id="L1129"> edit("allow_rebase_merge", Boolean.toString(value));</span>
|
|
<span class="fc" id="L1130"> }</span>
|
|
|
|
/**
|
|
* After pull requests are merged, you can have head branches deleted automatically.
|
|
*
|
|
* @param value
|
|
* the value
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void deleteBranchOnMerge(boolean value) throws IOException {
|
|
<span class="fc" id="L1141"> edit("delete_branch_on_merge", Boolean.toString(value));</span>
|
|
<span class="fc" id="L1142"> }</span>
|
|
|
|
/**
|
|
* Deletes this repository.
|
|
*
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void delete() throws IOException {
|
|
try {
|
|
<span class="fc" id="L1152"> root.createRequest().method("DELETE").withUrlPath(getApiTailUrl("")).send();</span>
|
|
<span class="nc" id="L1153"> } catch (FileNotFoundException x) {</span>
|
|
<span class="nc" id="L1154"> throw (FileNotFoundException) new FileNotFoundException("Failed to delete " + getOwnerName() + "/" + name</span>
|
|
+ "; might not exist, or you might need the delete_repo scope in your token: http://stackoverflow.com/a/19327004/12916")
|
|
<span class="nc" id="L1156"> .initCause(x);</span>
|
|
<span class="fc" id="L1157"> }</span>
|
|
<span class="fc" id="L1158"> }</span>
|
|
|
|
/**
|
|
* Will archive and this repository as read-only. When a repository is archived, any operation that can change its
|
|
* state is forbidden. This applies symmetrically if trying to unarchive it.
|
|
*
|
|
* <p>
|
|
* When you try to do any operation that modifies a read-only repository, it returns the response:
|
|
*
|
|
* <pre>
|
|
* org.kohsuke.github.HttpException: {
|
|
* "message":"Repository was archived so is read-only.",
|
|
* "documentation_url":"https://developer.github.com/v3/repos/#edit"
|
|
* }
|
|
* </pre>
|
|
*
|
|
* @throws IOException
|
|
* In case of any networking error or error from the server.
|
|
*/
|
|
public void archive() throws IOException {
|
|
<span class="fc" id="L1178"> edit("archived", "true");</span>
|
|
// Generall would not update this record,
|
|
// but do so here since this will result in any other update actions failing
|
|
<span class="fc" id="L1181"> archived = true;</span>
|
|
<span class="fc" id="L1182"> }</span>
|
|
|
|
/**
|
|
* Sort orders for listing forks
|
|
*/
|
|
<span class="nc" id="L1187"> public enum ForkSort {</span>
|
|
<span class="nc" id="L1188"> NEWEST, OLDEST, STARGAZERS</span>
|
|
}
|
|
|
|
/**
|
|
* Lists all the direct forks of this repository, sorted by github api default, currently {@link ForkSort#NEWEST
|
|
* ForkSort.NEWEST}*.
|
|
*
|
|
* @return the paged iterable
|
|
*/
|
|
public PagedIterable<GHRepository> listForks() {
|
|
<span class="nc" id="L1198"> return listForks(null);</span>
|
|
}
|
|
|
|
/**
|
|
* Lists all the direct forks of this repository, sorted by the given sort order.
|
|
*
|
|
* @param sort
|
|
* the sort order. If null, defaults to github api default, currently {@link ForkSort#NEWEST
|
|
* ForkSort.NEWEST}.
|
|
* @return the paged iterable
|
|
*/
|
|
public PagedIterable<GHRepository> listForks(final ForkSort sort) {
|
|
<span class="nc" id="L1210"> return root.createRequest()</span>
|
|
<span class="nc" id="L1211"> .with("sort", sort)</span>
|
|
<span class="nc" id="L1212"> .withUrlPath(getApiTailUrl("forks"))</span>
|
|
<span class="nc" id="L1213"> .toIterable(GHRepository[].class, item -> item.wrap(root));</span>
|
|
}
|
|
|
|
/**
|
|
* Forks this repository as your repository.
|
|
*
|
|
* @return Newly forked repository that belong to you.
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHRepository fork() throws IOException {
|
|
<span class="nc" id="L1224"> root.createRequest().method("POST").withUrlPath(getApiTailUrl("forks")).send();</span>
|
|
|
|
// this API is asynchronous. we need to wait for a bit
|
|
<span class="nc bnc" id="L1227" title="All 2 branches missed."> for (int i = 0; i < 10; i++) {</span>
|
|
<span class="nc" id="L1228"> GHRepository r = root.getMyself().getRepository(name);</span>
|
|
<span class="nc bnc" id="L1229" title="All 2 branches missed."> if (r != null)</span>
|
|
<span class="nc" id="L1230"> return r;</span>
|
|
try {
|
|
<span class="nc" id="L1232"> Thread.sleep(3000);</span>
|
|
<span class="nc" id="L1233"> } catch (InterruptedException e) {</span>
|
|
<span class="nc" id="L1234"> throw (IOException) new InterruptedIOException().initCause(e);</span>
|
|
<span class="nc" id="L1235"> }</span>
|
|
}
|
|
<span class="nc" id="L1237"> throw new IOException(this + " was forked but can't find the new repository");</span>
|
|
}
|
|
|
|
/**
|
|
* Forks this repository into an organization.
|
|
*
|
|
* @param org
|
|
* the org
|
|
* @return Newly forked repository that belong to you.
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHRepository forkTo(GHOrganization org) throws IOException {
|
|
<span class="fc" id="L1250"> root.createRequest()</span>
|
|
<span class="fc" id="L1251"> .method("POST")</span>
|
|
<span class="fc" id="L1252"> .with("organization", org.getLogin())</span>
|
|
<span class="fc" id="L1253"> .withUrlPath(getApiTailUrl("forks"))</span>
|
|
<span class="fc" id="L1254"> .send();</span>
|
|
|
|
// this API is asynchronous. we need to wait for a bit
|
|
<span class="pc bpc" id="L1257" title="1 of 2 branches missed."> for (int i = 0; i < 10; i++) {</span>
|
|
<span class="fc" id="L1258"> GHRepository r = org.getRepository(name);</span>
|
|
<span class="pc bpc" id="L1259" title="1 of 2 branches missed."> if (r != null)</span>
|
|
<span class="fc" id="L1260"> return r;</span>
|
|
try {
|
|
<span class="nc" id="L1262"> Thread.sleep(3000);</span>
|
|
<span class="nc" id="L1263"> } catch (InterruptedException e) {</span>
|
|
<span class="nc" id="L1264"> throw (IOException) new InterruptedIOException().initCause(e);</span>
|
|
<span class="nc" id="L1265"> }</span>
|
|
}
|
|
<span class="nc" id="L1267"> throw new IOException(this + " was forked into " + org.getLogin() + " but can't find the new repository");</span>
|
|
}
|
|
|
|
/**
|
|
* Retrieves a specified pull request.
|
|
*
|
|
* @param i
|
|
* the
|
|
* @return the pull request
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHPullRequest getPullRequest(int i) throws IOException {
|
|
<span class="fc" id="L1280"> return root.createRequest()</span>
|
|
<span class="fc" id="L1281"> .withPreview(SHADOW_CAT)</span>
|
|
<span class="fc" id="L1282"> .withUrlPath(getApiTailUrl("pulls/" + i))</span>
|
|
<span class="fc" id="L1283"> .fetch(GHPullRequest.class)</span>
|
|
<span class="fc" id="L1284"> .wrapUp(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Retrieves all the pull requests of a particular state.
|
|
*
|
|
* @param state
|
|
* the state
|
|
* @return the pull requests
|
|
* @throws IOException
|
|
* the io exception
|
|
* @see #listPullRequests(GHIssueState) #listPullRequests(GHIssueState)
|
|
*/
|
|
public List<GHPullRequest> getPullRequests(GHIssueState state) throws IOException {
|
|
<span class="nc" id="L1298"> return queryPullRequests().state(state).list().toList();</span>
|
|
}
|
|
|
|
/**
|
|
* Retrieves all the pull requests of a particular state.
|
|
*
|
|
* @param state
|
|
* the state
|
|
* @return the paged iterable
|
|
* @deprecated Use {@link #queryPullRequests()}
|
|
*/
|
|
@Deprecated
|
|
public PagedIterable<GHPullRequest> listPullRequests(GHIssueState state) {
|
|
<span class="fc" id="L1311"> return queryPullRequests().state(state).list();</span>
|
|
}
|
|
|
|
/**
|
|
* Retrieves pull requests.
|
|
*
|
|
* @return the gh pull request query builder
|
|
*/
|
|
public GHPullRequestQueryBuilder queryPullRequests() {
|
|
<span class="fc" id="L1320"> return new GHPullRequestQueryBuilder(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Creates a new pull request.
|
|
*
|
|
* @param title
|
|
* Required. The title of the pull request.
|
|
* @param head
|
|
* Required. The name of the branch where your changes are implemented. For cross-repository pull
|
|
* requests in the same network, namespace head with a user like this: username:branch.
|
|
* @param base
|
|
* Required. The name of the branch you want your changes pulled into. This should be an existing branch
|
|
* on the current repository.
|
|
* @param body
|
|
* The contents of the pull request. This is the markdown description of a pull request.
|
|
* @return the gh pull request
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHPullRequest createPullRequest(String title, String head, String base, String body) throws IOException {
|
|
<span class="fc" id="L1341"> return createPullRequest(title, head, base, body, true);</span>
|
|
}
|
|
|
|
/**
|
|
* Creates a new pull request. Maintainer's permissions aware.
|
|
*
|
|
* @param title
|
|
* Required. The title of the pull request.
|
|
* @param head
|
|
* Required. The name of the branch where your changes are implemented. For cross-repository pull
|
|
* requests in the same network, namespace head with a user like this: username:branch.
|
|
* @param base
|
|
* Required. The name of the branch you want your changes pulled into. This should be an existing branch
|
|
* on the current repository.
|
|
* @param body
|
|
* The contents of the pull request. This is the markdown description of a pull request.
|
|
* @param maintainerCanModify
|
|
* Indicates whether maintainers can modify the pull request.
|
|
* @return the gh pull request
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHPullRequest createPullRequest(String title,
|
|
String head,
|
|
String base,
|
|
String body,
|
|
boolean maintainerCanModify) throws IOException {
|
|
<span class="fc" id="L1368"> return createPullRequest(title, head, base, body, maintainerCanModify, false);</span>
|
|
}
|
|
|
|
/**
|
|
* Creates a new pull request. Maintainer's permissions and draft aware.
|
|
*
|
|
* @param title
|
|
* Required. The title of the pull request.
|
|
* @param head
|
|
* Required. The name of the branch where your changes are implemented. For cross-repository pull
|
|
* requests in the same network, namespace head with a user like this: username:branch.
|
|
* @param base
|
|
* Required. The name of the branch you want your changes pulled into. This should be an existing branch
|
|
* on the current repository.
|
|
* @param body
|
|
* The contents of the pull request. This is the markdown description of a pull request.
|
|
* @param maintainerCanModify
|
|
* Indicates whether maintainers can modify the pull request.
|
|
* @param draft
|
|
* Indicates whether to create a draft pull request or not.
|
|
* @return the gh pull request
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHPullRequest createPullRequest(String title,
|
|
String head,
|
|
String base,
|
|
String body,
|
|
boolean maintainerCanModify,
|
|
boolean draft) throws IOException {
|
|
<span class="fc" id="L1398"> return root.createRequest()</span>
|
|
<span class="fc" id="L1399"> .method("POST")</span>
|
|
<span class="fc" id="L1400"> .withPreview(SHADOW_CAT)</span>
|
|
<span class="fc" id="L1401"> .with("title", title)</span>
|
|
<span class="fc" id="L1402"> .with("head", head)</span>
|
|
<span class="fc" id="L1403"> .with("base", base)</span>
|
|
<span class="fc" id="L1404"> .with("body", body)</span>
|
|
<span class="fc" id="L1405"> .with("maintainer_can_modify", maintainerCanModify)</span>
|
|
<span class="fc" id="L1406"> .with("draft", draft)</span>
|
|
<span class="fc" id="L1407"> .withUrlPath(getApiTailUrl("pulls"))</span>
|
|
<span class="fc" id="L1408"> .fetch(GHPullRequest.class)</span>
|
|
<span class="fc" id="L1409"> .wrapUp(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Retrieves the currently configured hooks.
|
|
*
|
|
* @return the hooks
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public List<GHHook> getHooks() throws IOException {
|
|
<span class="fc" id="L1420"> return GHHooks.repoContext(this, owner).getHooks();</span>
|
|
}
|
|
|
|
/**
|
|
* Gets hook.
|
|
*
|
|
* @param id
|
|
* the id
|
|
* @return the hook
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHHook getHook(int id) throws IOException {
|
|
<span class="nc" id="L1433"> return GHHooks.repoContext(this, owner).getHook(id);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets a comparison between 2 points in the repository. This would be similar to calling
|
|
* <code>git log id1...id2</code> against a local repository.
|
|
*
|
|
* @param id1
|
|
* an identifier for the first point to compare from, this can be a sha1 ID (for a commit, tag etc) or a
|
|
* direct tag name
|
|
* @param id2
|
|
* an identifier for the second point to compare to. Can be the same as the first point.
|
|
* @return the comparison output
|
|
* @throws IOException
|
|
* on failure communicating with GitHub
|
|
*/
|
|
public GHCompare getCompare(String id1, String id2) throws IOException {
|
|
<span class="nc" id="L1450"> GHCompare compare = root.createRequest()</span>
|
|
<span class="nc" id="L1451"> .withUrlPath(getApiTailUrl(String.format("compare/%s...%s", id1, id2)))</span>
|
|
<span class="nc" id="L1452"> .fetch(GHCompare.class);</span>
|
|
<span class="nc" id="L1453"> return compare.wrap(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets compare.
|
|
*
|
|
* @param id1
|
|
* the id 1
|
|
* @param id2
|
|
* the id 2
|
|
* @return the compare
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHCompare getCompare(GHCommit id1, GHCommit id2) throws IOException {
|
|
<span class="nc" id="L1468"> return getCompare(id1.getSHA1(), id2.getSHA1());</span>
|
|
}
|
|
|
|
/**
|
|
* Gets compare.
|
|
*
|
|
* @param id1
|
|
* the id 1
|
|
* @param id2
|
|
* the id 2
|
|
* @return the compare
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHCompare getCompare(GHBranch id1, GHBranch id2) throws IOException {
|
|
|
|
<span class="nc" id="L1484"> GHRepository owner1 = id1.getOwner();</span>
|
|
<span class="nc" id="L1485"> GHRepository owner2 = id2.getOwner();</span>
|
|
|
|
// If the owner of the branches is different, we have a cross-fork compare.
|
|
<span class="nc bnc" id="L1488" title="All 4 branches missed."> if (owner1 != null && owner2 != null) {</span>
|
|
<span class="nc" id="L1489"> String ownerName1 = owner1.getOwnerName();</span>
|
|
<span class="nc" id="L1490"> String ownerName2 = owner2.getOwnerName();</span>
|
|
<span class="nc bnc" id="L1491" title="All 2 branches missed."> if (!StringUtils.equals(ownerName1, ownerName2)) {</span>
|
|
<span class="nc" id="L1492"> String qualifiedName1 = String.format("%s:%s", ownerName1, id1.getName());</span>
|
|
<span class="nc" id="L1493"> String qualifiedName2 = String.format("%s:%s", ownerName2, id2.getName());</span>
|
|
<span class="nc" id="L1494"> return getCompare(qualifiedName1, qualifiedName2);</span>
|
|
}
|
|
}
|
|
|
|
<span class="nc" id="L1498"> return getCompare(id1.getName(), id2.getName());</span>
|
|
|
|
}
|
|
|
|
/**
|
|
* Retrieves all refs for the github repository.
|
|
*
|
|
* @return an array of GHRef elements coresponding with the refs in the remote repository.
|
|
* @throws IOException
|
|
* on failure communicating with GitHub
|
|
*/
|
|
public GHRef[] getRefs() throws IOException {
|
|
<span class="fc" id="L1510"> return listRefs().toArray();</span>
|
|
}
|
|
|
|
/**
|
|
* Retrieves all refs for the github repository.
|
|
*
|
|
* @return paged iterable of all refs
|
|
* @throws IOException
|
|
* on failure communicating with GitHub, potentially due to an invalid ref type being requested
|
|
*/
|
|
public PagedIterable<GHRef> listRefs() throws IOException {
|
|
<span class="fc" id="L1521"> final String url = String.format("/repos/%s/%s/git/refs", getOwnerName(), name);</span>
|
|
<span class="fc" id="L1522"> return root.createRequest().withUrlPath(url).toIterable(GHRef[].class, item -> item.wrap(root));</span>
|
|
}
|
|
|
|
/**
|
|
* Retrieves all refs of the given type for the current GitHub repository.
|
|
*
|
|
* @param refType
|
|
* the type of reg to search for e.g. <code>tags</code> or <code>commits</code>
|
|
* @return an array of all refs matching the request type
|
|
* @throws IOException
|
|
* on failure communicating with GitHub, potentially due to an invalid ref type being requested
|
|
*/
|
|
public GHRef[] getRefs(String refType) throws IOException {
|
|
<span class="fc" id="L1535"> return listRefs(refType).toArray();</span>
|
|
}
|
|
|
|
/**
|
|
* Retrieves all refs of the given type for the current GitHub repository.
|
|
*
|
|
* @param refType
|
|
* the type of reg to search for e.g. <code>tags</code> or <code>commits</code>
|
|
* @return paged iterable of all refs of the specified type
|
|
* @throws IOException
|
|
* on failure communicating with GitHub, potentially due to an invalid ref type being requested
|
|
*/
|
|
public PagedIterable<GHRef> listRefs(String refType) throws IOException {
|
|
<span class="fc" id="L1548"> final String url = String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType);</span>
|
|
<span class="fc" id="L1549"> return root.createRequest().withUrlPath(url).toIterable(GHRef[].class, item -> item.wrap(root));</span>
|
|
}
|
|
|
|
/**
|
|
* Retrive a ref of the given type for the current GitHub repository.
|
|
*
|
|
* @param refName
|
|
* eg: heads/branch
|
|
* @return refs matching the request type
|
|
* @throws IOException
|
|
* on failure communicating with GitHub, potentially due to an invalid ref type being requested
|
|
*/
|
|
public GHRef getRef(String refName) throws IOException {
|
|
<span class="fc" id="L1562"> return root.createRequest()</span>
|
|
<span class="fc" id="L1563"> .withUrlPath(getApiTailUrl(String.format("git/refs/%s", refName)))</span>
|
|
<span class="fc" id="L1564"> .fetch(GHRef.class)</span>
|
|
<span class="fc" id="L1565"> .wrap(root);</span>
|
|
}
|
|
|
|
/**
|
|
* Returns the <strong>annotated</strong> tag object. Only valid if the {@link GHRef#getObject()} has a
|
|
* {@link GHRef.GHObject#getType()} of {@code tag}.
|
|
*
|
|
* @param sha
|
|
* the sha of the tag object
|
|
* @return the annotated tag object
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHTagObject getTagObject(String sha) throws IOException {
|
|
<span class="nc" id="L1579"> return root.createRequest().withUrlPath(getApiTailUrl("git/tags/" + sha)).fetch(GHTagObject.class).wrap(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Retrive a tree of the given type for the current GitHub repository.
|
|
*
|
|
* @param sha
|
|
* sha number or branch name ex: "master"
|
|
* @return refs matching the request type
|
|
* @throws IOException
|
|
* on failure communicating with GitHub, potentially due to an invalid tree type being requested
|
|
*/
|
|
public GHTree getTree(String sha) throws IOException {
|
|
<span class="fc" id="L1592"> String url = String.format("/repos/%s/%s/git/trees/%s", getOwnerName(), name, sha);</span>
|
|
<span class="fc" id="L1593"> return root.createRequest().withUrlPath(url).fetch(GHTree.class).wrap(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Create tree gh tree builder.
|
|
*
|
|
* @return the gh tree builder
|
|
*/
|
|
public GHTreeBuilder createTree() {
|
|
<span class="fc" id="L1602"> return new GHTreeBuilder(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Retrieves the tree for the current GitHub repository, recursively as described in here:
|
|
* https://developer.github.com/v3/git/trees/#get-a-tree-recursively
|
|
*
|
|
* @param sha
|
|
* sha number or branch name ex: "master"
|
|
* @param recursive
|
|
* use 1
|
|
* @return the tree recursive
|
|
* @throws IOException
|
|
* on failure communicating with GitHub, potentially due to an invalid tree type being requested
|
|
*/
|
|
public GHTree getTreeRecursive(String sha, int recursive) throws IOException {
|
|
<span class="fc" id="L1618"> String url = String.format("/repos/%s/%s/git/trees/%s", getOwnerName(), name, sha);</span>
|
|
<span class="fc" id="L1619"> return root.createRequest().with("recursive", recursive).withUrlPath(url).fetch(GHTree.class).wrap(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Obtains the metadata &amp; the content of a blob.
|
|
*
|
|
* <p>
|
|
* This method retrieves the whole content in memory, so beware when you are dealing with large BLOB.
|
|
*
|
|
* @param blobSha
|
|
* the blob sha
|
|
* @return the blob
|
|
* @throws IOException
|
|
* the io exception
|
|
* @see <a href="https://developer.github.com/v3/git/blobs/#get-a-blob">Get a blob</a>
|
|
* @see #readBlob(String) #readBlob(String)
|
|
*/
|
|
public GHBlob getBlob(String blobSha) throws IOException {
|
|
<span class="fc" id="L1637"> String target = getApiTailUrl("git/blobs/" + blobSha);</span>
|
|
<span class="fc" id="L1638"> return root.createRequest().withUrlPath(target).fetch(GHBlob.class);</span>
|
|
}
|
|
|
|
/**
|
|
* Create blob gh blob builder.
|
|
*
|
|
* @return the gh blob builder
|
|
*/
|
|
public GHBlobBuilder createBlob() {
|
|
<span class="fc" id="L1647"> return new GHBlobBuilder(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Reads the content of a blob as a stream for better efficiency.
|
|
*
|
|
* @param blobSha
|
|
* the blob sha
|
|
* @return the input stream
|
|
* @throws IOException
|
|
* the io exception
|
|
* @see <a href="https://developer.github.com/v3/git/blobs/#get-a-blob">Get a blob</a>
|
|
* @see #getBlob(String) #getBlob(String)
|
|
*/
|
|
public InputStream readBlob(String blobSha) throws IOException {
|
|
<span class="fc" id="L1662"> String target = getApiTailUrl("git/blobs/" + blobSha);</span>
|
|
|
|
// https://developer.github.com/v3/media/ describes this media type
|
|
<span class="fc" id="L1665"> return root.createRequest()</span>
|
|
<span class="fc" id="L1666"> .withHeader("Accept", "application/vnd.github.v3.raw")</span>
|
|
<span class="fc" id="L1667"> .withUrlPath(target)</span>
|
|
<span class="fc" id="L1668"> .fetchStream();</span>
|
|
}
|
|
|
|
/**
|
|
* Gets a commit object in this repository.
|
|
*
|
|
* @param sha1
|
|
* the sha 1
|
|
* @return the commit
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHCommit getCommit(String sha1) throws IOException {
|
|
<span class="fc" id="L1681"> GHCommit c = commits.get(sha1);</span>
|
|
<span class="pc bpc" id="L1682" title="1 of 2 branches missed."> if (c == null) {</span>
|
|
<span class="fc" id="L1683"> c = root.createRequest()</span>
|
|
<span class="fc" id="L1684"> .withUrlPath(String.format("/repos/%s/%s/commits/%s", getOwnerName(), name, sha1))</span>
|
|
<span class="fc" id="L1685"> .fetch(GHCommit.class)</span>
|
|
<span class="fc" id="L1686"> .wrapUp(this);</span>
|
|
<span class="fc" id="L1687"> commits.put(sha1, c);</span>
|
|
}
|
|
<span class="fc" id="L1689"> return c;</span>
|
|
}
|
|
|
|
/**
|
|
* Create commit gh commit builder.
|
|
*
|
|
* @return the gh commit builder
|
|
*/
|
|
public GHCommitBuilder createCommit() {
|
|
<span class="nc" id="L1698"> return new GHCommitBuilder(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Lists all the commits.
|
|
*
|
|
* @return the paged iterable
|
|
*/
|
|
public PagedIterable<GHCommit> listCommits() {
|
|
<span class="fc" id="L1707"> return root.createRequest()</span>
|
|
<span class="fc" id="L1708"> .withUrlPath(String.format("/repos/%s/%s/commits", getOwnerName(), name))</span>
|
|
<span class="fc" id="L1709"> .toIterable(GHCommit[].class, item -> item.wrapUp(this));</span>
|
|
}
|
|
|
|
/**
|
|
* Search commits by specifying filters through a builder pattern.
|
|
*
|
|
* @return the gh commit query builder
|
|
*/
|
|
public GHCommitQueryBuilder queryCommits() {
|
|
<span class="fc" id="L1718"> return new GHCommitQueryBuilder(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Lists up all the commit comments in this repository.
|
|
*
|
|
* @return the paged iterable
|
|
*/
|
|
public PagedIterable<GHCommitComment> listCommitComments() {
|
|
<span class="fc" id="L1727"> return root.createRequest()</span>
|
|
<span class="fc" id="L1728"> .withUrlPath(String.format("/repos/%s/%s/comments", getOwnerName(), name))</span>
|
|
<span class="fc" id="L1729"> .toIterable(GHCommitComment[].class, item -> item.wrap(this));</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the basic license details for the repository.
|
|
* <p>
|
|
*
|
|
* @return null if there's no license.
|
|
* @throws IOException
|
|
* as usual but also if you don't use the preview connector
|
|
*/
|
|
public GHLicense getLicense() throws IOException {
|
|
<span class="fc" id="L1741"> GHContentWithLicense lic = getLicenseContent_();</span>
|
|
<span class="fc bfc" id="L1742" title="All 2 branches covered."> return lic != null ? lic.license : null;</span>
|
|
}
|
|
|
|
/**
|
|
* Retrieves the contents of the repository's license file - makes an additional API call
|
|
* <p>
|
|
*
|
|
* @return details regarding the license contents, or null if there's no license.
|
|
* @throws IOException
|
|
* as usual but also if you don't use the preview connector
|
|
*/
|
|
public GHContent getLicenseContent() throws IOException {
|
|
<span class="fc" id="L1754"> return getLicenseContent_();</span>
|
|
}
|
|
|
|
private GHContentWithLicense getLicenseContent_() throws IOException {
|
|
try {
|
|
<span class="fc" id="L1759"> return root.createRequest()</span>
|
|
<span class="fc" id="L1760"> .withUrlPath(getApiTailUrl("license"))</span>
|
|
<span class="fc" id="L1761"> .fetch(GHContentWithLicense.class)</span>
|
|
<span class="fc" id="L1762"> .wrap(this);</span>
|
|
<span class="fc" id="L1763"> } catch (FileNotFoundException e) {</span>
|
|
<span class="fc" id="L1764"> return null;</span>
|
|
}
|
|
}
|
|
|
|
/**
|
|
* /** Lists all the commit statuses attached to the given commit, newer ones first.
|
|
*
|
|
* @param sha1
|
|
* the sha 1
|
|
* @return the paged iterable
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public PagedIterable<GHCommitStatus> listCommitStatuses(final String sha1) throws IOException {
|
|
<span class="fc" id="L1778"> return root.createRequest()</span>
|
|
<span class="fc" id="L1779"> .withUrlPath(String.format("/repos/%s/%s/statuses/%s", getOwnerName(), name, sha1))</span>
|
|
<span class="fc" id="L1780"> .toIterable(GHCommitStatus[].class, item -> item.wrapUp(root));</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the last status of this commit, which is what gets shown in the UI.
|
|
*
|
|
* @param sha1
|
|
* the sha 1
|
|
* @return the last commit status
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHCommitStatus getLastCommitStatus(String sha1) throws IOException {
|
|
<span class="fc" id="L1793"> List<GHCommitStatus> v = listCommitStatuses(sha1).toList();</span>
|
|
<span class="pc bpc" id="L1794" title="1 of 2 branches missed."> return v.isEmpty() ? null : v.get(0);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets check runs for given ref.
|
|
*
|
|
* @param ref
|
|
* ref
|
|
* @return check runs for given ref
|
|
* @throws IOException
|
|
* the io exception
|
|
* @see <a href="https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref">List check runs
|
|
* for a specific ref</a>
|
|
*/
|
|
@Preview
|
|
@Deprecated
|
|
public PagedIterable<GHCheckRun> getCheckRuns(String ref) throws IOException {
|
|
<span class="fc" id="L1811"> GitHubRequest request = root.createRequest()</span>
|
|
<span class="fc" id="L1812"> .withUrlPath(String.format("/repos/%s/%s/commits/%s/check-runs", getOwnerName(), name, ref))</span>
|
|
<span class="fc" id="L1813"> .withPreview(ANTIOPE)</span>
|
|
<span class="fc" id="L1814"> .build();</span>
|
|
<span class="fc" id="L1815"> return new GHCheckRunsIterable(root, request);</span>
|
|
}
|
|
|
|
/**
|
|
* Creates a commit status
|
|
*
|
|
* @param sha1
|
|
* the sha 1
|
|
* @param state
|
|
* the state
|
|
* @param targetUrl
|
|
* Optional parameter that points to the URL that has more details.
|
|
* @param description
|
|
* Optional short description.
|
|
* @param context
|
|
* Optinal commit status context.
|
|
* @return the gh commit status
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHCommitStatus createCommitStatus(String sha1,
|
|
GHCommitState state,
|
|
String targetUrl,
|
|
String description,
|
|
String context) throws IOException {
|
|
<span class="nc" id="L1840"> return root.createRequest()</span>
|
|
<span class="nc" id="L1841"> .method("POST")</span>
|
|
<span class="nc" id="L1842"> .with("state", state)</span>
|
|
<span class="nc" id="L1843"> .with("target_url", targetUrl)</span>
|
|
<span class="nc" id="L1844"> .with("description", description)</span>
|
|
<span class="nc" id="L1845"> .with("context", context)</span>
|
|
<span class="nc" id="L1846"> .withUrlPath(String.format("/repos/%s/%s/statuses/%s", getOwnerName(), this.name, sha1))</span>
|
|
<span class="nc" id="L1847"> .fetch(GHCommitStatus.class)</span>
|
|
<span class="nc" id="L1848"> .wrapUp(root);</span>
|
|
}
|
|
|
|
/**
|
|
* Create commit status gh commit status.
|
|
*
|
|
* @param sha1
|
|
* the sha 1
|
|
* @param state
|
|
* the state
|
|
* @param targetUrl
|
|
* the target url
|
|
* @param description
|
|
* the description
|
|
* @return the gh commit status
|
|
* @throws IOException
|
|
* the io exception
|
|
* @see #createCommitStatus(String, GHCommitState, String, String, String) #createCommitStatus(String,
|
|
* GHCommitState,String,String,String)
|
|
*/
|
|
public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description)
|
|
throws IOException {
|
|
<span class="nc" id="L1870"> return createCommitStatus(sha1, state, targetUrl, description, null);</span>
|
|
}
|
|
|
|
/**
|
|
* Creates a check run for a commit.
|
|
*
|
|
* @param name
|
|
* an identifier for the run
|
|
* @param headSHA
|
|
* the commit hash
|
|
* @return a builder which you should customize, then call {@link GHCheckRunBuilder#create}
|
|
*/
|
|
@Preview
|
|
@Deprecated
|
|
public @NonNull GHCheckRunBuilder createCheckRun(@NonNull String name, @NonNull String headSHA) {
|
|
<span class="fc" id="L1885"> return new GHCheckRunBuilder(this, name, headSHA);</span>
|
|
}
|
|
|
|
/**
|
|
* Lists repository events.
|
|
*
|
|
* @return the paged iterable
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public PagedIterable<GHEventInfo> listEvents() throws IOException {
|
|
<span class="nc" id="L1896"> return root.createRequest()</span>
|
|
<span class="nc" id="L1897"> .withUrlPath(String.format("/repos/%s/%s/events", getOwnerName(), name))</span>
|
|
<span class="nc" id="L1898"> .toIterable(GHEventInfo[].class, item -> item.wrapUp(root));</span>
|
|
}
|
|
|
|
/**
|
|
* Lists labels in this repository.
|
|
* <p>
|
|
* https://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository
|
|
*
|
|
* @return the paged iterable
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public PagedIterable<GHLabel> listLabels() throws IOException {
|
|
<span class="fc" id="L1911"> return GHLabel.readAll(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets label.
|
|
*
|
|
* @param name
|
|
* the name
|
|
* @return the label
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHLabel getLabel(String name) throws IOException {
|
|
<span class="fc" id="L1924"> return GHLabel.read(this, name);</span>
|
|
}
|
|
|
|
/**
|
|
* Create label gh label.
|
|
*
|
|
* @param name
|
|
* the name
|
|
* @param color
|
|
* the color
|
|
* @return the gh label
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHLabel createLabel(String name, String color) throws IOException {
|
|
<span class="fc" id="L1939"> return GHLabel.create(this).name(name).color(color).description("").done();</span>
|
|
}
|
|
|
|
/**
|
|
* Description is still in preview.
|
|
*
|
|
* @param name
|
|
* the name
|
|
* @param color
|
|
* the color
|
|
* @param description
|
|
* the description
|
|
* @return gh label
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHLabel createLabel(String name, String color, String description) throws IOException {
|
|
<span class="fc" id="L1956"> return GHLabel.create(this).name(name).color(color).description(description).done();</span>
|
|
}
|
|
|
|
/**
|
|
* Lists all the invitations.
|
|
*
|
|
* @return the paged iterable
|
|
*/
|
|
public PagedIterable<GHInvitation> listInvitations() {
|
|
<span class="nc" id="L1965"> return root.createRequest()</span>
|
|
<span class="nc" id="L1966"> .withUrlPath(String.format("/repos/%s/%s/invitations", getOwnerName(), name))</span>
|
|
<span class="nc" id="L1967"> .toIterable(GHInvitation[].class, item -> item.wrapUp(root));</span>
|
|
}
|
|
|
|
/**
|
|
* Lists all the subscribers (aka watchers.)
|
|
* <p>
|
|
* https://developer.github.com/v3/activity/watching/
|
|
*
|
|
* @return the paged iterable
|
|
*/
|
|
public PagedIterable<GHUser> listSubscribers() {
|
|
<span class="fc" id="L1978"> return listUsers("subscribers");</span>
|
|
}
|
|
|
|
/**
|
|
* Lists all the users who have starred this repo based on the old version of the API. For additional information,
|
|
* like date when the repository was starred, see {@link #listStargazers2()}
|
|
*
|
|
* @return the paged iterable
|
|
*/
|
|
public PagedIterable<GHUser> listStargazers() {
|
|
<span class="nc" id="L1988"> return listUsers("stargazers");</span>
|
|
}
|
|
|
|
/**
|
|
* Lists all the users who have starred this repo based on new version of the API, having extended information like
|
|
* the time when the repository was starred. For compatibility with the old API see {@link #listStargazers()}
|
|
*
|
|
* @return the paged iterable
|
|
*/
|
|
public PagedIterable<GHStargazer> listStargazers2() {
|
|
<span class="nc" id="L1998"> return root.createRequest()</span>
|
|
<span class="nc" id="L1999"> .withPreview("application/vnd.github.v3.star+json")</span>
|
|
<span class="nc" id="L2000"> .withUrlPath(getApiTailUrl("stargazers"))</span>
|
|
<span class="nc" id="L2001"> .toIterable(GHStargazer[].class, item -> item.wrapUp(this));</span>
|
|
}
|
|
|
|
private PagedIterable<GHUser> listUsers(final String suffix) {
|
|
<span class="fc" id="L2005"> return root.createRequest()</span>
|
|
<span class="fc" id="L2006"> .withUrlPath(getApiTailUrl(suffix))</span>
|
|
<span class="fc" id="L2007"> .toIterable(GHUser[].class, item -> item.wrapUp(root));</span>
|
|
}
|
|
|
|
/**
|
|
* See https://api.github.com/hooks for possible names and their configuration scheme. TODO: produce type-safe
|
|
* binding
|
|
*
|
|
* @param name
|
|
* Type of the hook to be created. See https://api.github.com/hooks for possible names.
|
|
* @param config
|
|
* The configuration hash.
|
|
* @param events
|
|
* Can be null. Types of events to hook into.
|
|
* @param active
|
|
* the active
|
|
* @return the gh hook
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHHook createHook(String name, Map<String, String> config, Collection<GHEvent> events, boolean active)
|
|
throws IOException {
|
|
<span class="fc" id="L2028"> return GHHooks.repoContext(this, owner).createHook(name, config, events, active);</span>
|
|
}
|
|
|
|
/**
|
|
* Create web hook gh hook.
|
|
*
|
|
* @param url
|
|
* the url
|
|
* @param events
|
|
* the events
|
|
* @return the gh hook
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHHook createWebHook(URL url, Collection<GHEvent> events) throws IOException {
|
|
<span class="fc" id="L2043"> return createHook("web", Collections.singletonMap("url", url.toExternalForm()), events, true);</span>
|
|
}
|
|
|
|
/**
|
|
* Create web hook gh hook.
|
|
*
|
|
* @param url
|
|
* the url
|
|
* @return the gh hook
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHHook createWebHook(URL url) throws IOException {
|
|
<span class="fc" id="L2056"> return createWebHook(url, null);</span>
|
|
}
|
|
|
|
/**
|
|
* Returns a set that represents the post-commit hook URLs. The returned set is live, and changes made to them are
|
|
* reflected to GitHub.
|
|
*
|
|
* @return the post commit hooks
|
|
* @deprecated Use {@link #getHooks()} and {@link #createHook(String, Map, Collection, boolean)}
|
|
*/
|
|
@SuppressFBWarnings(value = "DMI_COLLECTION_OF_URLS",
|
|
justification = "It causes a performance degradation, but we have already exposed it to the API")
|
|
@Deprecated
|
|
public Set<URL> getPostCommitHooks() {
|
|
<span class="fc" id="L2070"> return postCommitHooks;</span>
|
|
}
|
|
|
|
/**
|
|
* Live set view of the post-commit hook.
|
|
*/
|
|
<span class="fc" id="L2076"> @SuppressFBWarnings(value = "DMI_COLLECTION_OF_URLS",</span>
|
|
justification = "It causes a performance degradation, but we have already exposed it to the API")
|
|
@SkipFromToString
|
|
<span class="fc" id="L2079"> private final Set<URL> postCommitHooks = new AbstractSet<URL>() {</span>
|
|
private List<URL> getPostCommitHooks() {
|
|
try {
|
|
<span class="fc" id="L2082"> List<URL> r = new ArrayList<>();</span>
|
|
<span class="pc bpc" id="L2083" title="1 of 2 branches missed."> for (GHHook h : getHooks()) {</span>
|
|
<span class="nc bnc" id="L2084" title="All 2 branches missed."> if (h.getName().equals("web")) {</span>
|
|
<span class="nc" id="L2085"> r.add(new URL(h.getConfig().get("url")));</span>
|
|
}
|
|
<span class="nc" id="L2087"> }</span>
|
|
<span class="fc" id="L2088"> return r;</span>
|
|
<span class="nc" id="L2089"> } catch (IOException e) {</span>
|
|
<span class="nc" id="L2090"> throw new GHException("Failed to retrieve post-commit hooks", e);</span>
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Iterator<URL> iterator() {
|
|
<span class="nc" id="L2096"> return getPostCommitHooks().iterator();</span>
|
|
}
|
|
|
|
@Override
|
|
public int size() {
|
|
<span class="fc" id="L2101"> return getPostCommitHooks().size();</span>
|
|
}
|
|
|
|
@Override
|
|
public boolean add(URL url) {
|
|
try {
|
|
<span class="nc" id="L2107"> createWebHook(url);</span>
|
|
<span class="nc" id="L2108"> return true;</span>
|
|
<span class="nc" id="L2109"> } catch (IOException e) {</span>
|
|
<span class="nc" id="L2110"> throw new GHException("Failed to update post-commit hooks", e);</span>
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean remove(Object url) {
|
|
try {
|
|
<span class="nc" id="L2117"> String _url = ((URL) url).toExternalForm();</span>
|
|
<span class="nc bnc" id="L2118" title="All 2 branches missed."> for (GHHook h : getHooks()) {</span>
|
|
<span class="nc bnc" id="L2119" title="All 4 branches missed."> if (h.getName().equals("web") && h.getConfig().get("url").equals(_url)) {</span>
|
|
<span class="nc" id="L2120"> h.delete();</span>
|
|
<span class="nc" id="L2121"> return true;</span>
|
|
}
|
|
<span class="nc" id="L2123"> }</span>
|
|
<span class="nc" id="L2124"> return false;</span>
|
|
<span class="nc" id="L2125"> } catch (IOException e) {</span>
|
|
<span class="nc" id="L2126"> throw new GHException("Failed to update post-commit hooks", e);</span>
|
|
}
|
|
}
|
|
};
|
|
|
|
GHRepository wrap(GitHub root) {
|
|
<span class="fc" id="L2132"> this.root = root;</span>
|
|
<span class="fc bfc" id="L2133" title="All 2 branches covered."> if (root.isOffline()) {</span>
|
|
<span class="fc" id="L2134"> owner.wrapUp(root);</span>
|
|
}
|
|
<span class="fc" id="L2136"> return this;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets branches by {@linkplain GHBranch#getName() their names}.
|
|
*
|
|
* @return the branches
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public Map<String, GHBranch> getBranches() throws IOException {
|
|
<span class="nc" id="L2147"> Map<String, GHBranch> r = new TreeMap<String, GHBranch>();</span>
|
|
<span class="nc" id="L2148"> for (GHBranch p : root.createRequest()</span>
|
|
<span class="nc" id="L2149"> .withUrlPath(getApiTailUrl("branches"))</span>
|
|
<span class="nc" id="L2150"> .toIterable(GHBranch[].class, item -> item.wrap(this))</span>
|
|
<span class="nc bnc" id="L2151" title="All 2 branches missed."> .toArray()) {</span>
|
|
<span class="nc" id="L2152"> r.put(p.getName(), p);</span>
|
|
}
|
|
<span class="nc" id="L2154"> return r;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets branch.
|
|
*
|
|
* @param name
|
|
* the name
|
|
* @return the branch
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHBranch getBranch(String name) throws IOException {
|
|
<span class="fc" id="L2167"> return root.createRequest().withUrlPath(getApiTailUrl("branches/" + name)).fetch(GHBranch.class).wrap(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets milestones.
|
|
*
|
|
* @return the milestones
|
|
* @throws IOException
|
|
* the io exception
|
|
* @deprecated Use {@link #listMilestones(GHIssueState)}
|
|
*/
|
|
public Map<Integer, GHMilestone> getMilestones() throws IOException {
|
|
<span class="nc" id="L2179"> Map<Integer, GHMilestone> milestones = new TreeMap<Integer, GHMilestone>();</span>
|
|
<span class="nc bnc" id="L2180" title="All 2 branches missed."> for (GHMilestone m : listMilestones(GHIssueState.OPEN)) {</span>
|
|
<span class="nc" id="L2181"> milestones.put(m.getNumber(), m);</span>
|
|
<span class="nc" id="L2182"> }</span>
|
|
<span class="nc" id="L2183"> return milestones;</span>
|
|
}
|
|
|
|
/**
|
|
* Lists up all the milestones in this repository.
|
|
*
|
|
* @param state
|
|
* the state
|
|
* @return the paged iterable
|
|
*/
|
|
public PagedIterable<GHMilestone> listMilestones(final GHIssueState state) {
|
|
<span class="nc" id="L2194"> return root.createRequest()</span>
|
|
<span class="nc" id="L2195"> .with("state", state)</span>
|
|
<span class="nc" id="L2196"> .withUrlPath(getApiTailUrl("milestones"))</span>
|
|
<span class="nc" id="L2197"> .toIterable(GHMilestone[].class, item -> item.wrap(this));</span>
|
|
}
|
|
|
|
/**
|
|
* Gets milestone.
|
|
*
|
|
* @param number
|
|
* the number
|
|
* @return the milestone
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHMilestone getMilestone(int number) throws IOException {
|
|
<span class="fc" id="L2210"> GHMilestone m = milestones.get(number);</span>
|
|
<span class="pc bpc" id="L2211" title="1 of 2 branches missed."> if (m == null) {</span>
|
|
<span class="fc" id="L2212"> m = root.createRequest().withUrlPath(getApiTailUrl("milestones/" + number)).fetch(GHMilestone.class);</span>
|
|
<span class="fc" id="L2213"> m.owner = this;</span>
|
|
<span class="fc" id="L2214"> m.root = root;</span>
|
|
<span class="fc" id="L2215"> milestones.put(m.getNumber(), m);</span>
|
|
}
|
|
<span class="fc" id="L2217"> return m;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets file content.
|
|
*
|
|
* @param path
|
|
* the path
|
|
* @return the file content
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHContent getFileContent(String path) throws IOException {
|
|
<span class="fc" id="L2230"> return getFileContent(path, null);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets file content.
|
|
*
|
|
* @param path
|
|
* the path
|
|
* @param ref
|
|
* the ref
|
|
* @return the file content
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHContent getFileContent(String path, String ref) throws IOException {
|
|
<span class="fc" id="L2245"> Requester requester = root.createRequest();</span>
|
|
<span class="fc" id="L2246"> String target = getApiTailUrl("contents/" + path);</span>
|
|
|
|
<span class="fc" id="L2248"> return requester.with("ref", ref).withUrlPath(target).fetch(GHContent.class).wrap(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets directory content.
|
|
*
|
|
* @param path
|
|
* the path
|
|
* @return the directory content
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public List<GHContent> getDirectoryContent(String path) throws IOException {
|
|
<span class="fc" id="L2261"> return getDirectoryContent(path, null);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets directory content.
|
|
*
|
|
* @param path
|
|
* the path
|
|
* @param ref
|
|
* the ref
|
|
* @return the directory content
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public List<GHContent> getDirectoryContent(String path, String ref) throws IOException {
|
|
<span class="fc" id="L2276"> Requester requester = root.createRequest();</span>
|
|
<span class="fc bfc" id="L2277" title="All 2 branches covered."> while (path.endsWith("/")) {</span>
|
|
<span class="fc" id="L2278"> path = path.substring(0, path.length() - 1);</span>
|
|
}
|
|
<span class="fc" id="L2280"> String target = getApiTailUrl("contents/" + path);</span>
|
|
|
|
<span class="fc" id="L2282"> return requester.with("ref", ref)</span>
|
|
<span class="fc" id="L2283"> .withUrlPath(target)</span>
|
|
<span class="fc" id="L2284"> .toIterable(GHContent[].class, item -> item.wrap(this))</span>
|
|
<span class="fc" id="L2285"> .toList();</span>
|
|
}
|
|
|
|
/**
|
|
* https://developer.github.com/v3/repos/contents/#get-the-readme
|
|
*
|
|
* @return the readme
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHContent getReadme() throws IOException {
|
|
<span class="fc" id="L2296"> Requester requester = root.createRequest();</span>
|
|
<span class="fc" id="L2297"> return requester.withUrlPath(getApiTailUrl("readme")).fetch(GHContent.class).wrap(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Creates a new content, or update an existing content.
|
|
*
|
|
* @return the gh content builder
|
|
*/
|
|
public GHContentBuilder createContent() {
|
|
<span class="fc" id="L2306"> return new GHContentBuilder(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Use {@link #createContent()}.
|
|
*
|
|
* @param content
|
|
* the content
|
|
* @param commitMessage
|
|
* the commit message
|
|
* @param path
|
|
* the path
|
|
* @return the gh content update response
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
@Deprecated
|
|
public GHContentUpdateResponse createContent(String content, String commitMessage, String path) throws IOException {
|
|
<span class="fc" id="L2324"> return createContent().content(content).message(commitMessage).path(path).commit();</span>
|
|
}
|
|
|
|
/**
|
|
* Use {@link #createContent()}.
|
|
*
|
|
* @param content
|
|
* the content
|
|
* @param commitMessage
|
|
* the commit message
|
|
* @param path
|
|
* the path
|
|
* @param branch
|
|
* the branch
|
|
* @return the gh content update response
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
@Deprecated
|
|
public GHContentUpdateResponse createContent(String content, String commitMessage, String path, String branch)
|
|
throws IOException {
|
|
<span class="fc" id="L2345"> return createContent().content(content).message(commitMessage).path(path).branch(branch).commit();</span>
|
|
}
|
|
|
|
/**
|
|
* Use {@link #createContent()}.
|
|
*
|
|
* @param contentBytes
|
|
* the content bytes
|
|
* @param commitMessage
|
|
* the commit message
|
|
* @param path
|
|
* the path
|
|
* @return the gh content update response
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
@Deprecated
|
|
public GHContentUpdateResponse createContent(byte[] contentBytes, String commitMessage, String path)
|
|
throws IOException {
|
|
<span class="nc" id="L2364"> return createContent().content(contentBytes).message(commitMessage).path(path).commit();</span>
|
|
}
|
|
|
|
/**
|
|
* Use {@link #createContent()}.
|
|
*
|
|
* @param contentBytes
|
|
* the content bytes
|
|
* @param commitMessage
|
|
* the commit message
|
|
* @param path
|
|
* the path
|
|
* @param branch
|
|
* the branch
|
|
* @return the gh content update response
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
@Deprecated
|
|
public GHContentUpdateResponse createContent(byte[] contentBytes, String commitMessage, String path, String branch)
|
|
throws IOException {
|
|
<span class="nc" id="L2385"> return createContent().content(contentBytes).message(commitMessage).path(path).branch(branch).commit();</span>
|
|
}
|
|
|
|
/**
|
|
* Create milestone gh milestone.
|
|
*
|
|
* @param title
|
|
* the title
|
|
* @param description
|
|
* the description
|
|
* @return the gh milestone
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHMilestone createMilestone(String title, String description) throws IOException {
|
|
<span class="fc" id="L2400"> return root.createRequest()</span>
|
|
<span class="fc" id="L2401"> .method("POST")</span>
|
|
<span class="fc" id="L2402"> .with("title", title)</span>
|
|
<span class="fc" id="L2403"> .with("description", description)</span>
|
|
<span class="fc" id="L2404"> .withUrlPath(getApiTailUrl("milestones"))</span>
|
|
<span class="fc" id="L2405"> .fetch(GHMilestone.class)</span>
|
|
<span class="fc" id="L2406"> .wrap(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Add deploy key gh deploy key.
|
|
*
|
|
* @param title
|
|
* the title
|
|
* @param key
|
|
* the key
|
|
* @return the gh deploy key
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHDeployKey addDeployKey(String title, String key) throws IOException {
|
|
<span class="nc" id="L2421"> return root.createRequest()</span>
|
|
<span class="nc" id="L2422"> .method("POST")</span>
|
|
<span class="nc" id="L2423"> .with("title", title)</span>
|
|
<span class="nc" id="L2424"> .with("key", key)</span>
|
|
<span class="nc" id="L2425"> .withUrlPath(getApiTailUrl("keys"))</span>
|
|
<span class="nc" id="L2426"> .fetch(GHDeployKey.class)</span>
|
|
<span class="nc" id="L2427"> .wrap(this);</span>
|
|
|
|
}
|
|
|
|
/**
|
|
* Gets deploy keys.
|
|
*
|
|
* @return the deploy keys
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public List<GHDeployKey> getDeployKeys() throws IOException {
|
|
<span class="nc" id="L2439"> return root.createRequest()</span>
|
|
<span class="nc" id="L2440"> .withUrlPath(getApiTailUrl("keys"))</span>
|
|
<span class="nc" id="L2441"> .toIterable(GHDeployKey[].class, item -> item.wrap(this))</span>
|
|
<span class="nc" id="L2442"> .toList();</span>
|
|
}
|
|
|
|
/**
|
|
* Forked repositories have a 'source' attribute that specifies the ultimate source of the forking chain.
|
|
*
|
|
* @return {@link GHRepository} that points to the root repository where this repository is forked (indirectly or
|
|
* directly) from. Otherwise null.
|
|
* @throws IOException
|
|
* the io exception
|
|
* @see #getParent() #getParent()
|
|
*/
|
|
public GHRepository getSource() throws IOException {
|
|
<span class="nc bnc" id="L2455" title="All 2 branches missed."> if (source == null)</span>
|
|
<span class="nc" id="L2456"> return null;</span>
|
|
<span class="nc bnc" id="L2457" title="All 2 branches missed."> if (source.root == null)</span>
|
|
<span class="nc" id="L2458"> source = root.getRepository(source.getFullName());</span>
|
|
<span class="nc" id="L2459"> return source;</span>
|
|
}
|
|
|
|
/**
|
|
* Forked repositories have a 'parent' attribute that specifies the repository this repository is directly forked
|
|
* from. If we keep traversing {@link #getParent()} until it returns null, that is {@link #getSource()}.
|
|
*
|
|
* @return {@link GHRepository} that points to the repository where this repository is forked directly from.
|
|
* Otherwise null.
|
|
* @throws IOException
|
|
* the io exception
|
|
* @see #getSource() #getSource()
|
|
*/
|
|
public GHRepository getParent() throws IOException {
|
|
<span class="nc bnc" id="L2473" title="All 2 branches missed."> if (parent == null)</span>
|
|
<span class="nc" id="L2474"> return null;</span>
|
|
<span class="nc bnc" id="L2475" title="All 2 branches missed."> if (parent.root == null)</span>
|
|
<span class="nc" id="L2476"> parent = root.getRepository(parent.getFullName());</span>
|
|
<span class="nc" id="L2477"> return parent;</span>
|
|
}
|
|
|
|
/**
|
|
* Subscribes to this repository to get notifications.
|
|
*
|
|
* @param subscribed
|
|
* the subscribed
|
|
* @param ignored
|
|
* the ignored
|
|
* @return the gh subscription
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException {
|
|
<span class="fc" id="L2492"> return root.createRequest()</span>
|
|
<span class="fc" id="L2493"> .method("PUT")</span>
|
|
<span class="fc" id="L2494"> .with("subscribed", subscribed)</span>
|
|
<span class="fc" id="L2495"> .with("ignored", ignored)</span>
|
|
<span class="fc" id="L2496"> .withUrlPath(getApiTailUrl("subscription"))</span>
|
|
<span class="fc" id="L2497"> .fetch(GHSubscription.class)</span>
|
|
<span class="fc" id="L2498"> .wrapUp(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Returns the current subscription.
|
|
*
|
|
* @return null if no subscription exists.
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHSubscription getSubscription() throws IOException {
|
|
try {
|
|
<span class="pc" id="L2510"> return root.createRequest()</span>
|
|
<span class="fc" id="L2511"> .withUrlPath(getApiTailUrl("subscription"))</span>
|
|
<span class="nc" id="L2512"> .fetch(GHSubscription.class)</span>
|
|
<span class="nc" id="L2513"> .wrapUp(this);</span>
|
|
<span class="fc" id="L2514"> } catch (FileNotFoundException e) {</span>
|
|
<span class="fc" id="L2515"> return null;</span>
|
|
}
|
|
}
|
|
|
|
/**
|
|
* List contributors paged iterable.
|
|
*
|
|
* @return the paged iterable
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public PagedIterable<Contributor> listContributors() throws IOException {
|
|
<span class="fc" id="L2527"> return root.createRequest()</span>
|
|
<span class="fc" id="L2528"> .withUrlPath(getApiTailUrl("contributors"))</span>
|
|
<span class="fc" id="L2529"> .toIterable(Contributor[].class, item -> item.wrapUp(root));</span>
|
|
}
|
|
|
|
/**
|
|
* The type Contributor.
|
|
*/
|
|
<span class="fc" id="L2535"> public static class Contributor extends GHUser {</span>
|
|
private int contributions;
|
|
|
|
/**
|
|
* Gets contributions.
|
|
*
|
|
* @return the contributions
|
|
*/
|
|
public int getContributions() {
|
|
<span class="fc" id="L2544"> return contributions;</span>
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
// We ignore contributions in the calculation
|
|
<span class="nc" id="L2550"> return super.hashCode();</span>
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
// We ignore contributions in the calculation
|
|
<span class="nc" id="L2556"> return super.equals(obj);</span>
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns the statistics for this repository.
|
|
*
|
|
* @return the statistics
|
|
*/
|
|
public GHRepositoryStatistics getStatistics() {
|
|
// TODO: Use static object and introduce refresh() method,
|
|
// instead of returning new object each time.
|
|
<span class="fc" id="L2568"> return new GHRepositoryStatistics(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Create a project for this repository.
|
|
*
|
|
* @param name
|
|
* the name
|
|
* @param body
|
|
* the body
|
|
* @return the gh project
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHProject createProject(String name, String body) throws IOException {
|
|
<span class="nc" id="L2583"> return root.createRequest()</span>
|
|
<span class="nc" id="L2584"> .method("POST")</span>
|
|
<span class="nc" id="L2585"> .withPreview(INERTIA)</span>
|
|
<span class="nc" id="L2586"> .with("name", name)</span>
|
|
<span class="nc" id="L2587"> .with("body", body)</span>
|
|
<span class="nc" id="L2588"> .withUrlPath(getApiTailUrl("projects"))</span>
|
|
<span class="nc" id="L2589"> .fetch(GHProject.class)</span>
|
|
<span class="nc" id="L2590"> .wrap(this);</span>
|
|
}
|
|
|
|
/**
|
|
* Returns the projects for this repository.
|
|
*
|
|
* @param status
|
|
* The status filter (all, open or closed).
|
|
* @return the paged iterable
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public PagedIterable<GHProject> listProjects(final GHProject.ProjectStateFilter status) throws IOException {
|
|
<span class="nc" id="L2603"> return root.createRequest()</span>
|
|
<span class="nc" id="L2604"> .withPreview(INERTIA)</span>
|
|
<span class="nc" id="L2605"> .with("state", status)</span>
|
|
<span class="nc" id="L2606"> .withUrlPath(getApiTailUrl("projects"))</span>
|
|
<span class="nc" id="L2607"> .toIterable(GHProject[].class, item -> item.wrap(this));</span>
|
|
}
|
|
|
|
/**
|
|
* Returns open projects for this repository.
|
|
*
|
|
* @return the paged iterable
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public PagedIterable<GHProject> listProjects() throws IOException {
|
|
<span class="nc" id="L2618"> return listProjects(GHProject.ProjectStateFilter.OPEN);</span>
|
|
}
|
|
|
|
/**
|
|
* Render a Markdown document.
|
|
* <p>
|
|
* In {@linkplain MarkdownMode#GFM GFM mode}, issue numbers and user mentions are linked accordingly.
|
|
*
|
|
* @param text
|
|
* the text
|
|
* @param mode
|
|
* the mode
|
|
* @return the reader
|
|
* @throws IOException
|
|
* the io exception
|
|
* @see GitHub#renderMarkdown(String) GitHub#renderMarkdown(String)
|
|
*/
|
|
public Reader renderMarkdown(String text, MarkdownMode mode) throws IOException {
|
|
<span class="fc" id="L2636"> return new InputStreamReader(</span>
|
|
<span class="fc" id="L2637"> root.createRequest()</span>
|
|
<span class="fc" id="L2638"> .method("POST")</span>
|
|
<span class="fc" id="L2639"> .with("text", text)</span>
|
|
<span class="pc bpc" id="L2640" title="1 of 2 branches missed."> .with("mode", mode == null ? null : mode.toString())</span>
|
|
<span class="fc" id="L2641"> .with("context", getFullName())</span>
|
|
<span class="fc" id="L2642"> .withUrlPath("/markdown")</span>
|
|
<span class="fc" id="L2643"> .fetchStream(),</span>
|
|
"UTF-8");
|
|
}
|
|
|
|
/**
|
|
* List all the notifications in a repository for the current user.
|
|
*
|
|
* @return the gh notification stream
|
|
*/
|
|
public GHNotificationStream listNotifications() {
|
|
<span class="nc" id="L2653"> return new GHNotificationStream(root, getApiTailUrl("/notifications"));</span>
|
|
}
|
|
|
|
/**
|
|
* <a href=
|
|
* "https://developer.github.com/v3/repos/traffic/#views">https://developer.github.com/v3/repos/traffic/#views</a>
|
|
*
|
|
* @return the view traffic
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHRepositoryViewTraffic getViewTraffic() throws IOException {
|
|
<span class="fc" id="L2665"> return root.createRequest().withUrlPath(getApiTailUrl("/traffic/views")).fetch(GHRepositoryViewTraffic.class);</span>
|
|
}
|
|
|
|
/**
|
|
* <a href=
|
|
* "https://developer.github.com/v3/repos/traffic/#clones">https://developer.github.com/v3/repos/traffic/#clones</a>
|
|
*
|
|
* @return the clone traffic
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHRepositoryCloneTraffic getCloneTraffic() throws IOException {
|
|
<span class="fc" id="L2677"> return root.createRequest().withUrlPath(getApiTailUrl("/traffic/clones")).fetch(GHRepositoryCloneTraffic.class);</span>
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
<span class="nc" id="L2682"> return ("Repository:" + getOwnerName() + ":" + name).hashCode();</span>
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
<span class="pc bpc" id="L2687" title="1 of 2 branches missed."> if (obj instanceof GHRepository) {</span>
|
|
<span class="fc" id="L2688"> GHRepository that = (GHRepository) obj;</span>
|
|
<span class="pc bpc" id="L2689" title="1 of 4 branches missed."> return this.getOwnerName().equals(that.getOwnerName()) && this.name.equals(that.name);</span>
|
|
}
|
|
<span class="nc" id="L2691"> return false;</span>
|
|
}
|
|
|
|
String getApiTailUrl(String tail) {
|
|
<span class="fc bfc" id="L2695" title="All 4 branches covered."> if (tail.length() > 0 && !tail.startsWith("/"))</span>
|
|
<span class="fc" id="L2696"> tail = '/' + tail;</span>
|
|
<span class="fc" id="L2697"> return "/repos/" + getOwnerName() + "/" + name + tail;</span>
|
|
}
|
|
|
|
/**
|
|
* Get all issue events for this repository. See
|
|
* https://developer.github.com/v3/issues/events/#list-events-for-a-repository
|
|
*
|
|
* @return the paged iterable
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public PagedIterable<GHIssueEvent> listIssueEvents() throws IOException {
|
|
<span class="fc" id="L2709"> return root.createRequest()</span>
|
|
<span class="fc" id="L2710"> .withUrlPath(getApiTailUrl("issues/events"))</span>
|
|
<span class="fc" id="L2711"> .toIterable(GHIssueEvent[].class, item -> item.wrapUp(root));</span>
|
|
}
|
|
|
|
/**
|
|
* Get a single issue event. See https://developer.github.com/v3/issues/events/#get-a-single-event
|
|
*
|
|
* @param id
|
|
* the id
|
|
* @return the issue event
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHIssueEvent getIssueEvent(long id) throws IOException {
|
|
<span class="fc" id="L2724"> return root.createRequest()</span>
|
|
<span class="fc" id="L2725"> .withUrlPath(getApiTailUrl("issues/events/" + id))</span>
|
|
<span class="fc" id="L2726"> .fetch(GHIssueEvent.class)</span>
|
|
<span class="fc" id="L2727"> .wrapUp(root);</span>
|
|
}
|
|
|
|
// Only used within listTopics().
|
|
private static class Topics {
|
|
public List<String> names;
|
|
}
|
|
|
|
/**
|
|
* Return the topics for this repository. See
|
|
* https://developer.github.com/v3/repos/#list-all-topics-for-a-repository
|
|
*
|
|
* @return the list
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public List<String> listTopics() throws IOException {
|
|
<span class="fc" id="L2744"> Topics topics = root.createRequest()</span>
|
|
<span class="fc" id="L2745"> .withPreview(MERCY)</span>
|
|
<span class="fc" id="L2746"> .withUrlPath(getApiTailUrl("topics"))</span>
|
|
<span class="fc" id="L2747"> .fetch(Topics.class);</span>
|
|
<span class="fc" id="L2748"> return topics.names;</span>
|
|
}
|
|
|
|
/**
|
|
* Set the topics for this repository. See
|
|
* https://developer.github.com/v3/repos/#replace-all-topics-for-a-repository
|
|
*
|
|
* @param topics
|
|
* the topics
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void setTopics(List<String> topics) throws IOException {
|
|
<span class="fc" id="L2761"> root.createRequest()</span>
|
|
<span class="fc" id="L2762"> .method("PUT")</span>
|
|
<span class="fc" id="L2763"> .with("names", topics)</span>
|
|
<span class="fc" id="L2764"> .withPreview(MERCY)</span>
|
|
<span class="fc" id="L2765"> .withUrlPath(getApiTailUrl("topics"))</span>
|
|
<span class="fc" id="L2766"> .send();</span>
|
|
<span class="fc" id="L2767"> }</span>
|
|
|
|
/**
|
|
* Create a tag. See https://developer.github.com/v3/git/tags/#create-a-tag-object
|
|
*
|
|
* @param tag
|
|
* The tag's name.
|
|
* @param message
|
|
* The tag message.
|
|
* @param object
|
|
* The SHA of the git object this is tagging.
|
|
* @param type
|
|
* The type of the object we're tagging: "commit", "tree" or "blob".
|
|
* @return The newly created tag.
|
|
* @throws java.io.IOException
|
|
* The IO exception.
|
|
*/
|
|
public GHTagObject createTag(String tag, String message, String object, String type) throws IOException {
|
|
<span class="fc" id="L2785"> return root.createRequest()</span>
|
|
<span class="fc" id="L2786"> .method("POST")</span>
|
|
<span class="fc" id="L2787"> .with("tag", tag)</span>
|
|
<span class="fc" id="L2788"> .with("message", message)</span>
|
|
<span class="fc" id="L2789"> .with("object", object)</span>
|
|
<span class="fc" id="L2790"> .with("type", type)</span>
|
|
<span class="fc" id="L2791"> .withUrlPath(getApiTailUrl("git/tags"))</span>
|
|
<span class="fc" id="L2792"> .fetch(GHTagObject.class)</span>
|
|
<span class="fc" id="L2793"> .wrap(this);</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> |