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
a5ec26fb
Commit
a5ec26fb
authored
Jun 10, 2018
by
Greg Messner
Browse files
Added starProject() and unstarProject() (#194).
parent
8a456a46
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/ProjectApi.java
View file @
a5ec26fb
...
@@ -2097,4 +2097,34 @@ public class ProjectApi extends AbstractApi implements Constants {
...
@@ -2097,4 +2097,34 @@ public class ProjectApi extends AbstractApi implements Constants {
public
Pager
<
Project
>
getForks
(
Integer
projectId
,
int
itemsPerPage
)
throws
GitLabApiException
{
public
Pager
<
Project
>
getForks
(
Integer
projectId
,
int
itemsPerPage
)
throws
GitLabApiException
{
return
new
Pager
<
Project
>(
this
,
Project
.
class
,
itemsPerPage
,
null
,
"projects"
,
projectId
,
"forks"
);
return
new
Pager
<
Project
>(
this
,
Project
.
class
,
itemsPerPage
,
null
,
"projects"
,
projectId
,
"forks"
);
}
}
/**
* Star a project.
*
* POST /projects/:id/star
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @return a Project instance with the new project info
* @throws GitLabApiException if any exception occurs
*/
public
Project
starProject
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
Response
.
Status
expectedStatus
=
(
isApiVersion
(
ApiVersion
.
V3
)
?
Response
.
Status
.
OK
:
Response
.
Status
.
CREATED
);
Response
response
=
post
(
expectedStatus
,
(
Form
)
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"star"
);
return
(
response
.
readEntity
(
Project
.
class
));
}
/**
* Unstar a project.
*
* POST /projects/:id/unstar
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @return a Project instance with the new project info
* @throws GitLabApiException if any exception occurs
*/
public
Project
unstarProject
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
Response
.
Status
expectedStatus
=
(
isApiVersion
(
ApiVersion
.
V3
)
?
Response
.
Status
.
OK
:
Response
.
Status
.
CREATED
);
Response
response
=
post
(
expectedStatus
,
(
Form
)
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"unstar"
);
return
(
response
.
readEntity
(
Project
.
class
));
}
}
}
\ No newline at end of file
src/test/java/org/gitlab4j/api/TestProjectApi.java
View file @
a5ec26fb
...
@@ -495,4 +495,24 @@ public class TestProjectApi {
...
@@ -495,4 +495,24 @@ public class TestProjectApi {
assertFalse
(
optional
.
isPresent
());
assertFalse
(
optional
.
isPresent
());
assertEquals
(
Response
.
Status
.
NOT_FOUND
.
getStatusCode
(),
GitLabApi
.
getOptionalException
(
optional
).
getHttpStatus
());
assertEquals
(
Response
.
Status
.
NOT_FOUND
.
getStatusCode
(),
GitLabApi
.
getOptionalException
(
optional
).
getHttpStatus
());
}
}
@Test
public
void
testStarAndUnstarProject
()
throws
GitLabApiException
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
assertNotNull
(
project
);
try
{
gitLabApi
.
getProjectApi
().
unstarProject
(
project
);
}
catch
(
Exception
ignore
)
{
}
Project
starredProject
=
gitLabApi
.
getProjectApi
().
starProject
(
project
);
assertNotNull
(
starredProject
);
assertEquals
(
1
,
(
int
)
starredProject
.
getStarCount
());
Project
unstarredProject
=
gitLabApi
.
getProjectApi
().
unstarProject
(
project
);
assertNotNull
(
unstarredProject
);
assertEquals
(
0
,
(
int
)
unstarredProject
.
getStarCount
());
}
}
}
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