mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-12 00:11:22 +00:00
206 lines
8.0 KiB
HTML
206 lines
8.0 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>GHThread.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">GHThread.java</span></div><h1>GHThread.java</h1><pre class="source lang-java linenums">package org.kohsuke.github;
|
|
|
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.net.URL;
|
|
import java.util.Date;
|
|
|
|
/**
|
|
* A conversation in the notification API.
|
|
*
|
|
* @author Kohsuke Kawaguchi
|
|
* @see <a href="https://developer.github.com/v3/activity/notifications/">documentation</a>
|
|
* @see GHNotificationStream
|
|
*/
|
|
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
|
|
justification = "JSON API")
|
|
public class GHThread extends GHObject {
|
|
private GHRepository repository;
|
|
private Subject subject;
|
|
private String reason;
|
|
private boolean unread;
|
|
private String last_read_at;
|
|
private String url, subscription_url;
|
|
|
|
<span class="fc" id="L27"> static class Subject {</span>
|
|
String title;
|
|
String url;
|
|
String latest_comment_url;
|
|
String type;
|
|
}
|
|
|
|
private GHThread() {// no external construction allowed
|
|
}
|
|
|
|
/**
|
|
* Returns null if the entire thread has never been read.
|
|
*
|
|
* @return the last read at
|
|
*/
|
|
public Date getLastReadAt() {
|
|
<span class="fc" id="L43"> return GitHubClient.parseDate(last_read_at);</span>
|
|
}
|
|
|
|
/**
|
|
* @deprecated This object has no HTML URL.
|
|
*/
|
|
@Override
|
|
public URL getHtmlUrl() {
|
|
<span class="nc" id="L51"> return null;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets reason.
|
|
*
|
|
* @return the reason
|
|
*/
|
|
public String getReason() {
|
|
<span class="fc" id="L60"> return reason;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets repository.
|
|
*
|
|
* @return the repository
|
|
*/
|
|
public GHRepository getRepository() {
|
|
<span class="fc" id="L69"> return repository;</span>
|
|
}
|
|
|
|
// TODO: how to expose the subject?
|
|
|
|
/**
|
|
* Is read boolean.
|
|
*
|
|
* @return the boolean
|
|
*/
|
|
public boolean isRead() {
|
|
<span class="pc bpc" id="L80" title="1 of 2 branches missed."> return !unread;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets title.
|
|
*
|
|
* @return the title
|
|
*/
|
|
public String getTitle() {
|
|
<span class="fc" id="L89"> return subject.title;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets type.
|
|
*
|
|
* @return the type
|
|
*/
|
|
public String getType() {
|
|
<span class="fc" id="L98"> return subject.type;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets last comment url.
|
|
*
|
|
* @return the last comment url
|
|
*/
|
|
public String getLastCommentUrl() {
|
|
<span class="fc" id="L107"> return subject.latest_comment_url;</span>
|
|
}
|
|
|
|
/**
|
|
* If this thread is about an issue, return that issue.
|
|
*
|
|
* @return null if this thread is not about an issue.
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHIssue getBoundIssue() throws IOException {
|
|
<span class="nc bnc" id="L118" title="All 4 branches missed."> if (!"Issue".equals(subject.type) && "PullRequest".equals(subject.type))</span>
|
|
<span class="nc" id="L119"> return null;</span>
|
|
<span class="nc" id="L120"> return repository.getIssue(Integer.parseInt(subject.url.substring(subject.url.lastIndexOf('/') + 1)));</span>
|
|
}
|
|
|
|
/**
|
|
* If this thread is about a pull request, return that pull request.
|
|
*
|
|
* @return null if this thread is not about a pull request.
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHPullRequest getBoundPullRequest() throws IOException {
|
|
<span class="nc bnc" id="L131" title="All 2 branches missed."> if (!"PullRequest".equals(subject.type))</span>
|
|
<span class="nc" id="L132"> return null;</span>
|
|
<span class="nc" id="L133"> return repository.getPullRequest(Integer.parseInt(subject.url.substring(subject.url.lastIndexOf('/') + 1)));</span>
|
|
}
|
|
|
|
/**
|
|
* If this thread is about a commit, return that commit.
|
|
*
|
|
* @return null if this thread is not about a commit.
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHCommit getBoundCommit() throws IOException {
|
|
<span class="nc bnc" id="L144" title="All 2 branches missed."> if (!"Commit".equals(subject.type))</span>
|
|
<span class="nc" id="L145"> return null;</span>
|
|
<span class="nc" id="L146"> return repository.getCommit(subject.url.substring(subject.url.lastIndexOf('/') + 1));</span>
|
|
}
|
|
|
|
GHThread wrap(GitHub root) {
|
|
<span class="fc" id="L150"> this.root = root;</span>
|
|
<span class="pc bpc" id="L151" title="1 of 2 branches missed."> if (this.repository != null)</span>
|
|
<span class="fc" id="L152"> this.repository.wrap(root);</span>
|
|
<span class="fc" id="L153"> return this;</span>
|
|
}
|
|
|
|
/**
|
|
* Marks this thread as read.
|
|
*
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void markAsRead() throws IOException {
|
|
<span class="fc" id="L163"> root.createRequest().method("PATCH").withUrlPath(url).send();</span>
|
|
<span class="fc" id="L164"> }</span>
|
|
|
|
/**
|
|
* Subscribes to this conversation to get notifications.
|
|
*
|
|
* @param subscribed
|
|
* the subscribed
|
|
* @param ignored
|
|
* the ignored
|
|
* @return the gh subscription
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException {
|
|
<span class="nc" id="L178"> return root.createRequest()</span>
|
|
<span class="nc" id="L179"> .method("PUT")</span>
|
|
<span class="nc" id="L180"> .with("subscribed", subscribed)</span>
|
|
<span class="nc" id="L181"> .with("ignored", ignored)</span>
|
|
<span class="nc" id="L182"> .withUrlPath(subscription_url)</span>
|
|
<span class="nc" id="L183"> .fetch(GHSubscription.class)</span>
|
|
<span class="nc" id="L184"> .wrapUp(root);</span>
|
|
}
|
|
|
|
/**
|
|
* Returns the current subscription for this thread.
|
|
*
|
|
* @return null if no subscription exists.
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHSubscription getSubscription() throws IOException {
|
|
try {
|
|
<span class="nc" id="L196"> return root.createRequest()</span>
|
|
<span class="nc" id="L197"> .method("POST")</span>
|
|
<span class="nc" id="L198"> .withUrlPath(subscription_url)</span>
|
|
<span class="nc" id="L199"> .fetch(GHSubscription.class)</span>
|
|
<span class="nc" id="L200"> .wrapUp(root);</span>
|
|
<span class="nc" id="L201"> } catch (FileNotFoundException e) {</span>
|
|
<span class="nc" id="L202"> return null;</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> |