22
33import com .fasterxml .jackson .databind .node .ObjectNode ;
44import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
5- import org .kohsuke .github .GHEvent .GitHubEventType ;
65
76import java .io .IOException ;
8- import java .util .Date ;
7+ import java .util .* ;
98
109/**
1110 * Represents an event.
@@ -19,6 +18,16 @@ public class GHEventInfo extends GitHubInteractiveObject {
1918
2019 private long id ;
2120 private String created_at ;
21+
22+ /**
23+ * Representation of GitHub Event API Event Type.
24+ *
25+ * This is not the same as the values used for hook methods such as
26+ * {@link GHRepository#createHook(String, Map, Collection, boolean)}.
27+ *
28+ * @see <a href="https://docs.github.com/en/developers/webhooks-and-events/github-event-types">GitHub event
29+ * types</a>
30+ */
2231 private String type ;
2332
2433 // these are all shallow objects
@@ -41,13 +50,45 @@ public static class GHEventRepository {
4150 private String name ; // owner/repo
4251 }
4352
53+ static final Map <String , GHEvent > mapTypeStringToEvent = createEventMap ();
54+
55+ /**
56+ * Map for GitHub Event API Event Type to GHEvent.
57+ *
58+ * @see <a href="https://docs.github.com/en/developers/webhooks-and-events/github-event-types">GitHub event
59+ * types</a>
60+ */
61+ private static Map <String , GHEvent > createEventMap () {
62+ HashMap <String , GHEvent > map = new HashMap <>();
63+ map .put ("CommitCommentEvent" , GHEvent .COMMIT_COMMENT );
64+ map .put ("CreateEvent" , GHEvent .CREATE );
65+ map .put ("DeleteEvent" , GHEvent .DELETE );
66+ map .put ("ForkEvent" , GHEvent .FORK );
67+ map .put ("GollumEvent" , GHEvent .GOLLUM );
68+ map .put ("IssueCommentEvent" , GHEvent .ISSUE_COMMENT );
69+ map .put ("IssuesEvent" , GHEvent .ISSUES );
70+ map .put ("MemberEvent" , GHEvent .MEMBER );
71+ map .put ("PublicEvent" , GHEvent .PUBLIC );
72+ map .put ("PullRequestEvent" , GHEvent .PULL_REQUEST );
73+ map .put ("PullRequestReviewEvent" , GHEvent .PULL_REQUEST_REVIEW );
74+ map .put ("PullRequestReviewCommentEvent" , GHEvent .PULL_REQUEST_REVIEW_COMMENT );
75+ map .put ("PushEvent" , GHEvent .PUSH );
76+ map .put ("ReleaseEvent" , GHEvent .RELEASE );
77+ map .put ("WatchEvent" , GHEvent .WATCH );
78+ return Collections .unmodifiableMap (map );
79+ }
80+
81+ static GHEvent transformTypeToGHEvent (String type ) {
82+ return mapTypeStringToEvent .getOrDefault (type , GHEvent .UNKNOWN );
83+ }
84+
4485 /**
4586 * Gets type.
4687 *
4788 * @return the type
4889 */
4990 public GHEvent getType () {
50- return GitHubEventType . transformToGHEvent (type );
91+ return transformTypeToGHEvent (type );
5192 }
5293
5394 GHEventInfo wrapUp (GitHub root ) {
0 commit comments