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
7eb08e7f
Commit
7eb08e7f
authored
Jun 06, 2019
by
Philippe Vienne
Committed by
Greg Messner
Jun 06, 2019
Browse files
Add Container Registry API (#368)
* Add Container Registry API regarding #367
parent
1b352baa
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/ContainerRegistryApi.java
0 → 100644
View file @
7eb08e7f
/*
* The MIT License (MIT)
*
* Copyright (c) 2017 Greg Messner <greg@messners.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package
org.gitlab4j.api
;
import
org.gitlab4j.api.models.RegistryRepository
;
import
org.gitlab4j.api.models.RegistryRepositoryTag
;
import
javax.ws.rs.core.GenericType
;
import
javax.ws.rs.core.Response
;
import
java.util.List
;
import
java.util.stream.Stream
;
/**
* <p>This class implements the client side API for the GitLab Container Registry API.
* See <a href="https://docs.gitlab.com/ee/api/container_registry.html">Container Registry API at GitLab</a> for more information.</p>
*/
public
class
ContainerRegistryApi
extends
AbstractApi
{
public
ContainerRegistryApi
(
GitLabApi
gitLabApi
)
{
super
(
gitLabApi
);
}
/**
* Get a list of registry repositories in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/registry/repositories</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return a list of pages in the project's registry repositories
* @throws GitLabApiException if any exception occurs
*/
public
List
<
RegistryRepository
>
getRepositories
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
return
(
getRepositories
(
projectIdOrPath
,
getDefaultPerPage
()).
all
());
}
/**
* Get a list of registry repositories in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/registry/repositories</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param page the page to get
* @param perPage the number of Package instances per page
* @return a list of registry repositories for the specified range
* @throws GitLabApiException if any exception occurs
*/
public
List
<
RegistryRepository
>
getRepositories
(
Object
projectIdOrPath
,
int
page
,
int
perPage
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
getPageQueryParams
(
page
,
perPage
),
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"registry"
,
"repositories"
);
return
response
.
readEntity
(
new
GenericType
<
List
<
RegistryRepository
>>()
{
});
}
/**
* Get a list of registry repositories in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/registry/repositories</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param itemsPerPage the number of Package instances per page
* @return a Pager of registry repositories for the specified range
* @throws GitLabApiException if any exception occurs
*/
public
Pager
<
RegistryRepository
>
getRepositories
(
Object
projectIdOrPath
,
int
itemsPerPage
)
throws
GitLabApiException
{
return
(
new
Pager
<>(
this
,
RegistryRepository
.
class
,
itemsPerPage
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"registry"
,
"repositories"
));
}
/**
* Get a list of registry repositories in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/registry/repositories</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return a Stream of pages in the project's registry repositories
* @throws GitLabApiException if any exception occurs
*/
public
Stream
<
RegistryRepository
>
getRepositoriesStream
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
return
(
getRepositories
(
projectIdOrPath
,
getDefaultPerPage
()).
stream
());
}
/**
* Delete a repository in registry.
* <p>
* This operation is executed asynchronously and might take some time to get executed.
*
* <pre><code>GitLab Endpoint: DELETE /projects/:id/registry/repositories/:repository_id</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param repositoryId the ID of registry repository
* @throws GitLabApiException if any exception occurs
*/
public
void
deleteRepository
(
Object
projectIdOrPath
,
Integer
repositoryId
)
throws
GitLabApiException
{
if
(
repositoryId
==
null
)
{
throw
new
RuntimeException
(
"packageId cannot be null"
);
}
delete
(
Response
.
Status
.
NO_CONTENT
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"registry"
,
"repositories"
,
repositoryId
);
}
/**
* Get a list of tags for given registry repository.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/registry/repositories/:repository_id/tags</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param repositoryId the ID of registry repository
* @return a list of Repository Tags for the specified repository ID
* @throws GitLabApiException if any exception occurs
*/
public
List
<
RegistryRepositoryTag
>
getRepositoryTags
(
Object
projectIdOrPath
,
Integer
repositoryId
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"registry"
,
"repositories"
,
repositoryId
,
"tags"
);
return
response
.
readEntity
(
new
GenericType
<
List
<
RegistryRepositoryTag
>>()
{
});
}
/**
* Get a list of tags for given registry repository.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/registry/repositories/:repository_id/tags</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param repositoryId the ID of registry repository
* @return a list of Repository Tags for the specified repository ID
* @throws GitLabApiException if any exception occurs
*/
public
Stream
<
RegistryRepositoryTag
>
getRepositoryTagsStream
(
Object
projectIdOrPath
,
Integer
repositoryId
)
throws
GitLabApiException
{
return
getRepositoryTags
(
projectIdOrPath
,
repositoryId
).
stream
();
}
/**
* Get details of a registry repository tag.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/registry/repositories/:repository_id/tags/:tag_name</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param repositoryId the ID of registry repository
* @param tagName the name of tag
* @return the Repository Tag for the specified repository ID
* @throws GitLabApiException if any exception occurs
*/
public
RegistryRepositoryTag
getRepositoryTag
(
Object
projectIdOrPath
,
Integer
repositoryId
,
String
tagName
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"registry"
,
"repositories"
,
repositoryId
,
"tags"
,
tagName
);
return
response
.
readEntity
(
new
GenericType
<
RegistryRepositoryTag
>()
{
});
}
/**
* Delete a registry repository tag.
*
* <pre><code>GitLab Endpoint: DELETE /projects/:id/registry/repositories/:repository_id/tags/:tag_name</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param repositoryId the ID of registry repository
* @throws GitLabApiException if any exception occurs
*/
public
void
deleteRepositoryTag
(
Object
projectIdOrPath
,
Integer
repositoryId
,
String
tagName
)
throws
GitLabApiException
{
if
(
repositoryId
==
null
)
{
throw
new
RuntimeException
(
"packageId cannot be null"
);
}
delete
(
Response
.
Status
.
NO_CONTENT
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"registry"
,
"repositories"
,
repositoryId
,
"tags"
,
tagName
);
}
/**
* Delete repository tags in bulk based on given criteria.
*
* <pre><code>GitLab Endpoint: DELETE /projects/:id/registry/repositories/:repository_id/tags</code></pre>
* <p>
* This API call performs the following operations:
* <ol>
* <li>It orders all tags by creation date. The creation date is the time of the manifest creation,
* not the time of tag push.</li>
* <li>It removes only the tags matching the given name_regex.</li>
* <li>It never removes the tag named latest.</li>
* <li>It keeps N latest matching tags (if keep_n is specified).</li>
* <li>It only removes tags that are older than X amount of time (if older_than is specified).</li>
* <li>It schedules the asynchronous job to be executed in the background.</li>
* </ol>
* <p>
* These operations are executed asynchronously and it might take time to get executed. You can run this at most
* once an hour for a given container repository.
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param repositoryId the ID of registry repository
* @param nameRegex The regex of the name to delete. To delete all tags specify <code>.*</code>.
* @param keepN The amount of latest tags of given name to keep.
* @param olderThan Tags to delete that are older than the given time, written in human readable form
* <code>1h</code>, <code>1d</code>, <code>1month</code>.
* @throws GitLabApiException if any exception occurs
*/
@SuppressWarnings
({
"RedundantThrows"
,
"unused"
})
public
void
deleteRepositoryTagBulk
(
Object
projectIdOrPath
,
Integer
repositoryId
,
String
nameRegex
,
Integer
keepN
,
String
olderThan
)
throws
GitLabApiException
{
/*
This function is not implemented because we need the library to support FormData on DELETE requests.
See: https://docs.gitlab.com/ee/api/container_registry.html#delete-repository-tags-in-bulk
*/
throw
new
UnsupportedOperationException
(
"Not implemented yet"
);
}
}
src/main/java/org/gitlab4j/api/GitLabApi.java
View file @
7eb08e7f
...
@@ -56,6 +56,7 @@ public class GitLabApi {
...
@@ -56,6 +56,7 @@ public class GitLabApi {
private
AwardEmojiApi
awardEmojiApi
;
private
AwardEmojiApi
awardEmojiApi
;
private
BoardsApi
boardsApi
;
private
BoardsApi
boardsApi
;
private
CommitsApi
commitsApi
;
private
CommitsApi
commitsApi
;
private
ContainerRegistryApi
containerRegistryApi
;
private
DiscussionsApi
discussionsApi
;
private
DiscussionsApi
discussionsApi
;
private
DeployKeysApi
deployKeysApi
;
private
DeployKeysApi
deployKeysApi
;
private
EpicsApi
epicsApi
;
private
EpicsApi
epicsApi
;
...
@@ -989,6 +990,25 @@ public class GitLabApi {
...
@@ -989,6 +990,25 @@ public class GitLabApi {
return
(
commitsApi
);
return
(
commitsApi
);
}
}
/**
* Gets the ContainerRegistryApi instance owned by this GitLabApi instance. The ContainerRegistryApi is used
* to perform all Docker Registry related API calls.
*
* @return the ContainerRegistryApi instance owned by this GitLabApi instance
*/
public
ContainerRegistryApi
getContainerRegistryApi
()
{
if
(
containerRegistryApi
==
null
)
{
synchronized
(
this
)
{
if
(
containerRegistryApi
==
null
)
{
containerRegistryApi
=
new
ContainerRegistryApi
(
this
);
}
}
}
return
(
containerRegistryApi
);
}
/**
/**
* Gets the DeployKeysApi instance owned by this GitLabApi instance. The DeployKeysApi is used
* Gets the DeployKeysApi instance owned by this GitLabApi instance. The DeployKeysApi is used
* to perform all deploy key related API calls.
* to perform all deploy key related API calls.
...
...
src/main/java/org/gitlab4j/api/models/RegistryRepository.java
0 → 100644
View file @
7eb08e7f
package
org.gitlab4j.api.models
;
import
org.gitlab4j.api.utils.JacksonJson
;
import
java.util.Date
;
public
class
RegistryRepository
{
private
Integer
id
;
private
String
name
;
private
String
path
;
private
String
location
;
private
Date
createdAt
;
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getPath
()
{
return
path
;
}
public
void
setPath
(
String
path
)
{
this
.
path
=
path
;
}
public
String
getLocation
()
{
return
location
;
}
public
void
setLocation
(
String
location
)
{
this
.
location
=
location
;
}
public
Date
getCreatedAt
()
{
return
createdAt
;
}
public
void
setCreatedAt
(
Date
createdAt
)
{
this
.
createdAt
=
createdAt
;
}
@Override
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
}
}
src/main/java/org/gitlab4j/api/models/RegistryRepositoryTag.java
0 → 100644
View file @
7eb08e7f
package
org.gitlab4j.api.models
;
import
org.gitlab4j.api.utils.JacksonJson
;
import
java.util.Date
;
public
class
RegistryRepositoryTag
{
private
String
name
;
private
String
path
;
private
String
location
;
private
String
revision
;
private
String
shortRevision
;
private
String
digest
;
private
Date
createdAt
;
private
Integer
totalSize
;
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getPath
()
{
return
path
;
}
public
void
setPath
(
String
path
)
{
this
.
path
=
path
;
}
public
String
getLocation
()
{
return
location
;
}
public
void
setLocation
(
String
location
)
{
this
.
location
=
location
;
}
public
String
getRevision
()
{
return
revision
;
}
public
void
setRevision
(
String
revision
)
{
this
.
revision
=
revision
;
}
public
String
getShortRevision
()
{
return
shortRevision
;
}
public
void
setShortRevision
(
String
shortRevision
)
{
this
.
shortRevision
=
shortRevision
;
}
public
String
getDigest
()
{
return
digest
;
}
public
void
setDigest
(
String
digest
)
{
this
.
digest
=
digest
;
}
public
Date
getCreatedAt
()
{
return
createdAt
;
}
public
void
setCreatedAt
(
Date
createdAt
)
{
this
.
createdAt
=
createdAt
;
}
public
Integer
getTotalSize
()
{
return
totalSize
;
}
public
void
setTotalSize
(
Integer
totalSize
)
{
this
.
totalSize
=
totalSize
;
}
@Override
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
}
}
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