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
0028d7e7
Unverified
Commit
0028d7e7
authored
Feb 05, 2024
by
ddoleye
Committed by
GitHub
Feb 05, 2024
Browse files
Add NamespaceApi.getNamespace(idOrPath) using /namespaces/:id (#1079)
parent
ce461112
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/AbstractApi.java
View file @
0028d7e7
...
...
@@ -13,6 +13,7 @@ import javax.ws.rs.core.StreamingOutput;
import
org.gitlab4j.api.GitLabApi.ApiVersion
;
import
org.gitlab4j.api.models.Group
;
import
org.gitlab4j.api.models.Label
;
import
org.gitlab4j.api.models.Namespace
;
import
org.gitlab4j.api.models.Project
;
import
org.gitlab4j.api.models.User
;
import
org.gitlab4j.api.utils.UrlEncoder
;
...
...
@@ -169,6 +170,34 @@ public abstract class AbstractApi implements Constants {
}
}
public
Object
getNamespaceIdOrPath
(
Object
obj
)
throws
GitLabApiException
{
if
(
obj
==
null
)
{
throw
(
new
RuntimeException
(
"Cannot determine ID or path from null object"
));
}
else
if
(
obj
instanceof
Long
)
{
return
(
obj
);
}
else
if
(
obj
instanceof
String
)
{
return
(
urlEncode
(((
String
)
obj
).
trim
()));
}
else
if
(
obj
instanceof
Namespace
)
{
Long
id
=
((
Namespace
)
obj
).
getId
();
if
(
id
!=
null
&&
id
.
longValue
()
>
0
)
{
return
(
id
);
}
String
path
=
((
Namespace
)
obj
).
getFullPath
();
if
(
path
!=
null
&&
path
.
trim
().
length
()
>
0
)
{
return
(
urlEncode
(
path
.
trim
()));
}
throw
(
new
RuntimeException
(
"Cannot determine ID or path from provided Namespace instance"
));
}
else
{
throw
(
new
RuntimeException
(
"Cannot determine ID or path from provided "
+
obj
.
getClass
().
getSimpleName
()
+
" instance, must be Long, String, or a Namespace instance"
));
}
}
protected
ApiVersion
getApiVersion
()
{
return
(
gitLabApi
.
getApiVersion
());
}
...
...
src/main/java/org/gitlab4j/api/NamespaceApi.java
View file @
0028d7e7
package
org.gitlab4j.api
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.stream.Stream
;
import
javax.ws.rs.core.GenericType
;
...
...
@@ -130,4 +131,35 @@ public class NamespaceApi extends AbstractApi {
public
Stream
<
Namespace
>
findNamespacesStream
(
String
query
)
throws
GitLabApiException
{
return
(
findNamespaces
(
query
,
getDefaultPerPage
()).
stream
());
}
/**
* Get all details of a namespace.
*
* <pre><code>GitLab Endpoint: GET /namespaces/:id</code></pre>
*
* @param namespaceIdOrPath the namespace ID, path of the namespace, or a Namespace instance holding the namespace ID or path
* @return the Namespace instance for the specified path
* @throws GitLabApiException if any exception occurs
*/
public
Namespace
getNamespace
(
Object
namespaceIdOrPath
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"namespaces"
,
getNamespaceIdOrPath
(
namespaceIdOrPath
));
return
(
response
.
readEntity
(
Namespace
.
class
));
}
/**
* Get all details of a namespace as an Optional instance.
*
* <pre><code>GitLab Endpoint: GET /namespaces/:id</code></pre>
*
* @param namespaceIdOrPath the namespace ID, path of the namespace, or a Namespace instance holding the namespace ID or path
* @return the Group for the specified group path as an Optional instance
*/
public
Optional
<
Namespace
>
getOptionalNamespace
(
Object
namespaceIdOrPath
)
{
try
{
return
(
Optional
.
ofNullable
(
getNamespace
(
namespaceIdOrPath
)));
}
catch
(
GitLabApiException
glae
)
{
return
(
GitLabApi
.
createOptionalFromException
(
glae
));
}
}
}
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