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
d7c3c76b
Commit
d7c3c76b
authored
May 02, 2020
by
Greg Messner
Browse files
Addd support for getting license and custom attributes (#567)
parent
0a7ad132
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/ProjectApi.java
View file @
d7c3c76b
...
...
@@ -723,6 +723,50 @@ public class ProjectApi extends AbstractApi implements Constants {
}
}
/**
* Get a specific project, which is owned by the authentication user.
*
* <pre><code>GitLab Endpoint: GET /projects/:id</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param includeStatistics include project statistics
* @param includeLicense include project license data
* @param withCustomAttributes include custom attributes in response (admins only)
* @return the specified project
* @throws GitLabApiException if any exception occurs
*/
public
Project
getProject
(
Object
projectIdOrPath
,
Boolean
includeStatistics
,
Boolean
includeLicense
,
Boolean
withCustomAttributes
)
throws
GitLabApiException
{
Form
formData
=
new
GitLabApiForm
()
.
withParam
(
"statistics"
,
includeStatistics
)
.
withParam
(
"license"
,
includeLicense
)
.
withParam
(
"with_custom_attributes"
,
withCustomAttributes
);
Response
response
=
get
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
));
return
(
response
.
readEntity
(
Project
.
class
));
}
/**
* Get an Optional instance with the value for the specific project, which is owned by the authentication user.
*
* <pre><code>GitLab Endpoint: GET /projects/:id</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param includeStatistics include project statistics
* @param includeLicense include project license data
* @param withCustomAttributes include custom attributes in response (admins only)
* @return an Optional instance with the specified project as a value
*/
public
Optional
<
Project
>
getOptionalProject
(
Object
projectIdOrPath
,
Boolean
includeStatistics
,
Boolean
includeLicense
,
Boolean
withCustomAttributes
)
{
try
{
return
(
Optional
.
ofNullable
(
getProject
(
projectIdOrPath
,
includeStatistics
,
includeLicense
,
withCustomAttributes
)));
}
catch
(
GitLabApiException
glae
)
{
return
(
GitLabApi
.
createOptionalFromException
(
glae
));
}
}
/**
* Get a specific project, which is owned by the authentication user.
*
...
...
src/main/java/org/gitlab4j/api/ProjectLicense.java
0 → 100644
View file @
d7c3c76b
package
org.gitlab4j.api
;
import
org.gitlab4j.api.utils.JacksonJson
;
public
class
ProjectLicense
{
private
String
key
;
private
String
name
;
private
String
nickname
;
private
String
htmlUrl
;
private
String
sourceUrl
;
public
String
getKey
()
{
return
key
;
}
public
void
setKey
(
String
key
)
{
this
.
key
=
key
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getNickname
()
{
return
nickname
;
}
public
void
setNickname
(
String
nickname
)
{
this
.
nickname
=
nickname
;
}
public
String
getHtmlUrl
()
{
return
htmlUrl
;
}
public
void
setHtmlUrl
(
String
htmlUrl
)
{
this
.
htmlUrl
=
htmlUrl
;
}
public
String
getSourceUrl
()
{
return
sourceUrl
;
}
public
void
setSourceUrl
(
String
sourceUrl
)
{
this
.
sourceUrl
=
sourceUrl
;
}
@Override
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
}
}
src/main/java/org/gitlab4j/api/models/Project.java
View file @
d7c3c76b
...
...
@@ -4,6 +4,7 @@ package org.gitlab4j.api.models;
import
java.util.Date
;
import
java.util.List
;
import
org.gitlab4j.api.ProjectLicense
;
import
org.gitlab4j.api.utils.JacksonJson
;
import
org.gitlab4j.api.utils.JacksonJsonEnumHelper
;
...
...
@@ -86,6 +87,9 @@ public class Project {
private
Boolean
initializeWithReadme
;
private
Boolean
packagesEnabled
;
private
Boolean
emptyRepo
;
private
String
licenseUrl
;
private
ProjectLicense
license
;
private
List
<
CustomAttribute
>
customAttributes
;
@JsonSerialize
(
using
=
JacksonJson
.
DateOnlySerializer
.
class
)
private
Date
markedForDeletionOn
;
...
...
@@ -659,6 +663,30 @@ public class Project {
this
.
markedForDeletionOn
=
markedForDeletionOn
;
}
public
String
getLicenseUrl
()
{
return
licenseUrl
;
}
public
void
setLicenseUrl
(
String
licenseUrl
)
{
this
.
licenseUrl
=
licenseUrl
;
}
public
ProjectLicense
getLicense
()
{
return
license
;
}
public
void
setLicense
(
ProjectLicense
license
)
{
this
.
license
=
license
;
}
public
List
<
CustomAttribute
>
getCustomAttributes
()
{
return
customAttributes
;
}
public
void
setCustomAttributes
(
List
<
CustomAttribute
>
customAttributes
)
{
this
.
customAttributes
=
customAttributes
;
}
public
static
final
boolean
isValid
(
Project
project
)
{
return
(
project
!=
null
&&
project
.
getId
()
!=
null
);
}
...
...
src/test/resources/org/gitlab4j/api/project.json
View file @
d7c3c76b
...
...
@@ -77,5 +77,14 @@
"lfs_objects_size"
:
2118052893
,
"job_artifacts_size"
:
166537174716
},
"marked_for_deletion_on"
:
"2016-06-17"
"marked_for_deletion_on"
:
"2016-06-17"
,
"license_url"
:
"http://example.com/diaspora/diaspora-client/blob/master/LICENSE"
,
"license"
:
{
"key"
:
"lgpl-3.0"
,
"name"
:
"GNU Lesser General Public License v3.0"
,
"nickname"
:
"GNU LGPLv3"
,
"html_url"
:
"http://choosealicense.com/licenses/lgpl-3.0/"
,
"source_url"
:
"http://www.gnu.org/licenses/lgpl-3.0.txt"
},
"custom_attributes"
:
[]
}
\ 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