Files
github-api/jacoco/org.kohsuke.github/GHMyself.java.html
2021-06-02 11:09:28 -07:00

243 lines
11 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>GHMyself.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> &gt; <a href="index.source.html" class="el_package">org.kohsuke.github</a> &gt; <span class="el_source">GHMyself.java</span></div><h1>GHMyself.java</h1><pre class="source lang-java linenums">package org.kohsuke.github;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
/**
* Represents the account that's logging into GitHub.
*
* @author Kohsuke Kawaguchi
*/
<span class="fc" id="L17">public class GHMyself extends GHUser {</span>
/**
* Type of repositories returned during listing.
*/
<span class="fc" id="L22"> public enum RepositoryListFilter {</span>
/**
* All public and private repositories that current user has access or collaborates to
*/
<span class="fc" id="L26"> ALL,</span>
/**
* Public and private repositories owned by current user
*/
<span class="fc" id="L30"> OWNER,</span>
/**
* Public repositories that current user has access or collaborates to
*/
<span class="fc" id="L34"> PUBLIC,</span>
/**
* Private repositories that current user has access or collaborates to
*/
<span class="fc" id="L38"> PRIVATE,</span>
/**
* Public and private repositories that current user is a member
*/
<span class="fc" id="L42"> MEMBER;</span>
}
/**
* Gets emails.
*
* @return the emails
* @throws IOException
* the io exception
* @deprecated Use {@link #getEmails2()}
*/
public List&lt;String&gt; getEmails() throws IOException {
<span class="nc" id="L54"> List&lt;GHEmail&gt; src = getEmails2();</span>
<span class="nc" id="L55"> List&lt;String&gt; r = new ArrayList&lt;String&gt;(src.size());</span>
<span class="nc bnc" id="L56" title="All 2 branches missed."> for (GHEmail e : src) {</span>
<span class="nc" id="L57"> r.add(e.getEmail());</span>
<span class="nc" id="L58"> }</span>
<span class="nc" id="L59"> return r;</span>
}
/**
* Returns the read-only list of e-mail addresses configured for you.
* &lt;p&gt;
* This corresponds to the stuff you configure in https://github.com/settings/emails, and not to be confused with
* {@link #getEmail()} that shows your public e-mail address set in https://github.com/settings/profile
*
* @return Always non-null.
* @throws IOException
* the io exception
*/
public List&lt;GHEmail&gt; getEmails2() throws IOException {
<span class="nc" id="L73"> return root.createRequest().withUrlPath(&quot;/user/emails&quot;).toIterable(GHEmail[].class, null).toList();</span>
}
/**
* Returns the read-only list of all the pulic keys of the current user.
* &lt;p&gt;
* NOTE: When using OAuth authenticaiton, the READ/WRITE User scope is required by the GitHub APIs, otherwise you
* will get a 404 NOT FOUND.
*
* @return Always non-null.
* @throws IOException
* the io exception
*/
public List&lt;GHKey&gt; getPublicKeys() throws IOException {
<span class="nc" id="L87"> return root.createRequest().withUrlPath(&quot;/user/keys&quot;).toIterable(GHKey[].class, null).toList();</span>
}
/**
* Returns the read-only list of all the public verified keys of the current user.
* &lt;p&gt;
* Differently from the getPublicKeys() method, the retrieval of the user's verified public keys does not require
* any READ/WRITE OAuth Scope to the user's profile.
*
* @return Always non-null.
* @throws IOException
* the io exception
*/
public List&lt;GHVerifiedKey&gt; getPublicVerifiedKeys() throws IOException {
<span class="nc" id="L101"> return root.createRequest()</span>
<span class="nc" id="L102"> .withUrlPath(&quot;/users/&quot; + getLogin() + &quot;/keys&quot;)</span>
<span class="nc" id="L103"> .toIterable(GHVerifiedKey[].class, null)</span>
<span class="nc" id="L104"> .toList();</span>
}
/**
* Gets the organization that this user belongs to.
*
* @return the all organizations
* @throws IOException
* the io exception
*/
public GHPersonSet&lt;GHOrganization&gt; getAllOrganizations() throws IOException {
<span class="nc" id="L115"> GHPersonSet&lt;GHOrganization&gt; orgs = new GHPersonSet&lt;GHOrganization&gt;();</span>
<span class="nc" id="L116"> Set&lt;String&gt; names = new HashSet&lt;String&gt;();</span>
<span class="nc" id="L117"> for (GHOrganization o : root.createRequest()</span>
<span class="nc" id="L118"> .withUrlPath(&quot;/user/orgs&quot;)</span>
<span class="nc" id="L119"> .toIterable(GHOrganization[].class, null)</span>
<span class="nc bnc" id="L120" title="All 2 branches missed."> .toArray()) {</span>
<span class="nc bnc" id="L121" title="All 2 branches missed."> if (names.add(o.getLogin())) // in case of rumoured duplicates in the data</span>
<span class="nc" id="L122"> orgs.add(root.getOrganization(o.getLogin()));</span>
}
<span class="nc" id="L124"> return orgs;</span>
}
/**
* Gets the all repositories this user owns (public and private).
*
* @return the all repositories
* @throws IOException
* the io exception
*/
public synchronized Map&lt;String, GHRepository&gt; getAllRepositories() throws IOException {
<span class="nc" id="L135"> Map&lt;String, GHRepository&gt; repositories = new TreeMap&lt;String, GHRepository&gt;();</span>
<span class="nc bnc" id="L136" title="All 2 branches missed."> for (GHRepository r : listAllRepositories()) {</span>
<span class="nc" id="L137"> repositories.put(r.getName(), r);</span>
<span class="nc" id="L138"> }</span>
<span class="nc" id="L139"> return Collections.unmodifiableMap(repositories);</span>
}
/**
* Lists up all repositories this user owns (public and private).
*
* Unlike {@link #getAllRepositories()}, this does not wait until all the repositories are returned. Repositories
* are returned by GitHub API with a 30 items per page.
*/
@Override
public PagedIterable&lt;GHRepository&gt; listRepositories() {
<span class="fc" id="L150"> return listRepositories(30);</span>
}
/**
* List repositories that are accessible to the authenticated user (public and private) using the specified page
* size.
*
* This includes repositories owned by the authenticated user, repositories that belong to other users where the
* authenticated user is a collaborator, and other organizations' repositories that the authenticated user has
* access to through an organization membership.
*
* @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.
*/
public PagedIterable&lt;GHRepository&gt; listRepositories(final int pageSize) {
<span class="fc" id="L167"> return listRepositories(pageSize, RepositoryListFilter.ALL);</span>
}
/**
* List repositories of a certain type that are accessible by current authenticated user using the specified page
* size.
*
* @param pageSize
* size for each page of items returned by GitHub. Maximum page size is 100.
* @param repoType
* type of repository returned in the listing
* @return the paged iterable
*/
public PagedIterable&lt;GHRepository&gt; listRepositories(final int pageSize, final RepositoryListFilter repoType) {
<span class="fc" id="L181"> return root.createRequest()</span>
<span class="fc" id="L182"> .with(&quot;type&quot;, repoType)</span>
<span class="fc" id="L183"> .withUrlPath(&quot;/user/repos&quot;)</span>
<span class="fc" id="L184"> .toIterable(GHRepository[].class, item -&gt; item.wrap(root))</span>
<span class="fc" id="L185"> .withPageSize(pageSize);</span>
}
/**
* List all repositories paged iterable.
*
* @return the paged iterable
* @deprecated Use {@link #listRepositories()}
*/
@Deprecated
public PagedIterable&lt;GHRepository&gt; listAllRepositories() {
<span class="nc" id="L196"> return listRepositories();</span>
}
/**
* List your organization memberships
*
* @return the paged iterable
*/
public PagedIterable&lt;GHMembership&gt; listOrgMemberships() {
<span class="fc" id="L205"> return listOrgMemberships(null);</span>
}
/**
* List your organization memberships
*
* @param state
* Filter by a specific state
* @return the paged iterable
*/
public PagedIterable&lt;GHMembership&gt; listOrgMemberships(final GHMembership.State state) {
<span class="fc" id="L216"> return root.createRequest()</span>
<span class="fc" id="L217"> .with(&quot;state&quot;, state)</span>
<span class="fc" id="L218"> .withUrlPath(&quot;/user/memberships/orgs&quot;)</span>
<span class="fc" id="L219"> .toIterable(GHMembership[].class, item -&gt; item.wrap(root));</span>
}
/**
* Gets your membership in a specific organization.
*
* @param o
* the o
* @return the membership
* @throws IOException
* the io exception
*/
public GHMembership getMembership(GHOrganization o) throws IOException {
<span class="nc" id="L232"> return root.createRequest()</span>
<span class="nc" id="L233"> .withUrlPath(&quot;/user/memberships/orgs/&quot; + o.getLogin())</span>
<span class="nc" id="L234"> .fetch(GHMembership.class)</span>
<span class="nc" id="L235"> .wrap(root);</span>
}
// public void addEmails(Collection&lt;String&gt; emails) throws IOException {
//// new Requester(root,ApiVersion.V3).withCredential().to(&quot;/user/emails&quot;);
// root.retrieveWithAuth3()
// }
}
</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>