Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
0c31bd43
Commit
0c31bd43
authored
6 years ago
by
Greg Messner
Browse files
Options
Download
Email Patches
Plain Diff
Fixed issue unmarhalling merge_request system hook events (#332).
parent
04a76980
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/main/java/org/gitlab4j/api/systemhooks/MergeRequestSystemHookEvent.java
+7
-10
...gitlab4j/api/systemhooks/MergeRequestSystemHookEvent.java
src/main/java/org/gitlab4j/api/systemhooks/SystemHookEvent.java
+2
-1
...in/java/org/gitlab4j/api/systemhooks/SystemHookEvent.java
src/main/java/org/gitlab4j/api/systemhooks/SystemHookManager.java
+9
-6
.../java/org/gitlab4j/api/systemhooks/SystemHookManager.java
with
18 additions
and
17 deletions
+18
-17
src/main/java/org/gitlab4j/api/systemhooks/MergeRequestSystemHookEvent.java
+
7
-
10
View file @
0c31bd43
...
...
@@ -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
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/org/gitlab4j/api/systemhooks/SystemHookEvent.java
+
2
-
1
View file @
0c31bd43
...
...
@@ -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
{
...
...
This diff is collapsed.
Click to expand it.
src/main/java/org/gitlab4j/api/systemhooks/SystemHookManager.java
+
9
-
6
View file @
0c31bd43
...
...
@@ -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"
);
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets