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 97f0b7b commit 9e9e2c4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
11 changes: 8 additions & 3 deletions src/main/java/org/kohsuke/github/GHApp.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -20,7 +23,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 +117,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, GHEvent.UNKNOWN))
.collect(Collectors.toList());
}

/**
Expand All @@ -126,7 +131,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
10 changes: 7 additions & 3 deletions src/main/java/org/kohsuke/github/GHAppInstallation.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -35,7 +37,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 +252,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, GHEvent.UNKNOWN))
.collect(Collectors.toList());
}

/**
Expand All @@ -262,7 +266,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
4 changes: 2 additions & 2 deletions src/main/java/org/kohsuke/github/GHHook.java
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down Expand Up @@ -43,7 +43,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, GHEvent.UNKNOWN));
}
return s;
}
Expand Down

0 comments on commit 9e9e2c4

Please sign in to comment.