mirror of
https://github.com/jlengrand/github-api.git
synced 2026-04-04 08:21:23 +00:00
(refactor) Replace complex parsing logic from GHEvent.type to GHEvent with static mapping
[https://github.com/hub4j/github-api/issues/1099]
This commit is contained in:
@@ -2,6 +2,8 @@ package org.kohsuke.github;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Hook event type.
|
||||
*
|
||||
@@ -85,4 +87,50 @@ public enum GHEvent {
|
||||
return "*";
|
||||
return name().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Representation of GitHub Event Type
|
||||
*
|
||||
* @see <a href="https://docs.github.com/en/developers/webhooks-and-events/github-event-types">GitHub event
|
||||
* types</a>
|
||||
*/
|
||||
public enum GitHubEventType {
|
||||
CommitCommentEvent(COMMIT_COMMENT),
|
||||
CreateEvent(CREATE),
|
||||
DeleteEvent(DELETE),
|
||||
ForkEvent(FORK),
|
||||
GollumEvent(GOLLUM),
|
||||
IssueCommentEvent(ISSUE_COMMENT),
|
||||
IssuesEvent(ISSUES),
|
||||
MemberEvent(MEMBER),
|
||||
PublicEvent(PUBLIC),
|
||||
PullRequestEvent(PULL_REQUEST),
|
||||
PullRequestReviewEvent(PULL_REQUEST_REVIEW),
|
||||
PullRequestReviewCommentEvent(PULL_REQUEST_REVIEW_COMMENT),
|
||||
PushEvent(PUSH),
|
||||
ReleaseEvent(RELEASE),
|
||||
WatchEvent(WATCH);
|
||||
|
||||
private final GHEvent event;
|
||||
GitHubEventType(GHEvent event) {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required due to different naming conventions between different GitHub event names for Webhook events and
|
||||
* GitHub events
|
||||
*
|
||||
* @param event
|
||||
* the github event as a string to convert to Event enum
|
||||
* @return GHEvent
|
||||
*/
|
||||
public static GHEvent transformToGHEvent(@Nonnull String event) {
|
||||
try {
|
||||
GitHubEventType gitHubEventType = GitHubEventType.valueOf(event);
|
||||
return gitHubEventType.event;
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user