mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-26 15:50:47 +00:00
243 lines
11 KiB
HTML
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> > <a href="index.source.html" class="el_package">org.kohsuke.github</a> > <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<String> getEmails() throws IOException {
|
|
<span class="nc" id="L54"> List<GHEmail> src = getEmails2();</span>
|
|
<span class="nc" id="L55"> List<String> r = new ArrayList<String>(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.
|
|
* <p>
|
|
* 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<GHEmail> getEmails2() throws IOException {
|
|
<span class="nc" id="L73"> return root.createRequest().withUrlPath("/user/emails").toIterable(GHEmail[].class, null).toList();</span>
|
|
}
|
|
|
|
/**
|
|
* Returns the read-only list of all the pulic keys of the current user.
|
|
* <p>
|
|
* 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<GHKey> getPublicKeys() throws IOException {
|
|
<span class="nc" id="L87"> return root.createRequest().withUrlPath("/user/keys").toIterable(GHKey[].class, null).toList();</span>
|
|
}
|
|
|
|
/**
|
|
* Returns the read-only list of all the public verified keys of the current user.
|
|
* <p>
|
|
* 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<GHVerifiedKey> getPublicVerifiedKeys() throws IOException {
|
|
<span class="nc" id="L101"> return root.createRequest()</span>
|
|
<span class="nc" id="L102"> .withUrlPath("/users/" + getLogin() + "/keys")</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<GHOrganization> getAllOrganizations() throws IOException {
|
|
<span class="nc" id="L115"> GHPersonSet<GHOrganization> orgs = new GHPersonSet<GHOrganization>();</span>
|
|
<span class="nc" id="L116"> Set<String> names = new HashSet<String>();</span>
|
|
<span class="nc" id="L117"> for (GHOrganization o : root.createRequest()</span>
|
|
<span class="nc" id="L118"> .withUrlPath("/user/orgs")</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<String, GHRepository> getAllRepositories() throws IOException {
|
|
<span class="nc" id="L135"> Map<String, GHRepository> repositories = new TreeMap<String, GHRepository>();</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<GHRepository> 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<GHRepository> 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<GHRepository> listRepositories(final int pageSize, final RepositoryListFilter repoType) {
|
|
<span class="fc" id="L181"> return root.createRequest()</span>
|
|
<span class="fc" id="L182"> .with("type", repoType)</span>
|
|
<span class="fc" id="L183"> .withUrlPath("/user/repos")</span>
|
|
<span class="fc" id="L184"> .toIterable(GHRepository[].class, item -> 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<GHRepository> listAllRepositories() {
|
|
<span class="nc" id="L196"> return listRepositories();</span>
|
|
}
|
|
|
|
/**
|
|
* List your organization memberships
|
|
*
|
|
* @return the paged iterable
|
|
*/
|
|
public PagedIterable<GHMembership> 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<GHMembership> listOrgMemberships(final GHMembership.State state) {
|
|
<span class="fc" id="L216"> return root.createRequest()</span>
|
|
<span class="fc" id="L217"> .with("state", state)</span>
|
|
<span class="fc" id="L218"> .withUrlPath("/user/memberships/orgs")</span>
|
|
<span class="fc" id="L219"> .toIterable(GHMembership[].class, item -> 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("/user/memberships/orgs/" + o.getLogin())</span>
|
|
<span class="nc" id="L234"> .fetch(GHMembership.class)</span>
|
|
<span class="nc" id="L235"> .wrap(root);</span>
|
|
}
|
|
|
|
// public void addEmails(Collection<String> emails) throws IOException {
|
|
//// new Requester(root,ApiVersion.V3).withCredential().to("/user/emails");
|
|
// 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> |