Files
github-api/jacoco/org.kohsuke.github/GHTeam.java.html
2020-06-10 08:53:50 -07:00

389 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>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.Objects;
import java.util.Set;
import java.util.TreeMap;
import javax.annotation.Nonnull;
/**
* A team in GitHub organization.
*
* @author Kohsuke Kawaguchi
*/
<span class="fc" id="L17">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="L29"> public enum Privacy {</span>
<span class="fc" id="L30"> SECRET, // only visible to organization owners and members of this team.</span>
<span class="fc" id="L31"> CLOSED // visible to all members of this organization.</span>
}
/**
* Member's role in a team
*/
<span class="nc" id="L37"> public enum Role {</span>
/**
* A normal member of the team
*/
<span class="nc" id="L41"> 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="L46"> MAINTAINER</span>
}
GHTeam wrapUp(GHOrganization owner) {
<span class="fc" id="L50"> this.organization = owner;</span>
<span class="fc" id="L51"> this.root = owner.root;</span>
<span class="fc" id="L52"> return this;</span>
}
GHTeam wrapUp(GitHub root) { // auto-wrapUp when organization is known from GET /user/teams
<span class="fc" id="L56"> this.organization.wrapUp(root);</span>
<span class="fc" id="L57"> return wrapUp(organization);</span>
}
static GHTeam[] wrapUp(GHTeam[] teams, GHPullRequest owner) {
<span class="fc bfc" id="L61" title="All 2 branches covered."> for (GHTeam t : teams) {</span>
<span class="fc" id="L62"> t.root = owner.root;</span>
}
<span class="fc" id="L64"> return teams;</span>
}
/**
* Gets name.
*
* @return the name
*/
public String getName() {
<span class="fc" id="L73"> return name;</span>
}
/**
* Gets permission.
*
* @return the permission
*/
public String getPermission() {
<span class="fc" id="L82"> return permission;</span>
}
/**
* Gets slug.
*
* @return the slug
*/
public String getSlug() {
<span class="fc" id="L91"> return slug;</span>
}
/**
* Gets description.
*
* @return the description
*/
public String getDescription() {
<span class="fc" id="L100"> return description;</span>
}
/**
* Gets the privacy state.
*
* @return the privacy state.
*/
public Privacy getPrivacy() {
<span class="fc" id="L109"> 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="L121"> root.createRequest().method(&quot;PATCH&quot;).with(&quot;description&quot;, description).withUrlPath(api(&quot;&quot;)).send();</span>
<span class="fc" id="L122"> }</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="L133"> root.createRequest().method(&quot;PATCH&quot;).with(&quot;privacy&quot;, privacy).withUrlPath(api(&quot;&quot;)).send();</span>
<span class="fc" id="L134"> }</span>
/**
* Retrieves the discussions.
*
* @return the paged iterable
* @throws IOException
* the io exception
*/
@Nonnull
public PagedIterable&lt;GHDiscussion&gt; listDiscussions() throws IOException {
<span class="fc" id="L145"> return GHDiscussion.readAll(this);</span>
}
/**
* Gets a single discussion by ID.
*
* @param discussionNumber
* id of the discussion that we want to query for
* @return the discussion
* @throws java.io.FileNotFoundException
* if the discussion does not exist
* @throws IOException
* the io exception
*
* @see &lt;a href= &quot;https://developer.github.com/v3/teams/discussions/#get-a-discussion&quot;&gt;documentation&lt;/a&gt;
*/
@Nonnull
public GHDiscussion getDiscussion(long discussionNumber) throws IOException {
<span class="fc" id="L163"> return GHDiscussion.read(this, discussionNumber);</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="L174"> 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="L185"> 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="L197"> root.createRequest().withUrlPath(&quot;/teams/&quot; + getId() + &quot;/members/&quot; + user.getLogin()).send();</span>
<span class="fc" id="L198"> return true;</span>
<span class="nc" id="L199"> } catch (IOException ignore) {</span>
<span class="nc" id="L200"> 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="L212"> Map&lt;String, GHRepository&gt; m = new TreeMap&lt;String, GHRepository&gt;();</span>
<span class="fc bfc" id="L213" title="All 2 branches covered."> for (GHRepository r : listRepositories()) {</span>
<span class="fc" id="L214"> m.put(r.getName(), r);</span>
<span class="fc" id="L215"> }</span>
<span class="fc" id="L216"> return m;</span>
}
/**
* List repositories paged iterable.
*
* @return the paged iterable
*/
public PagedIterable&lt;GHRepository&gt; listRepositories() {
<span class="fc" id="L225"> return root.createRequest()</span>
<span class="fc" id="L226"> .withUrlPath(api(&quot;/repos&quot;))</span>
<span class="fc" id="L227"> .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="L242"> root.createRequest().method(&quot;PUT&quot;).withUrlPath(api(&quot;/memberships/&quot; + u.getLogin())).send();</span>
<span class="nc" id="L243"> }</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="L258"> root.createRequest()</span>
<span class="nc" id="L259"> .method(&quot;PUT&quot;)</span>
<span class="nc" id="L260"> .with(&quot;role&quot;, role)</span>
<span class="nc" id="L261"> .withUrlPath(api(&quot;/memberships/&quot; + user.getLogin()))</span>
<span class="nc" id="L262"> .send();</span>
<span class="nc" id="L263"> }</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="L274"> root.createRequest().method(&quot;DELETE&quot;).withUrlPath(api(&quot;/members/&quot; + u.getLogin())).send();</span>
<span class="nc" id="L275"> }</span>
/**
* Add.
*
* @param r
* the r
* @throws IOException
* the io exception
*/
public void add(GHRepository r) throws IOException {
<span class="nc" id="L286"> add(r, null);</span>
<span class="nc" id="L287"> }</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="L300"> root.createRequest()</span>
<span class="nc" id="L301"> .method(&quot;PUT&quot;)</span>
<span class="nc" id="L302"> .with(&quot;permission&quot;, permission)</span>
<span class="nc" id="L303"> .withUrlPath(api(&quot;/repos/&quot; + r.getOwnerName() + '/' + r.getName()))</span>
<span class="nc" id="L304"> .send();</span>
<span class="nc" id="L305"> }</span>
/**
* Remove.
*
* @param r
* the r
* @throws IOException
* the io exception
*/
public void remove(GHRepository r) throws IOException {
<span class="nc" id="L316"> root.createRequest().method(&quot;DELETE&quot;).withUrlPath(api(&quot;/repos/&quot; + r.getOwnerName() + '/' + r.getName())).send();</span>
<span class="nc" id="L317"> }</span>
/**
* Deletes this team.
*
* @throws IOException
* the io exception
*/
public void delete() throws IOException {
<span class="nc" id="L326"> root.createRequest().method(&quot;DELETE&quot;).withUrlPath(api(&quot;&quot;)).send();</span>
<span class="nc" id="L327"> }</span>
private String api(String tail) {
<span class="fc" id="L330"> return &quot;/teams/&quot; + getId() + tail;</span>
}
/**
* Begins the creation of a new instance.
*
* Consumer must call {@link GHDiscussion.Creator#done()} to commit changes.
*
* @param title
* title of the discussion to be created
* @return a {@link GHDiscussion.Creator}
* @throws IOException
* the io exception
*/
public GHDiscussion.Creator createDiscussion(String title) throws IOException {
<span class="fc" id="L345"> return GHDiscussion.create(this).title(title);</span>
}
/**
* Gets organization.
*
* @return the organization
* @throws IOException
* the io exception
*/
public GHOrganization getOrganization() throws IOException {
<span class="fc" id="L356"> refresh(organization);</span>
<span class="fc" id="L357"> return organization;</span>
}
@Override
public void refresh() throws IOException {
<span class="fc" id="L362"> root.createRequest().withUrlPath(api(&quot;&quot;)).fetchInto(this).wrapUp(root);</span>
<span class="fc" id="L363"> }</span>
@Override
public URL getHtmlUrl() {
<span class="nc" id="L367"> return GitHubClient.parseURL(html_url);</span>
}
@Override
public boolean equals(Object o) {
<span class="fc bfc" id="L372" title="All 2 branches covered."> if (this == o) {</span>
<span class="fc" id="L373"> return true;</span>
}
<span class="pc bpc" id="L375" title="2 of 4 branches missed."> if (o == null || getClass() != o.getClass()) {</span>
<span class="nc" id="L376"> return false;</span>
}
<span class="fc" id="L378"> GHTeam ghTeam = (GHTeam) o;</span>
<span class="pc bpc" id="L379" title="2 of 4 branches missed."> return Objects.equals(name, ghTeam.name) &amp;&amp; Objects.equals(getUrl(), ghTeam.getUrl())</span>
<span class="pc bpc" id="L380" title="2 of 4 branches missed."> &amp;&amp; Objects.equals(permission, ghTeam.permission) &amp;&amp; Objects.equals(slug, ghTeam.slug)</span>
<span class="pc bpc" id="L381" title="2 of 4 branches missed."> &amp;&amp; Objects.equals(description, ghTeam.description) &amp;&amp; privacy == ghTeam.privacy;</span>
}
@Override
public int hashCode() {
<span class="fc" id="L386"> return Objects.hash(name, getUrl(), permission, slug, description, privacy);</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>