mirror of
https://github.com/jlengrand/github-api.git
synced 2026-04-08 15:51:02 +00:00
371 lines
14 KiB
HTML
371 lines
14 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>GHPerson.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">GHPerson.java</span></div><h1>GHPerson.java</h1><pre class="source lang-java linenums">package org.kohsuke.github;
|
|
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.net.MalformedURLException;
|
|
import java.net.URL;
|
|
import java.util.Collections;
|
|
import java.util.Date;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Optional;
|
|
import java.util.TreeMap;
|
|
|
|
/**
|
|
* Common part of {@link GHUser} and {@link GHOrganization}.
|
|
*
|
|
* @author Kohsuke Kawaguchi
|
|
*/
|
|
<span class="fc" id="L20">public abstract class GHPerson extends GHObject {</span>
|
|
|
|
// core data fields that exist even for "small" user data (such as the user info in pull request)
|
|
protected String login, avatar_url;
|
|
|
|
// other fields (that only show up in full data)
|
|
protected String location, blog, email, bio, name, company, type, twitter_username;
|
|
protected String html_url;
|
|
protected int followers, following, public_repos, public_gists;
|
|
protected boolean site_admin, hireable;
|
|
|
|
// other fields (that only show up in full data) that require privileged scope
|
|
protected Integer total_private_repos;
|
|
|
|
GHPerson wrapUp(GitHub root) {
|
|
<span class="fc" id="L35"> this.root = root;</span>
|
|
<span class="fc" id="L36"> return this;</span>
|
|
}
|
|
|
|
/**
|
|
* Fully populate the data by retrieving missing data.
|
|
* <p>
|
|
* Depending on the original API call where this object is created, it may not contain everything.
|
|
*
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
protected synchronized void populate() throws IOException {
|
|
<span class="fc bfc" id="L48" title="All 2 branches covered."> if (super.getCreatedAt() != null) {</span>
|
|
<span class="fc" id="L49"> return; // already populated</span>
|
|
}
|
|
<span class="pc bpc" id="L51" title="2 of 4 branches missed."> if (root == null || root.isOffline()) {</span>
|
|
<span class="nc" id="L52"> return; // cannot populate, will have to live with what we have</span>
|
|
}
|
|
<span class="fc" id="L54"> URL url = getUrl();</span>
|
|
<span class="pc bpc" id="L55" title="1 of 2 branches missed."> if (url != null) {</span>
|
|
<span class="fc" id="L56"> root.createRequest().setRawUrlPath(url.toString()).fetchInto(this);</span>
|
|
}
|
|
<span class="fc" id="L58"> }</span>
|
|
|
|
/**
|
|
* Gets the public repositories this user owns.
|
|
*
|
|
* <p>
|
|
* To list your own repositories, including private repositories, use {@link GHMyself#listRepositories()}
|
|
*
|
|
* @return the repositories
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public synchronized Map<String, GHRepository> getRepositories() throws IOException {
|
|
<span class="fc" id="L71"> Map<String, GHRepository> repositories = new TreeMap<String, GHRepository>();</span>
|
|
<span class="fc bfc" id="L72" title="All 2 branches covered."> for (GHRepository r : listRepositories(100)) {</span>
|
|
<span class="fc" id="L73"> repositories.put(r.getName(), r);</span>
|
|
<span class="fc" id="L74"> }</span>
|
|
<span class="fc" id="L75"> return Collections.unmodifiableMap(repositories);</span>
|
|
}
|
|
|
|
/**
|
|
* Lists up all the repositories using a 30 items page size.
|
|
* <p>
|
|
* Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned.
|
|
*
|
|
* @return the paged iterable
|
|
*/
|
|
public PagedIterable<GHRepository> listRepositories() {
|
|
<span class="fc" id="L86"> return listRepositories(30);</span>
|
|
}
|
|
|
|
/**
|
|
* Lists up all the repositories using the specified page size.
|
|
*
|
|
* @param pageSize
|
|
* size for each page of items returned by GitHub. Maximum page size is 100. Unlike
|
|
* {@link #getRepositories()}, this does not wait until all the repositories are returned.
|
|
* @return the paged iterable
|
|
*/
|
|
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
|
|
<span class="fc" id="L98"> return root.createRequest()</span>
|
|
<span class="fc" id="L99"> .withUrlPath("/users/" + login + "/repos")</span>
|
|
<span class="fc" id="L100"> .toIterable(GHRepository[].class, item -> item.wrap(root))</span>
|
|
<span class="fc" id="L101"> .withPageSize(pageSize);</span>
|
|
}
|
|
|
|
/**
|
|
* Loads repository list in a paginated fashion.
|
|
*
|
|
* <p>
|
|
* For a person with a lot of repositories, GitHub returns the list of repositories in a paginated fashion. Unlike
|
|
* {@link #getRepositories()}, this method allows the caller to start processing data as it arrives.
|
|
* <p>
|
|
* Every {@link Iterator#next()} call results in I/O. Exceptions that occur during the processing is wrapped into
|
|
* {@link Error}.
|
|
*
|
|
* @param pageSize
|
|
* the page size
|
|
* @return the iterable
|
|
* @deprecated Use {@link #listRepositories()}
|
|
*/
|
|
@Deprecated
|
|
public synchronized Iterable<List<GHRepository>> iterateRepositories(final int pageSize) {
|
|
<span class="nc" id="L121"> return () -> {</span>
|
|
final PagedIterator<GHRepository> pager;
|
|
try {
|
|
<span class="nc" id="L124"> GitHubPageIterator<GHRepository[]> iterator = GitHubPageIterator.create(root.getClient(),</span>
|
|
GHRepository[].class,
|
|
<span class="nc" id="L126"> root.createRequest().withUrlPath("users", login, "repos").build(),</span>
|
|
pageSize);
|
|
<span class="nc" id="L128"> pager = new PagedIterator<>(iterator, item -> item.wrap(root));</span>
|
|
<span class="nc" id="L129"> } catch (MalformedURLException e) {</span>
|
|
<span class="nc" id="L130"> throw new GHException("Unable to build GitHub API URL", e);</span>
|
|
<span class="nc" id="L131"> }</span>
|
|
|
|
<span class="nc" id="L133"> return new Iterator<List<GHRepository>>() {</span>
|
|
public boolean hasNext() {
|
|
<span class="nc" id="L135"> return pager.hasNext();</span>
|
|
}
|
|
|
|
public List<GHRepository> next() {
|
|
<span class="nc" id="L139"> return pager.nextPage();</span>
|
|
}
|
|
};
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Gets repository.
|
|
*
|
|
* @param name
|
|
* the name
|
|
* @return null if the repository was not found
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHRepository getRepository(String name) throws IOException {
|
|
try {
|
|
<span class="fc" id="L156"> return GHRepository.read(root, login, name);</span>
|
|
<span class="nc" id="L157"> } catch (FileNotFoundException e) {</span>
|
|
<span class="nc" id="L158"> return null;</span>
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Lists events for an organization or an user.
|
|
*
|
|
* @return the paged iterable
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public abstract PagedIterable<GHEventInfo> listEvents() throws IOException;
|
|
|
|
/**
|
|
* Gravatar ID of this user, like 0cb9832a01c22c083390f3c5dcb64105
|
|
*
|
|
* @return the gravatar id
|
|
* @deprecated No longer available in the v3 API.
|
|
*/
|
|
@Deprecated
|
|
public String getGravatarId() {
|
|
<span class="nc" id="L179"> return "";</span>
|
|
}
|
|
|
|
/**
|
|
* Returns a string of the avatar image URL.
|
|
*
|
|
* @return the avatar url
|
|
*/
|
|
public String getAvatarUrl() {
|
|
<span class="nc" id="L188"> return avatar_url;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the login ID of this user, like 'kohsuke'
|
|
*
|
|
* @return the login
|
|
*/
|
|
public String getLogin() {
|
|
<span class="fc" id="L197"> return login;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the human-readable name of the user, like "Kohsuke Kawaguchi"
|
|
*
|
|
* @return the name
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public String getName() throws IOException {
|
|
<span class="fc" id="L208"> populate();</span>
|
|
<span class="fc" id="L209"> return name;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the company name of this user, like "Sun Microsystems, Inc."
|
|
*
|
|
* @return the company
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public String getCompany() throws IOException {
|
|
<span class="fc" id="L220"> populate();</span>
|
|
<span class="fc" id="L221"> return company;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the location of this user, like "Santa Clara, California"
|
|
*
|
|
* @return the location
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public String getLocation() throws IOException {
|
|
<span class="nc" id="L232"> populate();</span>
|
|
<span class="nc" id="L233"> return location;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the Twitter Username of this user, like "GitHub"
|
|
*
|
|
* @return the Twitter username
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public String getTwitterUsername() throws IOException {
|
|
<span class="fc" id="L244"> populate();</span>
|
|
<span class="fc" id="L245"> return twitter_username;</span>
|
|
}
|
|
|
|
public Date getCreatedAt() throws IOException {
|
|
<span class="nc" id="L249"> populate();</span>
|
|
<span class="nc" id="L250"> return super.getCreatedAt();</span>
|
|
}
|
|
|
|
public Date getUpdatedAt() throws IOException {
|
|
<span class="nc" id="L254"> populate();</span>
|
|
<span class="nc" id="L255"> return super.getUpdatedAt();</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the blog URL of this user.
|
|
*
|
|
* @return the blog
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public String getBlog() throws IOException {
|
|
<span class="fc" id="L266"> populate();</span>
|
|
<span class="fc" id="L267"> return blog;</span>
|
|
}
|
|
|
|
@Override
|
|
public URL getHtmlUrl() {
|
|
<span class="nc" id="L272"> return GitHubClient.parseURL(html_url);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the e-mail address of the user.
|
|
*
|
|
* @return the email
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public String getEmail() throws IOException {
|
|
<span class="nc" id="L283"> populate();</span>
|
|
<span class="nc" id="L284"> return email;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets public gist count.
|
|
*
|
|
* @return the public gist count
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public int getPublicGistCount() throws IOException {
|
|
<span class="fc" id="L295"> populate();</span>
|
|
<span class="fc" id="L296"> return public_gists;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets public repo count.
|
|
*
|
|
* @return the public repo count
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public int getPublicRepoCount() throws IOException {
|
|
<span class="fc" id="L307"> populate();</span>
|
|
<span class="fc" id="L308"> return public_repos;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets following count.
|
|
*
|
|
* @return the following count
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public int getFollowingCount() throws IOException {
|
|
<span class="fc" id="L319"> populate();</span>
|
|
<span class="fc" id="L320"> return following;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets followers count.
|
|
*
|
|
* @return the followers count
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public int getFollowersCount() throws IOException {
|
|
<span class="fc" id="L331"> populate();</span>
|
|
<span class="fc" id="L332"> return followers;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the type. This is either "User" or "Organization".
|
|
*
|
|
* @return the type
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public String getType() throws IOException {
|
|
<span class="fc" id="L343"> populate();</span>
|
|
<span class="fc" id="L344"> return type;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the site_admin field
|
|
*
|
|
* @return the site_admin field
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public boolean isSiteAdmin() throws IOException {
|
|
<span class="fc" id="L355"> populate();</span>
|
|
<span class="fc" id="L356"> return site_admin;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets total private repo count.
|
|
*
|
|
* @return the total private repo count
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public Optional<Integer> getTotalPrivateRepoCount() throws IOException {
|
|
<span class="fc" id="L367"> populate();</span>
|
|
<span class="fc" id="L368"> return Optional.ofNullable(total_private_repos);</span>
|
|
}
|
|
}
|
|
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html> |