Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
13afdbb0
Commit
13afdbb0
authored
Aug 12, 2017
by
Greg Messner
Browse files
Mods to support EventsApi (#60).
parent
c50c87cd
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/Constants.java
View file @
13afdbb0
...
...
@@ -45,12 +45,12 @@ public interface Constants {
@JsonValue
public
String
toValue
()
{
return
(
name
().
toLowerCase
(
));
return
(
enumHelper
.
toString
(
this
));
}
@Override
public
String
toString
()
{
return
(
name
().
toLowerCase
(
));
return
(
enumHelper
.
toString
(
this
));
}
}
...
...
@@ -67,12 +67,12 @@ public interface Constants {
@JsonValue
public
String
toValue
()
{
return
(
name
().
toLowerCase
(
));
return
(
enumHelper
.
toString
(
this
));
}
@Override
public
String
toString
()
{
return
(
name
().
toLowerCase
(
));
return
(
enumHelper
.
toString
(
this
));
}
}
...
...
@@ -90,12 +90,12 @@ public interface Constants {
@JsonValue
public
String
toValue
()
{
return
(
name
().
toLowerCase
(
));
return
(
enumHelper
.
toString
(
this
));
}
@Override
public
String
toString
()
{
return
(
name
().
toLowerCase
(
));
return
(
enumHelper
.
toString
(
this
));
}
}
...
...
@@ -113,12 +113,12 @@ public interface Constants {
@JsonValue
public
String
toValue
()
{
return
(
name
().
toLowerCase
(
));
return
(
enumHelper
.
toString
(
this
));
}
@Override
public
String
toString
()
{
return
(
name
().
toLowerCase
(
));
return
(
enumHelper
.
toString
(
this
));
}
}
...
...
@@ -133,10 +133,14 @@ public interface Constants {
public
static
JobScope
forValue
(
String
value
)
{
return
enumHelper
.
forValue
(
value
);
}
@JsonValue
public
String
toValue
()
{
return
(
name
().
toLowerCase
());
}
public
String
toValue
()
{
return
(
enumHelper
.
toString
(
this
));
}
@Override
public
String
toString
()
{
return
(
name
().
toLowerCase
());
}
public
String
toString
()
{
return
(
enumHelper
.
toString
(
this
));
}
}
/** Enum to use for specifying the state of a merge request update. */
...
...
@@ -149,10 +153,61 @@ public interface Constants {
@JsonCreator
public
static
StateEvent
forValue
(
String
value
)
{
return
enumHelper
.
forValue
(
value
);
}
@JsonValue
public
String
toValue
()
{
return
(
name
().
toLowerCase
());
}
public
String
toValue
()
{
return
(
enumHelper
.
toString
(
this
));
}
@Override
public
String
toString
()
{
return
(
name
().
toLowerCase
());
}
public
String
toString
()
{
return
(
enumHelper
.
toString
(
this
));
}
}
/** Enum to use for specifying the event action_type. */
public
enum
ActionType
{
CREATED
,
UPDATED
,
CLOSED
,
REOPENED
,
PUSHED
,
COMMENTED
,
MERGED
,
JOINED
,
LEFT
,
DESTROYED
,
EXPIRED
;
private
static
JacksonJsonEnumHelper
<
ActionType
>
enumHelper
=
new
JacksonJsonEnumHelper
<>(
ActionType
.
class
);
@JsonCreator
public
static
ActionType
forValue
(
String
value
)
{
return
enumHelper
.
forValue
(
value
);
}
@JsonValue
public
String
toValue
()
{
return
(
enumHelper
.
toString
(
this
));
}
@Override
public
String
toString
()
{
return
(
enumHelper
.
toString
(
this
));
}
}
/** Enum to use for specifying the event target_type. */
public
enum
TargetType
{
ISSUE
,
MILESTONE
,
MERGE_REQUEST
,
NOTE
,
PROJECT
,
SNIPPET
,
USER
;
private
static
JacksonJsonEnumHelper
<
TargetType
>
enumHelper
=
new
JacksonJsonEnumHelper
<>(
TargetType
.
class
,
true
);
@JsonCreator
public
static
TargetType
forValue
(
String
value
)
{
return
enumHelper
.
forValue
(
value
);
}
@JsonValue
public
String
toValue
()
{
return
(
enumHelper
.
toString
(
this
));
}
@Override
public
String
toString
()
{
return
(
enumHelper
.
toString
(
this
));
}
}
}
src/main/java/org/gitlab4j/api/GitLabApi.java
View file @
13afdbb0
...
...
@@ -41,6 +41,7 @@ public class GitLabApi {
private
UserApi
userApi
;
private
JobApi
jobApi
;
private
NotesApi
notesApi
;
private
EventsApi
eventsApi
;
private
Session
session
;
...
...
@@ -192,6 +193,7 @@ public class GitLabApi {
repositoryFileApi
=
new
RepositoryFileApi
(
this
);
jobApi
=
new
JobApi
(
this
);
notesApi
=
new
NotesApi
(
this
);
eventsApi
=
new
EventsApi
(
this
);
}
/**
...
...
@@ -401,7 +403,9 @@ public class GitLabApi {
*
* @return the JobsApi instance owned by this GitLabApi instance
*/
public
JobApi
getJobApi
()
{
return
(
jobApi
);
}
public
JobApi
getJobApi
()
{
return
(
jobApi
);
}
/**
* Gets the NotesApi instance owned by this GitLabApi instance. The NotesApi is used
...
...
@@ -413,4 +417,13 @@ public class GitLabApi {
return
(
notesApi
);
}
/**
* Gets the EventsApi instance owned by this GitLabApi instance. The EventsApi is used
* to perform all events related API calls.
*
* @return the EventsApi instance owned by this GitLabApi instance
*/
public
EventsApi
getEventsApi
()
{
return
(
eventsApi
);
}
}
src/main/java/org/gitlab4j/api/models/Event.java
View file @
13afdbb0
...
...
@@ -5,6 +5,8 @@ import javax.xml.bind.annotation.XmlAccessType;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
org.gitlab4j.api.Constants.TargetType
;
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
Event
{
...
...
@@ -17,7 +19,7 @@ public class Event {
private
Integer
projectId
;
private
Integer
targetId
;
private
String
targetTitle
;
private
String
targetType
;
private
TargetType
targetType
;
private
String
title
;
public
String
getActionName
()
{
...
...
@@ -84,11 +86,11 @@ public class Event {
this
.
targetTitle
=
targetTitle
;
}
public
String
getTargetType
()
{
public
TargetType
getTargetType
()
{
return
targetType
;
}
public
void
setTargetType
(
String
targetType
)
{
public
void
setTargetType
(
TargetType
targetType
)
{
this
.
targetType
=
targetType
;
}
...
...
src/main/java/org/gitlab4j/api/utils/JacksonJsonEnumHelper.java
View file @
13afdbb0
...
...
@@ -8,15 +8,41 @@ import com.fasterxml.jackson.annotation.JsonCreator;
public
class
JacksonJsonEnumHelper
<
E
extends
Enum
<
E
>>
{
private
Map
<
String
,
E
>
valuesMap
;
private
Map
<
E
,
String
>
namesMap
;
public
JacksonJsonEnumHelper
(
Class
<
E
>
enumType
)
{
this
(
enumType
,
false
);
}
public
JacksonJsonEnumHelper
(
Class
<
E
>
enumType
,
boolean
firstLetterCapitalized
)
{
valuesMap
=
new
HashMap
<>();
for
(
E
e
:
enumType
.
getEnumConstants
())
valuesMap
.
put
(
e
.
name
().
toLowerCase
(),
e
);
namesMap
=
new
HashMap
<>();
for
(
E
e
:
enumType
.
getEnumConstants
())
{
String
name
=
e
.
name
().
toLowerCase
();
if
(
firstLetterCapitalized
)
{
name
=
name
.
substring
(
0
,
1
).
toUpperCase
()
+
name
.
substring
(
1
);
}
valuesMap
.
put
(
name
,
e
);
namesMap
.
put
(
e
,
name
);
}
}
@JsonCreator
public
E
forValue
(
String
value
)
{
return
valuesMap
.
get
(
value
);
}
/**
* Get the string used by the API for this enum.
*
* @param e the enum value to get the API string for
* @return the string used by the API for this enum
*/
public
String
toString
(
E
e
)
{
return
(
namesMap
.
get
(
e
));
}
}
\ No newline at end of file
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