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
b2a4fc3c
Commit
b2a4fc3c
authored
Jul 05, 2017
by
jsimomaa
Committed by
Greg Messner
Jul 05, 2017
Browse files
Initial implementation of NotesApi for fetching notes of an issue
parent
7d0a4a89
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/GitLabApi.java
View file @
b2a4fc3c
...
...
@@ -37,6 +37,7 @@ public class GitLabApi {
private
ServicesApi
servicesApi
;
private
SessionApi
sessoinApi
;
private
UserApi
userApi
;
private
NotesApi
notesApi
;
private
Session
session
;
...
...
@@ -186,6 +187,7 @@ public class GitLabApi {
sessoinApi
=
new
SessionApi
(
this
);
userApi
=
new
UserApi
(
this
);
repositoryFileApi
=
new
RepositoryFileApi
(
this
);
notesApi
=
new
NotesApi
(
this
);
}
/**
...
...
@@ -368,4 +370,14 @@ public class GitLabApi {
public
UserApi
getUserApi
()
{
return
(
userApi
);
}
/**
* Gets the NotesApi instance owned by this GitLabApi instance. The NotesApi is used
* to perform all notes related API calls.
*
* @return the NotesApi instance owned by this GitLabApi instance
*/
public
NotesApi
getNotesApi
()
{
return
(
notesApi
);
}
}
src/main/java/org/gitlab4j/api/NotesApi.java
0 → 100644
View file @
b2a4fc3c
package
org.gitlab4j.api
;
import
java.util.List
;
import
javax.ws.rs.core.GenericType
;
import
javax.ws.rs.core.Response
;
import
org.gitlab4j.api.models.Note
;
public
class
NotesApi
extends
AbstractApi
{
public
NotesApi
(
GitLabApi
gitLabApi
)
{
super
(
gitLabApi
);
}
/**
* Get a list of issues's notes. Only returns the first page
*
* GET /projects/:id/issues/:issue_iid/notes
*
* @param projectId the project ID to get the issues for
* @param issueIid the issue ID to get the notes for
* @return a list of issues's notes
* @throws GitLabApiException if any exception occurs
*/
public
List
<
Note
>
getNotes
(
Integer
projectId
,
Integer
issueIid
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
getDefaultPerPageParam
(),
"projects"
,
projectId
,
"issues"
,
issueIid
,
"notes"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Note
>>()
{}));
}
/**
* Get a list of project's issues using the specified page and per page settings.
*
* GET /projects/:id/issues/:issue_iid/notes
*
* @param projectId the project ID to get the issues for
* @param issueIid the issue IID to get the notes for
* @param page the page to get
* @param perPage the number of notes per page
* @return the list of notes in the specified range
* @throws GitLabApiException if any exception occurs
*/
public
List
<
Note
>
getIssues
(
Integer
projectId
,
Integer
issueIid
,
int
page
,
int
perPage
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
getPageQueryParams
(
page
,
perPage
),
"projects"
,
projectId
,
"issues"
,
issueIid
,
"notes"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Note
>>()
{}));
}
/**
* Get a Pager of issues's notes.
*
* GET /projects/:id/issues/:issue_iid/notes
*
* @param projectId the project ID to get the issues for
* @param issueIid the issue IID to get the notes for
* @param itemsPerPage the number of notes per page
* @return the list of issues in the specified range
* @throws GitLabApiException if any exception occurs
*/
public
Pager
<
Note
>
getNotes
(
Integer
projectId
,
Integer
issueIid
,
int
itemsPerPage
)
throws
GitLabApiException
{
return
(
new
Pager
<
Note
>(
this
,
Note
.
class
,
itemsPerPage
,
null
,
"projects"
,
projectId
,
"issues"
,
issueIid
,
"notes"
));
}
}
src/test/java/org/gitlab4j/api/TestNotesApi.java
0 → 100644
View file @
b2a4fc3c
package
org.gitlab4j.api
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assume
.
assumeTrue
;
import
java.util.List
;
import
org.gitlab4j.api.GitLabApi.ApiVersion
;
import
org.gitlab4j.api.models.Issue
;
import
org.gitlab4j.api.models.Note
;
import
org.gitlab4j.api.models.Project
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
org.junit.FixMethodOrder
;
import
org.junit.Test
;
import
org.junit.runners.MethodSorters
;
/**
* In order for these tests to run you must set the following properties in test-gitlab4j.properties
*
* TEST_NAMESPACE
* TEST_PROJECT_NAME
* TEST_HOST_URL
* TEST_PRIVATE_TOKEN
*
* If any of the above are NULL, all tests in this class will be skipped.
*/
@FixMethodOrder
(
MethodSorters
.
NAME_ASCENDING
)
public
class
TestNotesApi
{
// The following needs to be set to your test repository
private
static
final
String
TEST_PROJECT_NAME
;
private
static
final
String
TEST_NAMESPACE
;
private
static
final
String
TEST_HOST_URL
;
private
static
final
String
TEST_PRIVATE_TOKEN
;
static
{
TEST_NAMESPACE
=
TestUtils
.
getProperty
(
"TEST_NAMESPACE"
);
TEST_PROJECT_NAME
=
TestUtils
.
getProperty
(
"TEST_PROJECT_NAME"
);
TEST_HOST_URL
=
TestUtils
.
getProperty
(
"TEST_HOST_URL"
);
TEST_PRIVATE_TOKEN
=
TestUtils
.
getProperty
(
"TEST_PRIVATE_TOKEN"
);
}
private
static
GitLabApi
gitLabApi
;
public
TestNotesApi
()
{
super
();
}
@BeforeClass
public
static
void
setup
()
{
String
problems
=
""
;
if
(
TEST_NAMESPACE
==
null
||
TEST_NAMESPACE
.
trim
().
length
()
==
0
)
{
problems
+=
"TEST_NAMESPACE cannot be empty\n"
;
}
if
(
TEST_PROJECT_NAME
==
null
||
TEST_PROJECT_NAME
.
trim
().
length
()
==
0
)
{
problems
+=
"TEST_PROJECT_NAME cannot be empty\n"
;
}
if
(
TEST_HOST_URL
==
null
||
TEST_HOST_URL
.
trim
().
length
()
==
0
)
{
problems
+=
"TEST_HOST_URL cannot be empty\n"
;
}
if
(
TEST_PRIVATE_TOKEN
==
null
||
TEST_PRIVATE_TOKEN
.
trim
().
length
()
==
0
)
{
problems
+=
"TEST_PRIVATE_TOKEN cannot be empty\n"
;
}
if
(
problems
.
isEmpty
())
{
gitLabApi
=
new
GitLabApi
(
ApiVersion
.
V4
,
TEST_HOST_URL
,
TEST_PRIVATE_TOKEN
);
}
else
{
System
.
err
.
print
(
problems
);
}
}
@Before
public
void
beforeMethod
()
{
assumeTrue
(
gitLabApi
!=
null
);
}
@Test
public
void
testNotes
()
throws
GitLabApiException
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
assertNotNull
(
project
);
for
(
Issue
issue
:
gitLabApi
.
getProjectApi
().
getIssues
(
project
.
getId
()))
{
List
<
Note
>
notes
=
gitLabApi
.
getNotesApi
().
getNotes
(
project
.
getId
(),
issue
.
getIid
());
assertNotNull
(
notes
);
// This requires some issues in the project
// assertTrue(0 < notes.size());
}
}
}
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