Commit 0c31bd43 authored by Greg Messner's avatar Greg Messner
Browse files

Fixed issue unmarhalling merge_request system hook events (#332).

parent 04a76980
......@@ -2,21 +2,18 @@ package org.gitlab4j.api.systemhooks;
import org.gitlab4j.api.webhook.MergeRequestEvent;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, property="object_kind")
@JsonSubTypes({
@JsonSubTypes.Type(value = MergeRequestSystemHookEvent.class, name = MergeRequestSystemHookEvent.OBJECT_KIND),
})
public class MergeRequestSystemHookEvent extends MergeRequestEvent implements SystemHookEvent {
public static final String X_GITLAB_EVENT = "System Hook";
public static final String MERGE_REQUEST_EVENT = "merge_request";
@Override
public String getObjectKind() {
return (MERGE_REQUEST_EVENT);
}
@JsonIgnore
@Override
public String getEventName() {
return (OBJECT_KIND);
return (MERGE_REQUEST_EVENT);
}
}
......@@ -26,7 +26,8 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
@JsonSubTypes.Type(value = RemoveGroupMemberSystemHookEvent.class, name = GroupMemberSystemHookEvent.GROUP_MEMBER_REMOVED_EVENT),
@JsonSubTypes.Type(value = PushSystemHookEvent.class, name = PushSystemHookEvent.PUSH_EVENT),
@JsonSubTypes.Type(value = TagPushSystemHookEvent.class, name = TagPushSystemHookEvent.TAG_PUSH_EVENT),
@JsonSubTypes.Type(value = RepositorySystemHookEvent.class, name = RepositorySystemHookEvent.REPOSITORY_UPDATE_EVENT)
@JsonSubTypes.Type(value = RepositorySystemHookEvent.class, name = RepositorySystemHookEvent.REPOSITORY_UPDATE_EVENT),
@JsonSubTypes.Type(value = MergeRequestSystemHookEvent.class, name = MergeRequestSystemHookEvent.MERGE_REQUEST_EVENT)
})
public interface SystemHookEvent {
......
......@@ -16,6 +16,7 @@ import org.gitlab4j.api.utils.HttpRequestUtils;
import org.gitlab4j.api.utils.JacksonJson;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* This class provides a handler for processing GitLab System Hook callouts.
......@@ -90,11 +91,14 @@ public class SystemHookManager extends HookManager {
tree = jacksonJson.readTree(reader);
}
if (tree.has("object_kind")) {
// NOTE: This is a hack based on the GitLab documentation showing that the "event_name" property
// is missing from the merge_request system hook event
if (!tree.has("event_name") && tree.has("object_kind")) {
String objectKind = tree.asText("object_kind");
switch (objectKind) {
case MergeRequestSystemHookEvent.OBJECT_KIND:
event = jacksonJson.unmarshal(MergeRequestSystemHookEvent.class, tree);
case MergeRequestSystemHookEvent.MERGE_REQUEST_EVENT:
ObjectNode node = (ObjectNode)tree;
node.put("event_name", MergeRequestSystemHookEvent.MERGE_REQUEST_EVENT);
break;
default:
......@@ -102,11 +106,10 @@ public class SystemHookManager extends HookManager {
LOGGER.warning(message);
throw new GitLabApiException(message);
}
} else {
event = jacksonJson.unmarshal(SystemHookEvent.class, tree);
}
event = jacksonJson.unmarshal(SystemHookEvent.class, tree);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(event.getEventName() + "\n" + jacksonJson.marshal(event) + "\n");
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment