From 9e9e2c4073dcb7d2b4699c0deff3df18ff713a48 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Wed, 26 May 2021 19:25:22 +0200 Subject: [PATCH] Store GHEvents as strings so that we properly handle the unknown values --- src/main/java/org/kohsuke/github/GHApp.java | 11 ++++++++--- .../java/org/kohsuke/github/GHAppInstallation.java | 10 +++++++--- src/main/java/org/kohsuke/github/GHHook.java | 4 ++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHApp.java b/src/main/java/org/kohsuke/github/GHApp.java index b2178046d0..eb1f8c35a1 100644 --- a/src/main/java/org/kohsuke/github/GHApp.java +++ b/src/main/java/org/kohsuke/github/GHApp.java @@ -1,9 +1,12 @@ package org.kohsuke.github; +import org.kohsuke.github.internal.EnumUtils; + import java.io.IOException; import java.net.URL; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import static org.kohsuke.github.internal.Previews.MACHINE_MAN; @@ -20,7 +23,7 @@ public class GHApp extends GHObject { private String description; private String externalUrl; private Map permissions; - private List events; + private List events; private long installationsCount; private String htmlUrl; @@ -114,7 +117,9 @@ public void setExternalUrl(String externalUrl) { * @return the events */ public List getEvents() { - return events; + return events.stream() + .map(e -> EnumUtils.getEnumOrDefault(GHEvent.class, e, GHEvent.UNKNOWN)) + .collect(Collectors.toList()); } /** @@ -126,7 +131,7 @@ public List getEvents() { */ @Deprecated public void setEvents(List events) { - this.events = events; + this.events = events.stream().map(GHEvent::symbol).collect(Collectors.toList()); } /** diff --git a/src/main/java/org/kohsuke/github/GHAppInstallation.java b/src/main/java/org/kohsuke/github/GHAppInstallation.java index 7b1797fd5d..ee5c732c25 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallation.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallation.java @@ -1,12 +1,14 @@ package org.kohsuke.github; import com.fasterxml.jackson.annotation.JsonProperty; +import org.kohsuke.github.internal.EnumUtils; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import static org.kohsuke.github.internal.Previews.GAMBIT; import static org.kohsuke.github.internal.Previews.MACHINE_MAN; @@ -35,7 +37,7 @@ public class GHAppInstallation extends GHObject { @JsonProperty("target_type") private GHTargetType targetType; private Map permissions; - private List events; + private List events; @JsonProperty("single_file_name") private String singleFileName; @JsonProperty("repository_selection") @@ -250,7 +252,9 @@ public void setPermissions(Map permissions) { * @return the events */ public List getEvents() { - return events; + return events.stream() + .map(e -> EnumUtils.getEnumOrDefault(GHEvent.class, e, GHEvent.UNKNOWN)) + .collect(Collectors.toList()); } /** @@ -262,7 +266,7 @@ public List getEvents() { */ @Deprecated public void setEvents(List events) { - this.events = events; + this.events = events.stream().map(GHEvent::symbol).collect(Collectors.toList()); } /** diff --git a/src/main/java/org/kohsuke/github/GHHook.java b/src/main/java/org/kohsuke/github/GHHook.java index 35fa7bd1f9..ed4c0b1064 100644 --- a/src/main/java/org/kohsuke/github/GHHook.java +++ b/src/main/java/org/kohsuke/github/GHHook.java @@ -1,13 +1,13 @@ package org.kohsuke.github; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import org.kohsuke.github.internal.EnumUtils; import java.io.IOException; import java.net.URL; import java.util.Collections; import java.util.EnumSet; import java.util.List; -import java.util.Locale; import java.util.Map; /** @@ -43,7 +43,7 @@ public EnumSet getEvents() { if (e.equals("*")) s.add(GHEvent.ALL); else - s.add(Enum.valueOf(GHEvent.class, e.toUpperCase(Locale.ENGLISH))); + s.add(EnumUtils.getEnumOrDefault(GHEvent.class, e, GHEvent.UNKNOWN)); } return s; }