mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-20 15:50:29 +00:00
185 lines
8.5 KiB
HTML
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> > <a href="index.source.html" class="el_package">org.kohsuke.github</a> > <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 = "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", justification = "JSON API")
|
|
<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 <a href="https://docs.github.com/en/developers/webhooks-and-events/github-event-types">GitHub event
|
|
* types</a>
|
|
*/
|
|
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 = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
|
|
"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" },
|
|
justification = "JSON API")
|
|
<span class="fc" id="L45"> public static class GHEventRepository {</span>
|
|
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
|
|
private long id;
|
|
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
|
|
private String url; // repository API URL
|
|
private String name; // owner/repo
|
|
}
|
|
|
|
<span class="fc" id="L53"> static final Map<String, GHEvent> mapTypeStringToEvent = createEventMap();</span>
|
|
|
|
/**
|
|
* Map for GitHub Event API Event Type to GHEvent.
|
|
*
|
|
* @see <a href="https://docs.github.com/en/developers/webhooks-and-events/github-event-types">GitHub event
|
|
* types</a>
|
|
*/
|
|
private static Map<String, GHEvent> createEventMap() {
|
|
<span class="fc" id="L62"> HashMap<String, GHEvent> map = new HashMap<>();</span>
|
|
<span class="fc" id="L63"> map.put("CommitCommentEvent", GHEvent.COMMIT_COMMENT);</span>
|
|
<span class="fc" id="L64"> map.put("CreateEvent", GHEvent.CREATE);</span>
|
|
<span class="fc" id="L65"> map.put("DeleteEvent", GHEvent.DELETE);</span>
|
|
<span class="fc" id="L66"> map.put("ForkEvent", GHEvent.FORK);</span>
|
|
<span class="fc" id="L67"> map.put("GollumEvent", GHEvent.GOLLUM);</span>
|
|
<span class="fc" id="L68"> map.put("IssueCommentEvent", GHEvent.ISSUE_COMMENT);</span>
|
|
<span class="fc" id="L69"> map.put("IssuesEvent", GHEvent.ISSUES);</span>
|
|
<span class="fc" id="L70"> map.put("MemberEvent", GHEvent.MEMBER);</span>
|
|
<span class="fc" id="L71"> map.put("PublicEvent", GHEvent.PUBLIC);</span>
|
|
<span class="fc" id="L72"> map.put("PullRequestEvent", GHEvent.PULL_REQUEST);</span>
|
|
<span class="fc" id="L73"> map.put("PullRequestReviewEvent", GHEvent.PULL_REQUEST_REVIEW);</span>
|
|
<span class="fc" id="L74"> map.put("PullRequestReviewCommentEvent", GHEvent.PULL_REQUEST_REVIEW_COMMENT);</span>
|
|
<span class="fc" id="L75"> map.put("PushEvent", GHEvent.PUSH);</span>
|
|
<span class="fc" id="L76"> map.put("ReleaseEvent", GHEvent.RELEASE);</span>
|
|
<span class="fc" id="L77"> map.put("WatchEvent", 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 = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" },
|
|
justification = "The field comes from JSON deserialization")
|
|
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 = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" },
|
|
justification = "The field comes from JSON deserialization")
|
|
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 = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" },
|
|
justification = "The field comes from JSON deserialization")
|
|
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 <T>
|
|
* 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 <T extends GHEventPayload> T getPayload(Class<T> 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> |