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
79b831c7
Commit
79b831c7
authored
Aug 13, 2021
by
t0m4uk1991
Browse files
Add ability to read resource state events for Issues
parent
3d327e39
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/GitLabApi.java
View file @
79b831c7
...
@@ -85,6 +85,7 @@ public class GitLabApi implements AutoCloseable {
...
@@ -85,6 +85,7 @@ public class GitLabApi implements AutoCloseable {
private
RepositoryApi
repositoryApi
;
private
RepositoryApi
repositoryApi
;
private
RepositoryFileApi
repositoryFileApi
;
private
RepositoryFileApi
repositoryFileApi
;
private
ResourceLabelEventsApi
resourceLabelEventsApi
;
private
ResourceLabelEventsApi
resourceLabelEventsApi
;
private
ResourceStateEventsApi
resourceStateEventsApi
;
private
RunnersApi
runnersApi
;
private
RunnersApi
runnersApi
;
private
SearchApi
searchApi
;
private
SearchApi
searchApi
;
private
ServicesApi
servicesApi
;
private
ServicesApi
servicesApi
;
...
@@ -1488,6 +1489,25 @@ public class GitLabApi implements AutoCloseable {
...
@@ -1488,6 +1489,25 @@ public class GitLabApi implements AutoCloseable {
return
(
resourceLabelEventsApi
);
return
(
resourceLabelEventsApi
);
}
}
/**
* Gets the ResourceStateEventsApi instance owned by this GitLabApi instance. The ResourceStateEventsApi
* is used to perform all Resource State Events related API calls.
*
* @return the ResourceStateEventsApi instance owned by this GitLabApi instance
*/
public
ResourceStateEventsApi
getResourceStateEventsApi
()
{
if
(
resourceStateEventsApi
==
null
)
{
synchronized
(
this
)
{
if
(
resourceStateEventsApi
==
null
)
{
resourceStateEventsApi
=
new
ResourceStateEventsApi
(
this
);
}
}
}
return
(
resourceStateEventsApi
);
}
/**
/**
* Gets the RunnersApi instance owned by this GitLabApi instance. The RunnersApi is used
* Gets the RunnersApi instance owned by this GitLabApi instance. The RunnersApi is used
* to perform all Runner related API calls.
* to perform all Runner related API calls.
...
...
src/main/java/org/gitlab4j/api/ResourceStateEventsApi.java
0 → 100644
View file @
79b831c7
package
org.gitlab4j.api
;
import
org.gitlab4j.api.models.IssueEvent
;
import
org.gitlab4j.api.models.LabelEvent
;
import
javax.ws.rs.core.Response
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.stream.Stream
;
/**
* This class provides an entry point to all the GitLab Resource state events API
* @see <a href="https://docs.gitlab.com/ce/api/resource_state_events.html">Resource state events API at GitLab</a>
*/
public
class
ResourceStateEventsApi
extends
AbstractApi
{
public
ResourceStateEventsApi
(
GitLabApi
gitLabApi
)
{
super
(
gitLabApi
);
}
/**
* Gets a list of all state events for a single issue.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/issues/:issue_iid/resource_state_events</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param issueIid the IID of the issue
* @return a List of IssueEvent for the specified issue
* @throws GitLabApiException if any exception occurs
*/
public
List
<
IssueEvent
>
getIssueStateEvents
(
Object
projectIdOrPath
,
Integer
issueIid
)
throws
GitLabApiException
{
return
(
getIssueStateEvents
(
projectIdOrPath
,
issueIid
,
getDefaultPerPage
()).
all
());
}
/**
* Gets a Pager of all state events for a single issue.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/issues/:issue_iid/resource_state_events</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param issueIid the IID of the issue
* @param itemsPerPage the number of LabelEvent instances that will be fetched per page
* @return the Pager of IssueEvent instances for the specified issue IID
* @throws GitLabApiException if any exception occurs
*/
public
Pager
<
IssueEvent
>
getIssueStateEvents
(
Object
projectIdOrPath
,
Integer
issueIid
,
int
itemsPerPage
)
throws
GitLabApiException
{
return
(
new
Pager
<
IssueEvent
>(
this
,
IssueEvent
.
class
,
itemsPerPage
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"issues"
,
issueIid
,
"resource_state_events"
));
}
/**
* Gets a Stream of all state events for a single issue.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/issues/:issue_iid/resource_state_events</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param issueIid the IID of the issue
* @return a Stream of IssueEvent for the specified issue
* @throws GitLabApiException if any exception occurs
*/
public
Stream
<
IssueEvent
>
getIssueStateEventsStream
(
Object
projectIdOrPath
,
Integer
issueIid
)
throws
GitLabApiException
{
return
(
getIssueStateEvents
(
projectIdOrPath
,
issueIid
,
getDefaultPerPage
()).
stream
());
}
}
src/main/java/org/gitlab4j/api/models/IssueEvent.java
0 → 100644
View file @
79b831c7
package
org.gitlab4j.api.models
;
import
com.fasterxml.jackson.annotation.JsonCreator
;
import
com.fasterxml.jackson.annotation.JsonValue
;
import
org.gitlab4j.api.utils.JacksonJson
;
import
org.gitlab4j.api.utils.JacksonJsonEnumHelper
;
public
class
IssueEvent
{
/** Enum to use for specifying the state events resource type. */
public
enum
ResourceType
{
ISSUE
;
private
static
JacksonJsonEnumHelper
<
ResourceType
>
enumHelper
=
new
JacksonJsonEnumHelper
<>(
ResourceType
.
class
,
true
,
true
);
@JsonCreator
public
static
ResourceType
forValue
(
String
value
)
{
return
enumHelper
.
forValue
(
value
);
}
@JsonValue
public
String
toValue
()
{
return
(
enumHelper
.
toString
(
this
));
}
@Override
public
String
toString
()
{
return
(
enumHelper
.
toString
(
this
));
}
}
private
int
id
;
private
User
user
;
private
String
createdAt
;
private
ResourceType
resourceType
;
private
int
resourceId
;
private
String
state
;
public
int
getId
()
{
return
id
;
}
public
void
setId
(
int
id
)
{
this
.
id
=
id
;
}
public
User
getUser
()
{
return
user
;
}
public
void
setUser
(
User
user
)
{
this
.
user
=
user
;
}
public
String
getCreatedAt
()
{
return
createdAt
;
}
public
void
setCreatedAt
(
String
createdAt
)
{
this
.
createdAt
=
createdAt
;
}
public
ResourceType
getResourceType
()
{
return
resourceType
;
}
public
void
setResourceType
(
ResourceType
resourceType
)
{
this
.
resourceType
=
resourceType
;
}
public
int
getResourceId
()
{
return
resourceId
;
}
public
void
setResourceId
(
int
resourceId
)
{
this
.
resourceId
=
resourceId
;
}
public
String
getState
()
{
return
state
;
}
public
void
setState
(
String
state
)
{
this
.
state
=
state
;
}
@Override
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
}
}
src/test/java/org/gitlab4j/api/TestIssuesApi.java
View file @
79b831c7
...
@@ -101,7 +101,7 @@ public class TestIssuesApi extends AbstractIntegrationTest {
...
@@ -101,7 +101,7 @@ public class TestIssuesApi extends AbstractIntegrationTest {
deleteAllTestIssues
();
deleteAllTestIssues
();
}
}
p
rivate
static
void
deleteAllTestIssues
()
{
p
ublic
static
void
deleteAllTestIssues
()
{
if
(
gitLabApi
!=
null
)
{
if
(
gitLabApi
!=
null
)
{
try
{
try
{
...
...
src/test/java/org/gitlab4j/api/TestResourceStateEventsApi.java
0 → 100644
View file @
79b831c7
package
org.gitlab4j.api
;
import
org.gitlab4j.api.models.Issue
;
import
org.gitlab4j.api.models.IssueEvent
;
import
org.gitlab4j.api.models.Project
;
import
org.junit.AfterClass
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
org.junit.experimental.categories.Category
;
import
java.util.List
;
import
static
org
.
gitlab4j
.
api
.
TestIssuesApi
.
deleteAllTestIssues
;
import
static
org
.
junit
.
Assert
.*;
@Category
(
IntegrationTest
.
class
)
public
class
TestResourceStateEventsApi
extends
AbstractIntegrationTest
{
private
static
GitLabApi
gitLabApi
;
private
static
Project
testProject
;
private
static
final
String
ISSUE_TITLE
=
"Test Issue Title"
;
private
static
final
String
ISSUE_DESCRIPTION
=
"This is a really nice description, not."
;
public
TestResourceStateEventsApi
()
{
super
();
}
@BeforeClass
public
static
void
setup
()
{
gitLabApi
=
baseTestSetup
();
testProject
=
getTestProject
();
}
@AfterClass
public
static
void
teardown
()
{
deleteAllTestIssues
();
}
@Test
public
void
testGetCloseReopenIssueEvents
()
throws
GitLabApiException
{
Integer
projectId
=
testProject
.
getId
();
Issue
issue
=
gitLabApi
.
getIssuesApi
().
createIssue
(
projectId
,
ISSUE_TITLE
,
ISSUE_DESCRIPTION
);
Issue
closedIssue
=
gitLabApi
.
getIssuesApi
().
closeIssue
(
projectId
,
issue
.
getIid
());
assertEquals
(
closedIssue
.
getState
(),
Constants
.
IssueState
.
CLOSED
);
List
<
IssueEvent
>
issueEvents
=
gitLabApi
.
getResourceStateEventsApi
().
getIssueStateEvents
(
projectId
,
issue
.
getIid
());
assertNotNull
(
issueEvents
);
assertEquals
(
1
,
issueEvents
.
size
());
assertEquals
(
1
,
issueEvents
.
stream
()
.
filter
(
issueEvent
->
issueEvent
.
getState
().
equals
(
Constants
.
IssueState
.
CLOSED
.
toValue
()))
.
count
());
Issue
reopenedIssue
=
gitLabApi
.
getIssuesApi
()
.
updateIssue
(
projectId
,
issue
.
getIid
(),
null
,
null
,
null
,
null
,
null
,
null
,
Constants
.
StateEvent
.
REOPEN
,
null
,
null
);
assertEquals
(
Constants
.
IssueState
.
OPENED
.
toValue
(),
reopenedIssue
.
getState
().
toValue
());
issueEvents
=
gitLabApi
.
getResourceStateEventsApi
().
getIssueStateEvents
(
projectId
,
issue
.
getIid
());
assertNotNull
(
issueEvents
);
assertEquals
(
2
,
issueEvents
.
size
());
assertEquals
(
1
,
issueEvents
.
stream
()
.
filter
(
issueEvent
->
issueEvent
.
getState
().
equals
(
Constants
.
IssueState
.
CLOSED
.
toValue
()))
.
count
());
assertEquals
(
1
,
issueEvents
.
stream
()
.
filter
(
issueEvent
->
issueEvent
.
getState
().
equals
(
Constants
.
IssueState
.
REOPENED
.
toValue
()))
.
count
());
}
}
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