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

231 lines
9.3 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>GHDiscussion.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">GHDiscussion.java</span></div><h1>GHDiscussion.java</h1><pre class="source lang-java linenums">package org.kohsuke.github;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.kohsuke.github.internal.Previews;
import java.io.IOException;
import java.net.URL;
import java.util.Objects;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
/**
* A discussion in GitHub Team.
*
* @author Charles Moulliard
* @see &lt;a href=&quot;https://developer.github.com/v3/teams/discussions&quot;&gt;GitHub Team Discussions&lt;/a&gt;
*/
<span class="fc" id="L19">public class GHDiscussion extends GHObject {</span>
private GHTeam team;
private long number;
private String body, title, htmlUrl;
@JsonProperty(value = &quot;private&quot;)
private boolean isPrivate;
@Override
public URL getHtmlUrl() throws IOException {
<span class="nc" id="L30"> return GitHubClient.parseURL(htmlUrl);</span>
}
GHDiscussion wrapUp(GHTeam team) {
<span class="fc" id="L34"> this.team = team;</span>
<span class="fc" id="L35"> return this;</span>
}
/**
* Get the team to which this discussion belongs.
*
* @return the team for this discussion
*/
@Nonnull
public GHTeam getTeam() {
<span class="fc" id="L45"> return team;</span>
}
/**
* Get the title of the discussion.
*
* @return the title
*/
public String getTitle() {
<span class="fc" id="L54"> return title;</span>
}
/**
* The description of this discussion.
*
* @return the body
*/
public String getBody() {
<span class="fc" id="L63"> return body;</span>
}
/**
* The number of this discussion.
*
* @return the number
*/
public long getNumber() {
<span class="fc" id="L72"> return number;</span>
}
/**
* The id number of this discussion. GitHub discussions have &quot;number&quot; instead of &quot;id&quot;. This is provided for
* convenience.
*
* @return the id number for this discussion
* @see #getNumber()
*/
@Override
public long getId() {
<span class="fc" id="L84"> return getNumber();</span>
}
/**
* Whether the discussion is private to the team.
*
* @return {@code true} if discussion is private.
*/
public boolean isPrivate() {
<span class="fc" id="L93"> return isPrivate;</span>
}
/**
* Begins the creation of a new instance.
*
* Consumer must call {@link GHDiscussion.Creator#done()} to commit changes.
*
* @param team
* the team in which the discussion will be created.
* @return a {@link GHLabel.Creator}
* @throws IOException
* the io exception
*/
static GHDiscussion.Creator create(GHTeam team) throws IOException {
<span class="fc" id="L108"> return new GHDiscussion.Creator(team);</span>
}
static GHDiscussion read(GHTeam team, long discussionNumber) throws IOException {
<span class="fc" id="L112"> return team.root.createRequest()</span>
<span class="fc" id="L113"> .setRawUrlPath(getRawUrlPath(team, discussionNumber))</span>
<span class="fc" id="L114"> .fetch(GHDiscussion.class)</span>
<span class="fc" id="L115"> .wrapUp(team);</span>
}
static PagedIterable&lt;GHDiscussion&gt; readAll(GHTeam team) throws IOException {
<span class="fc" id="L119"> return team.root.createRequest()</span>
<span class="fc" id="L120"> .setRawUrlPath(getRawUrlPath(team, null))</span>
<span class="fc" id="L121"> .toIterable(GHDiscussion[].class, item -&gt; item.wrapUp(team));</span>
}
/**
* Begins a batch update
*
* Consumer must call {@link GHDiscussion.Updater#done()} to commit changes.
*
* @return a {@link GHDiscussion.Updater}
*/
@Preview(Previews.SQUIRREL_GIRL)
@Deprecated
public GHDiscussion.Updater update() {
<span class="fc" id="L134"> return new GHDiscussion.Updater(this);</span>
}
/**
* Begins a single property update.
*
* @return a {@link GHDiscussion.Setter}
*/
@Preview(Previews.SQUIRREL_GIRL)
@Deprecated
public GHDiscussion.Setter set() {
<span class="fc" id="L145"> return new GHDiscussion.Setter(this);</span>
}
/**
* Delete the discussion
*
* @throws IOException
* the io exception
*/
public void delete() throws IOException {
<span class="fc" id="L155"> team.root.createRequest().method(&quot;DELETE&quot;).setRawUrlPath(getRawUrlPath(team, number)).send();</span>
<span class="fc" id="L156"> }</span>
private static String getRawUrlPath(@Nonnull GHTeam team, @CheckForNull Long discussionNumber) {
<span class="fc bfc" id="L159" title="All 2 branches covered."> return team.getUrl().toString() + &quot;/discussions&quot; + (discussionNumber == null ? &quot;&quot; : &quot;/&quot; + discussionNumber);</span>
}
/**
* A {@link GHLabelBuilder} that updates a single property per request
*
* {@link #done()} is called automatically after the property is set.
*/
public static class Setter extends GHDiscussionBuilder&lt;GHDiscussion&gt; {
private Setter(@Nonnull GHDiscussion base) {
<span class="fc" id="L169"> super(GHDiscussion.class, base.team, base);</span>
<span class="fc" id="L170"> requester.method(&quot;PATCH&quot;).setRawUrlPath(base.getUrl().toString());</span>
<span class="fc" id="L171"> }</span>
}
/**
* A {@link GHLabelBuilder} that allows multiple properties to be updated per request.
*
* Consumer must call {@link #done()} to commit changes.
*/
public static class Updater extends GHDiscussionBuilder&lt;Updater&gt; {
private Updater(@Nonnull GHDiscussion base) {
<span class="fc" id="L181"> super(GHDiscussion.Updater.class, base.team, base);</span>
<span class="fc" id="L182"> requester.method(&quot;PATCH&quot;).setRawUrlPath(base.getUrl().toString());</span>
<span class="fc" id="L183"> }</span>
}
/**
* A {@link GHLabelBuilder} that creates a new {@link GHLabel}
*
* Consumer must call {@link #done()} to create the new instance.
*/
public static class Creator extends GHDiscussionBuilder&lt;Creator&gt; {
private Creator(@Nonnull GHTeam team) {
<span class="fc" id="L194"> super(GHDiscussion.Creator.class, team, null);</span>
<span class="fc" id="L195"> requester.method(&quot;POST&quot;).setRawUrlPath(getRawUrlPath(team, null));</span>
<span class="fc" id="L196"> }</span>
/**
* Sets whether this discussion is private to this team.
*
* @param value
* privacy of this discussion
* @return either a continuing builder or an updated {@link GHDiscussion}
* @throws IOException
* if there is an I/O Exception
*/
@Nonnull
public Creator private_(boolean value) throws IOException {
<span class="fc" id="L209"> return with(&quot;private&quot;, value);</span>
}
}
@Override
public boolean equals(Object o) {
<span class="pc bpc" id="L215" title="1 of 2 branches missed."> if (this == o) {</span>
<span class="nc" id="L216"> return true;</span>
}
<span class="pc bpc" id="L218" title="2 of 4 branches missed."> if (o == null || getClass() != o.getClass()) {</span>
<span class="nc" id="L219"> return false;</span>
}
<span class="fc" id="L221"> GHDiscussion that = (GHDiscussion) o;</span>
<span class="pc bpc" id="L222" title="3 of 6 branches missed."> return number == that.number &amp;&amp; Objects.equals(getUrl(), that.getUrl()) &amp;&amp; Objects.equals(team, that.team)</span>
<span class="pc bpc" id="L223" title="2 of 4 branches missed."> &amp;&amp; Objects.equals(body, that.body) &amp;&amp; Objects.equals(title, that.title);</span>
}
@Override
public int hashCode() {
<span class="fc" id="L228"> return Objects.hash(team, number, body, title);</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>