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
a6fb4a7d
Unverified
Commit
a6fb4a7d
authored
Sep 05, 2023
by
Дмитрий
Committed by
GitHub
Sep 05, 2023
Browse files
Add MetatdataApi (#1025)
Fixes #992
parent
2d9a588f
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/GitLabApi.java
View file @
a6fb4a7d
...
@@ -99,6 +99,7 @@ public class GitLabApi implements AutoCloseable {
...
@@ -99,6 +99,7 @@ public class GitLabApi implements AutoCloseable {
private
UserApi
userApi
;
private
UserApi
userApi
;
private
WikisApi
wikisApi
;
private
WikisApi
wikisApi
;
private
KeysApi
keysApi
;
private
KeysApi
keysApi
;
private
MetadataApi
metadataApi
;
/**
/**
* Get the GitLab4J shared Logger instance.
* Get the GitLab4J shared Logger instance.
...
@@ -1463,7 +1464,7 @@ public class GitLabApi implements AutoCloseable {
...
@@ -1463,7 +1464,7 @@ public class GitLabApi implements AutoCloseable {
return
releaseLinksApi
;
return
releaseLinksApi
;
}
}
/**
/**
* Gets the ReleasesApi instance owned by this GitLabApi instance. The ReleasesApi is used
* Gets the ReleasesApi instance owned by this GitLabApi instance. The ReleasesApi is used
* to perform all release related API calls.
* to perform all release related API calls.
...
@@ -1739,6 +1740,21 @@ public class GitLabApi implements AutoCloseable {
...
@@ -1739,6 +1740,21 @@ public class GitLabApi implements AutoCloseable {
return
keysApi
;
return
keysApi
;
}
}
/**
* Gets the MetadataApi instance owned by this GitlabApi instance. The MetadataApi is used to
* retrieve metadata information for this GitLab instance
*
* @return the MetadataApi instance owned by this GitlabApi instance
*/
public
MetadataApi
getMetadataApi
()
{
synchronized
(
this
)
{
if
(
metadataApi
==
null
)
{
metadataApi
=
new
MetadataApi
(
this
);
}
}
return
metadataApi
;
}
/**
/**
* Create and return an Optional instance associated with a GitLabApiException.
* Create and return an Optional instance associated with a GitLabApiException.
...
...
src/main/java/org/gitlab4j/api/MetadataApi.java
0 → 100644
View file @
a6fb4a7d
package
org.gitlab4j.api
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.Response.Status
;
import
org.gitlab4j.api.models.Metadata
;
/**
* This class implements the client side API for the Gitlab metadata call.
*
* @see <a href="https://https://docs.gitlab.com/ee/api/metadata.html">Metadata API at Gitlab</a>
*/
public
class
MetadataApi
extends
AbstractApi
{
public
MetadataApi
(
GitLabApi
gitLabApi
)
{
super
(
gitLabApi
);
}
/**
* Get Gitlab metadata
*
* <pre><code>Gitlab Endpoint: GET /metadata</code></pre>
*
* @return Gitlab metadata
* @throws GitLabApiException if any exception occurs
*/
public
Metadata
getMetadata
()
throws
GitLabApiException
{
Response
response
=
get
(
Status
.
OK
,
null
,
"metadata"
);
return
(
response
.
readEntity
(
Metadata
.
class
));
}
}
src/main/java/org/gitlab4j/api/models/Metadata.java
0 → 100644
View file @
a6fb4a7d
package
org.gitlab4j.api.models
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
org.gitlab4j.api.utils.JacksonJson
;
public
class
Metadata
{
private
String
version
;
private
String
revision
;
private
Kas
kas
;
private
Boolean
enterprise
;
public
String
getVersion
()
{
return
version
;
}
public
void
setVersion
(
String
version
)
{
this
.
version
=
version
;
}
public
String
getRevision
()
{
return
revision
;
}
public
void
setRevision
(
String
revision
)
{
this
.
revision
=
revision
;
}
public
Kas
getKas
()
{
return
kas
;
}
public
void
setKas
(
Kas
kas
)
{
this
.
kas
=
kas
;
}
public
Boolean
getEnterprise
()
{
return
enterprise
;
}
public
void
setEnterprise
(
Boolean
enterprise
)
{
this
.
enterprise
=
enterprise
;
}
@Override
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
}
private
static
class
Kas
{
private
Boolean
enabled
;
@JsonProperty
(
"externalUrl"
)
private
String
externalUrl
;
private
String
version
;
public
Boolean
getEnabled
()
{
return
enabled
;
}
public
void
setEnabled
(
Boolean
enabled
)
{
this
.
enabled
=
enabled
;
}
public
String
getExternalUrl
()
{
return
externalUrl
;
}
public
void
setExternalUrl
(
String
externalUrl
)
{
this
.
externalUrl
=
externalUrl
;
}
public
String
getVersion
()
{
return
version
;
}
public
void
setVersion
(
String
version
)
{
this
.
version
=
version
;
}
@Override
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
}
}
}
src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
View file @
a6fb4a7d
...
@@ -87,6 +87,7 @@ import org.gitlab4j.api.models.Member;
...
@@ -87,6 +87,7 @@ import org.gitlab4j.api.models.Member;
import
org.gitlab4j.api.models.MergeRequest
;
import
org.gitlab4j.api.models.MergeRequest
;
import
org.gitlab4j.api.models.MergeRequestDiff
;
import
org.gitlab4j.api.models.MergeRequestDiff
;
import
org.gitlab4j.api.models.MergeRequestVersion
;
import
org.gitlab4j.api.models.MergeRequestVersion
;
import
org.gitlab4j.api.models.Metadata
;
import
org.gitlab4j.api.models.Milestone
;
import
org.gitlab4j.api.models.Milestone
;
import
org.gitlab4j.api.models.Note
;
import
org.gitlab4j.api.models.Note
;
import
org.gitlab4j.api.models.NotificationSettings
;
import
org.gitlab4j.api.models.NotificationSettings
;
...
@@ -790,4 +791,10 @@ public class TestGitLabApiBeans {
...
@@ -790,4 +791,10 @@ public class TestGitLabApiBeans {
ProjectAccessToken
token
=
unmarshalResource
(
ProjectAccessToken
.
class
,
"project-access-token.json"
);
ProjectAccessToken
token
=
unmarshalResource
(
ProjectAccessToken
.
class
,
"project-access-token.json"
);
assertTrue
(
compareJson
(
token
,
"project-access-token.json"
));
assertTrue
(
compareJson
(
token
,
"project-access-token.json"
));
}
}
@Test
public
void
testMetadata
()
throws
Exception
{
Metadata
metadata
=
unmarshalResource
(
Metadata
.
class
,
"metadata.json"
);
assertTrue
(
compareJson
(
metadata
,
"metadata.json"
));
}
}
}
src/test/java/org/gitlab4j/api/TestMetadataApi.java
0 → 100644
View file @
a6fb4a7d
package
org.gitlab4j.api
;
import
static
org
.
junit
.
jupiter
.
api
.
Assumptions
.
assumeTrue
;
import
org.gitlab4j.api.models.Metadata
;
import
org.gitlab4j.api.models.Project
;
import
org.gitlab4j.api.models.User
;
import
org.junit.jupiter.api.BeforeAll
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Disabled
;
import
org.junit.jupiter.api.Tag
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
@Tag
(
"integration"
)
@ExtendWith
(
SetupIntegrationTestExtension
.
class
)
@Disabled
(
"Required Gitlab version not less then 15.6"
)
public
class
TestMetadataApi
extends
AbstractIntegrationTest
{
private
static
GitLabApi
gitLabApi
;
private
static
Project
testProject
;
private
static
User
currentUser
;
public
TestMetadataApi
()
{
super
();
}
@BeforeAll
public
static
void
setup
()
{
gitLabApi
=
baseTestSetup
();
testProject
=
getTestProject
();
currentUser
=
getCurrentUser
();
}
@BeforeEach
public
void
beforeMethod
()
{
assumeTrue
(
gitLabApi
!=
null
);
}
@Test
public
void
testGetMetadata
()
throws
GitLabApiException
{
Metadata
metadata
=
gitLabApi
.
getMetadataApi
().
getMetadata
();
System
.
out
.
println
(
"METADATA +\n"
+
metadata
);
}
}
src/test/resources/org/gitlab4j/api/metadata.json
0 → 100644
View file @
a6fb4a7d
{
"version"
:
"15.11.13"
,
"revision"
:
"cc3748fcd2d"
,
"kas"
:
{
"enabled"
:
true
,
"externalUrl"
:
"ws://820bd8a8b4f6/-/kubernetes-agent/"
,
"version"
:
"v15.11.0"
},
"enterprise"
:
false
}
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