Skip to content

Commit

Permalink
Store GHEvents as strings so that we properly handle the unknown values
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed May 27, 2021
1 parent 1a56f9d commit a79971e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/main/java/org/kohsuke/github/GHApp.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
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.Locale;
import java.util.Map;
import java.util.stream.Collectors;

import static org.kohsuke.github.internal.Previews.MACHINE_MAN;

Expand All @@ -20,7 +24,7 @@ public class GHApp extends GHObject {
private String description;
private String externalUrl;
private Map<String, String> permissions;
private List<GHEvent> events;
private List<String> events;
private long installationsCount;
private String htmlUrl;

Expand Down Expand Up @@ -114,7 +118,9 @@ public void setExternalUrl(String externalUrl) {
* @return the events
*/
public List<GHEvent> getEvents() {
return events;
return events.stream()
.map(e -> EnumUtils.getEnumOrDefault(GHEvent.class, e.toUpperCase(Locale.ROOT), GHEvent.UNKNOWN))
.collect(Collectors.toList());
}

/**
Expand All @@ -126,7 +132,7 @@ public List<GHEvent> getEvents() {
*/
@Deprecated
public void setEvents(List<GHEvent> events) {
this.events = events;
this.events = events.stream().map(GHEvent::symbol).collect(Collectors.toList());
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/kohsuke/github/GHAppInstallation.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
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.Locale;
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;
Expand Down Expand Up @@ -35,7 +38,7 @@ public class GHAppInstallation extends GHObject {
@JsonProperty("target_type")
private GHTargetType targetType;
private Map<String, GHPermissionType> permissions;
private List<GHEvent> events;
private List<String> events;
@JsonProperty("single_file_name")
private String singleFileName;
@JsonProperty("repository_selection")
Expand Down Expand Up @@ -250,7 +253,9 @@ public void setPermissions(Map<String, GHPermissionType> permissions) {
* @return the events
*/
public List<GHEvent> getEvents() {
return events;
return events.stream()
.map(e -> EnumUtils.getEnumOrDefault(GHEvent.class, e.toUpperCase(Locale.ROOT), GHEvent.UNKNOWN))
.collect(Collectors.toList());
}

/**
Expand All @@ -262,7 +267,7 @@ public List<GHEvent> getEvents() {
*/
@Deprecated
public void setEvents(List<GHEvent> events) {
this.events = events;
this.events = events.stream().map(GHEvent::symbol).collect(Collectors.toList());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/kohsuke/github/GHHook.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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;
Expand Down Expand Up @@ -43,7 +44,7 @@ public EnumSet<GHEvent> 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.toUpperCase(Locale.ROOT), GHEvent.UNKNOWN));
}
return s;
}
Expand Down

0 comments on commit a79971e

Please sign in to comment.