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

185 lines
8.5 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>GHEventInfo.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">GHEventInfo.java</span></div><h1>GHEventInfo.java</h1><pre class="source lang-java linenums">package org.kohsuke.github;
import com.fasterxml.jackson.databind.node.ObjectNode;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.util.*;
/**
* Represents an event.
*
* @author Kohsuke Kawaguchi
*/
@SuppressFBWarnings(value = &quot;UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD&quot;, justification = &quot;JSON API&quot;)
<span class="fc" id="L15">public class GHEventInfo extends GitHubInteractiveObject {</span>
// we don't want to expose Jackson dependency to the user. This needs databinding
private ObjectNode payload;
private long id;
private String created_at;
/**
* Representation of GitHub Event API Event Type.
*
* This is not the same as the values used for hook methods such as
* {@link GHRepository#createHook(String, Map, Collection, boolean)}.
*
* @see &lt;a href=&quot;https://docs.github.com/en/developers/webhooks-and-events/github-event-types&quot;&gt;GitHub event
* types&lt;/a&gt;
*/
private String type;
// these are all shallow objects
private GHEventRepository repo;
private GHUser actor;
private GHOrganization org;
/**
* Inside the event JSON model, GitHub uses a slightly different format.
*/
@SuppressFBWarnings(
value = { &quot;UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD&quot;, &quot;UWF_UNWRITTEN_FIELD&quot;,
&quot;UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR&quot; },
justification = &quot;JSON API&quot;)
<span class="fc" id="L45"> public static class GHEventRepository {</span>
@SuppressFBWarnings(value = &quot;UUF_UNUSED_FIELD&quot;, justification = &quot;We don't provide it in API now&quot;)
private long id;
@SuppressFBWarnings(value = &quot;UUF_UNUSED_FIELD&quot;, justification = &quot;We don't provide it in API now&quot;)
private String url; // repository API URL
private String name; // owner/repo
}
<span class="fc" id="L53"> static final Map&lt;String, GHEvent&gt; mapTypeStringToEvent = createEventMap();</span>
/**
* Map for GitHub Event API Event Type to GHEvent.
*
* @see &lt;a href=&quot;https://docs.github.com/en/developers/webhooks-and-events/github-event-types&quot;&gt;GitHub event
* types&lt;/a&gt;
*/
private static Map&lt;String, GHEvent&gt; createEventMap() {
<span class="fc" id="L62"> HashMap&lt;String, GHEvent&gt; map = new HashMap&lt;&gt;();</span>
<span class="fc" id="L63"> map.put(&quot;CommitCommentEvent&quot;, GHEvent.COMMIT_COMMENT);</span>
<span class="fc" id="L64"> map.put(&quot;CreateEvent&quot;, GHEvent.CREATE);</span>
<span class="fc" id="L65"> map.put(&quot;DeleteEvent&quot;, GHEvent.DELETE);</span>
<span class="fc" id="L66"> map.put(&quot;ForkEvent&quot;, GHEvent.FORK);</span>
<span class="fc" id="L67"> map.put(&quot;GollumEvent&quot;, GHEvent.GOLLUM);</span>
<span class="fc" id="L68"> map.put(&quot;IssueCommentEvent&quot;, GHEvent.ISSUE_COMMENT);</span>
<span class="fc" id="L69"> map.put(&quot;IssuesEvent&quot;, GHEvent.ISSUES);</span>
<span class="fc" id="L70"> map.put(&quot;MemberEvent&quot;, GHEvent.MEMBER);</span>
<span class="fc" id="L71"> map.put(&quot;PublicEvent&quot;, GHEvent.PUBLIC);</span>
<span class="fc" id="L72"> map.put(&quot;PullRequestEvent&quot;, GHEvent.PULL_REQUEST);</span>
<span class="fc" id="L73"> map.put(&quot;PullRequestReviewEvent&quot;, GHEvent.PULL_REQUEST_REVIEW);</span>
<span class="fc" id="L74"> map.put(&quot;PullRequestReviewCommentEvent&quot;, GHEvent.PULL_REQUEST_REVIEW_COMMENT);</span>
<span class="fc" id="L75"> map.put(&quot;PushEvent&quot;, GHEvent.PUSH);</span>
<span class="fc" id="L76"> map.put(&quot;ReleaseEvent&quot;, GHEvent.RELEASE);</span>
<span class="fc" id="L77"> map.put(&quot;WatchEvent&quot;, GHEvent.WATCH);</span>
<span class="fc" id="L78"> return Collections.unmodifiableMap(map);</span>
}
static GHEvent transformTypeToGHEvent(String type) {
<span class="fc" id="L82"> return mapTypeStringToEvent.getOrDefault(type, GHEvent.UNKNOWN);</span>
}
/**
* Gets type.
*
* @return the type
*/
public GHEvent getType() {
<span class="fc" id="L91"> return transformTypeToGHEvent(type);</span>
}
GHEventInfo wrapUp(GitHub root) {
<span class="fc" id="L95"> this.root = root;</span>
<span class="fc" id="L96"> return this;</span>
}
/**
* Gets id.
*
* @return the id
*/
public long getId() {
<span class="fc" id="L105"> return id;</span>
}
/**
* Gets created at.
*
* @return the created at
*/
public Date getCreatedAt() {
<span class="fc" id="L114"> return GitHubClient.parseDate(created_at);</span>
}
/**
* Gets repository.
*
* @return Repository where the change was made.
* @throws IOException
* on error
*/
@SuppressFBWarnings(value = { &quot;UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR&quot; },
justification = &quot;The field comes from JSON deserialization&quot;)
public GHRepository getRepository() throws IOException {
<span class="fc" id="L127"> return root.getRepository(repo.name);</span>
}
/**
* Gets actor.
*
* @return the {@link GHUser} actor for this event.
* @throws IOException
* on error
*/
@SuppressFBWarnings(value = { &quot;UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR&quot; },
justification = &quot;The field comes from JSON deserialization&quot;)
public GHUser getActor() throws IOException {
<span class="nc" id="L140"> return root.getUser(actor.getLogin());</span>
}
/**
* Gets actor login.
*
* @return the login of the actor.
* @throws IOException
* on error
*/
public String getActorLogin() throws IOException {
<span class="fc" id="L151"> return actor.getLogin();</span>
}
/**
* Gets organization.
*
* @return the organization
* @throws IOException
* the io exception
*/
@SuppressFBWarnings(value = { &quot;UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR&quot; },
justification = &quot;The field comes from JSON deserialization&quot;)
public GHOrganization getOrganization() throws IOException {
<span class="pc bpc" id="L164" title="3 of 4 branches missed."> return (org == null || org.getLogin() == null) ? null : root.getOrganization(org.getLogin());</span>
}
/**
* Retrieves the payload.
*
* @param &lt;T&gt;
* the type parameter
* @param type
* Specify one of the {@link GHEventPayload} subtype that defines a type-safe access to the payload. This
* must match the {@linkplain #getType() event type}.
* @return parsed event payload
* @throws IOException
* if payload cannot be parsed
*/
public &lt;T extends GHEventPayload&gt; T getPayload(Class&lt;T&gt; type) throws IOException {
<span class="fc" id="L180"> T v = GitHubClient.getMappingObjectReader(root).readValue(payload.traverse(), type);</span>
<span class="fc" id="L181"> v.wrapUp(root);</span>
<span class="fc" id="L182"> return v;</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>