Files
github-api/jacoco/org.kohsuke.github/GHTeam.java.html
2020-05-31 15:14:45 -07:00

322 lines
12 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>GHTeam.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">GHTeam.java</span></div><h1>GHTeam.java</h1><pre class="source lang-java linenums">package org.kohsuke.github;
import java.io.IOException;
import java.net.URL;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
/**
* A team in GitHub organization.
*
* @author Kohsuke Kawaguchi
*/
<span class="fc" id="L14">public class GHTeam extends GHObject implements Refreshable {</span>
private String html_url;
private String name;
private String permission;
private String slug;
private String description;
private Privacy privacy;
private GHOrganization organization; // populated by GET /user/teams where Teams+Orgs are returned together
protected /* final */ GitHub root;
<span class="fc" id="L26"> public enum Privacy {</span>
<span class="fc" id="L27"> SECRET, // only visible to organization owners and members of this team.</span>
<span class="fc" id="L28"> CLOSED // visible to all members of this organization.</span>
}
/**
* Member's role in a team
*/
<span class="nc" id="L34"> public enum Role {</span>
/**
* A normal member of the team
*/
<span class="nc" id="L38"> MEMBER,</span>
/**
* Able to add/remove other team members, promote other team members to team maintainer, and edit the team's
* name and description.
*/
<span class="nc" id="L43"> MAINTAINER</span>
}
GHTeam wrapUp(GHOrganization owner) {
<span class="fc" id="L47"> this.organization = owner;</span>
<span class="fc" id="L48"> this.root = owner.root;</span>
<span class="fc" id="L49"> return this;</span>
}
GHTeam wrapUp(GitHub root) { // auto-wrapUp when organization is known from GET /user/teams
<span class="fc" id="L53"> this.organization.wrapUp(root);</span>
<span class="fc" id="L54"> return wrapUp(organization);</span>
}
static GHTeam[] wrapUp(GHTeam[] teams, GHPullRequest owner) {
<span class="fc bfc" id="L58" title="All 2 branches covered."> for (GHTeam t : teams) {</span>
<span class="fc" id="L59"> t.root = owner.root;</span>
}
<span class="fc" id="L61"> return teams;</span>
}
/**
* Gets name.
*
* @return the name
*/
public String getName() {
<span class="fc" id="L70"> return name;</span>
}
/**
* Gets permission.
*
* @return the permission
*/
public String getPermission() {
<span class="fc" id="L79"> return permission;</span>
}
/**
* Gets slug.
*
* @return the slug
*/
public String getSlug() {
<span class="fc" id="L88"> return slug;</span>
}
/**
* Gets description.
*
* @return the description
*/
public String getDescription() {
<span class="fc" id="L97"> return description;</span>
}
/**
* Gets the privacy state.
*
* @return the privacy state.
*/
public Privacy getPrivacy() {
<span class="fc" id="L106"> return privacy;</span>
}
/**
* Sets description.
*
* @param description
* the description
* @throws IOException
* the io exception
*/
public void setDescription(String description) throws IOException {
<span class="fc" id="L118"> root.createRequest().method(&quot;PATCH&quot;).with(&quot;description&quot;, description).withUrlPath(api(&quot;&quot;)).send();</span>
<span class="fc" id="L119"> }</span>
/**
* Updates the team's privacy setting.
*
* @param privacy
* the privacy
* @throws IOException
* the io exception
*/
public void setPrivacy(Privacy privacy) throws IOException {
<span class="fc" id="L130"> root.createRequest().method(&quot;PATCH&quot;).with(&quot;privacy&quot;, privacy).withUrlPath(api(&quot;&quot;)).send();</span>
<span class="fc" id="L131"> }</span>
/**
* Retrieves the current members.
*
* @return the paged iterable
* @throws IOException
* the io exception
*/
public PagedIterable&lt;GHUser&gt; listMembers() throws IOException {
<span class="nc" id="L141"> return root.createRequest().withUrlPath(api(&quot;/members&quot;)).toIterable(GHUser[].class, item -&gt; item.wrapUp(root));</span>
}
/**
* Gets members.
*
* @return the members
* @throws IOException
* the io exception
*/
public Set&lt;GHUser&gt; getMembers() throws IOException {
<span class="nc" id="L152"> return listMembers().toSet();</span>
}
/**
* Checks if this team has the specified user as a member.
*
* @param user
* the user
* @return the boolean
*/
public boolean hasMember(GHUser user) {
try {
<span class="fc" id="L164"> root.createRequest().withUrlPath(&quot;/teams/&quot; + getId() + &quot;/members/&quot; + user.getLogin()).send();</span>
<span class="fc" id="L165"> return true;</span>
<span class="nc" id="L166"> } catch (IOException ignore) {</span>
<span class="nc" id="L167"> return false;</span>
}
}
/**
* Gets repositories.
*
* @return the repositories
* @throws IOException
* the io exception
*/
public Map&lt;String, GHRepository&gt; getRepositories() throws IOException {
<span class="fc" id="L179"> Map&lt;String, GHRepository&gt; m = new TreeMap&lt;String, GHRepository&gt;();</span>
<span class="fc bfc" id="L180" title="All 2 branches covered."> for (GHRepository r : listRepositories()) {</span>
<span class="fc" id="L181"> m.put(r.getName(), r);</span>
<span class="fc" id="L182"> }</span>
<span class="fc" id="L183"> return m;</span>
}
/**
* List repositories paged iterable.
*
* @return the paged iterable
*/
public PagedIterable&lt;GHRepository&gt; listRepositories() {
<span class="fc" id="L192"> return root.createRequest()</span>
<span class="fc" id="L193"> .withUrlPath(api(&quot;/repos&quot;))</span>
<span class="fc" id="L194"> .toIterable(GHRepository[].class, item -&gt; item.wrap(root));</span>
}
/**
* Adds a member to the team.
* &lt;p&gt;
* The user will be invited to the organization if required.
*
* @param u
* the u
* @throws IOException
* the io exception
* @since 1.59
*/
public void add(GHUser u) throws IOException {
<span class="nc" id="L209"> root.createRequest().method(&quot;PUT&quot;).withUrlPath(api(&quot;/memberships/&quot; + u.getLogin())).send();</span>
<span class="nc" id="L210"> }</span>
/**
* Adds a member to the team
* &lt;p&gt;
* The user will be invited to the organization if required.
*
* @param user
* github user
* @param role
* role for the new member
* @throws IOException
* the io exception
*/
public void add(GHUser user, Role role) throws IOException {
<span class="nc" id="L225"> root.createRequest()</span>
<span class="nc" id="L226"> .method(&quot;PUT&quot;)</span>
<span class="nc" id="L227"> .with(&quot;role&quot;, role)</span>
<span class="nc" id="L228"> .withUrlPath(api(&quot;/memberships/&quot; + user.getLogin()))</span>
<span class="nc" id="L229"> .send();</span>
<span class="nc" id="L230"> }</span>
/**
* Removes a member to the team.
*
* @param u
* the u
* @throws IOException
* the io exception
*/
public void remove(GHUser u) throws IOException {
<span class="nc" id="L241"> root.createRequest().method(&quot;DELETE&quot;).withUrlPath(api(&quot;/members/&quot; + u.getLogin())).send();</span>
<span class="nc" id="L242"> }</span>
/**
* Add.
*
* @param r
* the r
* @throws IOException
* the io exception
*/
public void add(GHRepository r) throws IOException {
<span class="nc" id="L253"> add(r, null);</span>
<span class="nc" id="L254"> }</span>
/**
* Add.
*
* @param r
* the r
* @param permission
* the permission
* @throws IOException
* the io exception
*/
public void add(GHRepository r, GHOrganization.Permission permission) throws IOException {
<span class="nc" id="L267"> root.createRequest()</span>
<span class="nc" id="L268"> .method(&quot;PUT&quot;)</span>
<span class="nc" id="L269"> .with(&quot;permission&quot;, permission)</span>
<span class="nc" id="L270"> .withUrlPath(api(&quot;/repos/&quot; + r.getOwnerName() + '/' + r.getName()))</span>
<span class="nc" id="L271"> .send();</span>
<span class="nc" id="L272"> }</span>
/**
* Remove.
*
* @param r
* the r
* @throws IOException
* the io exception
*/
public void remove(GHRepository r) throws IOException {
<span class="nc" id="L283"> root.createRequest().method(&quot;DELETE&quot;).withUrlPath(api(&quot;/repos/&quot; + r.getOwnerName() + '/' + r.getName())).send();</span>
<span class="nc" id="L284"> }</span>
/**
* Deletes this team.
*
* @throws IOException
* the io exception
*/
public void delete() throws IOException {
<span class="nc" id="L293"> root.createRequest().method(&quot;DELETE&quot;).withUrlPath(api(&quot;&quot;)).send();</span>
<span class="nc" id="L294"> }</span>
private String api(String tail) {
<span class="fc" id="L297"> return &quot;/teams/&quot; + getId() + tail;</span>
}
/**
* Gets organization.
*
* @return the organization
* @throws IOException
* the io exception
*/
public GHOrganization getOrganization() throws IOException {
<span class="fc" id="L308"> refresh(organization);</span>
<span class="fc" id="L309"> return organization;</span>
}
@Override
public void refresh() throws IOException {
<span class="fc" id="L314"> root.createRequest().withUrlPath(api(&quot;&quot;)).fetchInto(this).wrapUp(root);</span>
<span class="fc" id="L315"> }</span>
@Override
public URL getHtmlUrl() {
<span class="nc" id="L319"> return GitHubClient.parseURL(html_url);</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>