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
4080db20
Commit
4080db20
authored
Mar 19, 2019
by
Greg Messner
Browse files
Initial commit (#317).
parent
2f2d2b45
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/PackagesApi.java
0 → 100644
View file @
4080db20
/*
* 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
java.util.List
;
import
java.util.stream.Stream
;
import
javax.ws.rs.core.GenericType
;
import
javax.ws.rs.core.Response
;
import
org.gitlab4j.api.models.Package
;
import
org.gitlab4j.api.models.PackageFile
;
/**
* <p>This class implements the client side API for the GitLab Packages API.
* See <a href="https://docs.gitlab.com/ee/api/packages.html">Packages API at GitLab</a> for more information.</p>
*
* NOTE: This API is not available in the Community edition of GitLab.
*/
public
class
PackagesApi
extends
AbstractApi
{
public
PackagesApi
(
GitLabApi
gitLabApi
)
{
super
(
gitLabApi
);
}
/**
* Get a list of project packages. Both Maven and NPM packages are included in results.
* When accessed without authentication, only packages of public projects are returned.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/packages</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 packages
* @throws GitLabApiException if any exception occurs
*/
public
List
<
Package
>
getPackages
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
return
(
getPackages
(
projectIdOrPath
,
getDefaultPerPage
()).
all
());
}
/**
* Get a list of project packages for the specified page. Both Maven and NPM packages are included in results.
* When accessed without authentication, only packages of public projects are returned.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/packages</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 project packages for the specified range
* @throws GitLabApiException if any exception occurs
*/
public
List
<
Package
>
getPackages
(
Object
projectIdOrPath
,
int
page
,
int
perPage
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
getPageQueryParams
(
page
,
perPage
),
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"packages"
);
return
response
.
readEntity
(
new
GenericType
<
List
<
Package
>>()
{});
}
/**
* Get a Pager of project packages. Both Maven and NPM packages are included in results.
* When accessed without authentication, only packages of public projects are returned.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/packages</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 project packages for the specified range
* @throws GitLabApiException if any exception occurs
*/
public
Pager
<
Package
>
getPackages
(
Object
projectIdOrPath
,
int
itemsPerPage
)
throws
GitLabApiException
{
return
(
new
Pager
<
Package
>(
this
,
Package
.
class
,
itemsPerPage
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"packages"
));
}
/**
* Get a Stream of project packages. Both Maven and NPM packages are included in results.
* When accessed without authentication, only packages of public projects are returned.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/packages</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 packages
* @throws GitLabApiException if any exception occurs
*/
public
Stream
<
Package
>
getPackagesStream
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
return
(
getPackages
(
projectIdOrPath
,
getDefaultPerPage
()).
stream
());
}
/**
* Get a single project package.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/packages/:package_id</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param packageId the ID of the package to get
* @return a Package instance for the specified package ID
* @throws GitLabApiException if any exception occurs
*/
public
Package
getPackage
(
Object
projectIdOrPath
,
Integer
packageId
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"packages"
,
packageId
);
return
(
response
.
readEntity
(
Package
.
class
));
}
/**
* Get a list of package files of a single package.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/packages/:package_id/package_files</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param packageId the ID of the package to get the package files for
* @return a list of PackageFile instances for the specified package ID
* @throws GitLabApiException if any exception occurs
*/
public
List
<
PackageFile
>
getPackageFiles
(
Object
projectIdOrPath
,
Integer
packageId
)
throws
GitLabApiException
{
return
(
getPackageFiles
(
projectIdOrPath
,
packageId
,
getDefaultPerPage
()).
all
());
}
/**
* Get a list of package files of a single package for the specified page.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/packages/:package_id/package_files</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param packageId the ID of the package to get the package files for
* @param page the page to get
* @param perPage the number of PackageFile instances per page
* @return a list of PackageFile instances for the specified package ID
* @throws GitLabApiException if any exception occurs
*/
public
List
<
PackageFile
>
getPackageFiles
(
Object
projectIdOrPath
,
Integer
packageId
,
int
page
,
int
perPage
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
getPageQueryParams
(
page
,
perPage
),
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"packages"
,
packageId
,
"package_files"
);
return
response
.
readEntity
(
new
GenericType
<
List
<
PackageFile
>>()
{});
}
/**
* Get a Pager of project package files.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/packages/:package_id/package_files</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param packageId the ID of the package to get the package files for
* @param itemsPerPage the number of PackageFile instances per page
* @return a Pager of PackageFile instances for the specified package ID
* @throws GitLabApiException if any exception occurs
*/
public
Pager
<
PackageFile
>
getPackageFiles
(
Object
projectIdOrPath
,
Integer
packageId
,
int
itemsPerPage
)
throws
GitLabApiException
{
return
(
new
Pager
<
PackageFile
>(
this
,
PackageFile
.
class
,
itemsPerPage
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"packages"
,
packageId
,
"package_files"
));
}
/**
* Get a Stream of project package files.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/packages/:package_id/package_files</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param packageId the ID of the package to get the package files for
* @return a Stream of PackageFile instances for the specified package ID
* @throws GitLabApiException if any exception occurs
*/
public
Stream
<
PackageFile
>
getPackagesStream
(
Object
projectIdOrPath
,
Integer
packageId
)
throws
GitLabApiException
{
return
(
getPackageFiles
(
projectIdOrPath
,
packageId
,
getDefaultPerPage
()).
stream
());
}
/**
* Deletes a project package.
*
* <pre><code>GitLab Endpoint: DELETE /projects/:id/packages/:package_id</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param packageId the ID of the package to delete
* @throws GitLabApiException if any exception occurs
*/
public
void
deletePackage
(
Object
projectIdOrPath
,
Integer
packageId
)
throws
GitLabApiException
{
if
(
packageId
==
null
)
{
throw
new
RuntimeException
(
"packageId cannot be null"
);
}
delete
(
Response
.
Status
.
NO_CONTENT
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"packages"
,
packageId
);
}
}
src/main/java/org/gitlab4j/api/models/Package.java
0 → 100644
View file @
4080db20
package
org.gitlab4j.api.models
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
org.gitlab4j.api.utils.JacksonJson
;
@XmlRootElement
public
class
Package
{
private
Integer
id
;
private
String
name
;
private
String
version
;
private
PackageType
packageType
;
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
getVersion
()
{
return
version
;
}
public
void
setVersion
(
String
version
)
{
this
.
version
=
version
;
}
public
PackageType
getPackageType
()
{
return
packageType
;
}
public
void
setPackageType
(
PackageType
packageType
)
{
this
.
packageType
=
packageType
;
}
@Override
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
}
}
\ No newline at end of file
src/main/java/org/gitlab4j/api/models/PackageFile.java
0 → 100644
View file @
4080db20
package
org.gitlab4j.api.models
;
import
java.util.Date
;
import
org.gitlab4j.api.utils.JacksonJson
;
public
class
PackageFile
{
private
Integer
id
;
private
Integer
packageId
;
private
Date
created_at
;
private
String
fileName
;
private
Long
size
;
private
String
fileMd5
;
private
String
fileSha1
;
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
Integer
getPackageId
()
{
return
packageId
;
}
public
void
setPackageId
(
Integer
packageId
)
{
this
.
packageId
=
packageId
;
}
public
Date
getCreated_at
()
{
return
created_at
;
}
public
void
setCreated_at
(
Date
created_at
)
{
this
.
created_at
=
created_at
;
}
public
String
getFileName
()
{
return
fileName
;
}
public
void
setFileName
(
String
fileName
)
{
this
.
fileName
=
fileName
;
}
public
Long
getSize
()
{
return
size
;
}
public
void
setSize
(
Long
size
)
{
this
.
size
=
size
;
}
public
String
getFileMd5
()
{
return
fileMd5
;
}
public
void
setFileMd5
(
String
fileMd5
)
{
this
.
fileMd5
=
fileMd5
;
}
public
String
getFileSha1
()
{
return
fileSha1
;
}
public
void
setFileSha1
(
String
fileSha1
)
{
this
.
fileSha1
=
fileSha1
;
}
@Override
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
}
}
src/main/java/org/gitlab4j/api/models/PackageType.java
0 → 100644
View file @
4080db20
package
org.gitlab4j.api.models
;
import
org.gitlab4j.api.utils.JacksonJsonEnumHelper
;
import
com.fasterxml.jackson.annotation.JsonCreator
;
import
com.fasterxml.jackson.annotation.JsonValue
;
public
enum
PackageType
{
MAVEN
,
NPM
;
private
static
JacksonJsonEnumHelper
<
PackageType
>
enumHelper
=
new
JacksonJsonEnumHelper
<>(
PackageType
.
class
);
@JsonCreator
public
static
PackageType
forValue
(
String
value
)
{
return
enumHelper
.
forValue
(
value
);
}
@JsonValue
public
String
toValue
()
{
return
(
enumHelper
.
toString
(
this
));
}
@Override
public
String
toString
()
{
return
(
enumHelper
.
toString
(
this
));
}
}
\ No newline at end of file
src/test/resources/org/gitlab4j/api/package-files.json
0 → 100644
View file @
4080db20
[
{
"id"
:
25
,
"package_id"
:
4
,
"created_at"
:
"2018-11-07T15:25:52.199Z"
,
"file_name"
:
"my-app-1.5-20181107.152550-1.jar"
,
"size"
:
2421
,
"file_md5"
:
"58e6a45a629910c6ff99145a688971ac"
,
"file_sha1"
:
"ebd193463d3915d7e22219f52740056dfd26cbfe"
},
{
"id"
:
26
,
"package_id"
:
4
,
"created_at"
:
"2018-11-07T15:25:56.776Z"
,
"file_name"
:
"my-app-1.5-20181107.152550-1.pom"
,
"size"
:
1122
,
"file_md5"
:
"d90f11d851e17c5513586b4a7e98f1b2"
,
"file_sha1"
:
"9608d068fe88aff85781811a42f32d97feb440b5"
},
{
"id"
:
27
,
"package_id"
:
4
,
"created_at"
:
"2018-11-07T15:26:00.556Z"
,
"file_name"
:
"maven-metadata.xml"
,
"size"
:
767
,
"file_md5"
:
"6dfd0cce1203145a927fef5e3a1c650c"
,
"file_sha1"
:
"d25932de56052d320a8ac156f745ece73f6a8cd2"
}
]
\ No newline at end of file
src/test/resources/org/gitlab4j/api/packages.json
0 → 100644
View file @
4080db20
[
{
"id"
:
1
,
"name"
:
"com/mycompany/my-app"
,
"version"
:
"1.0-SNAPSHOT"
,
"package_type"
:
"maven"
},
{
"id"
:
2
,
"name"
:
"@foo/bar"
,
"version"
:
"1.0.3"
,
"package_type"
:
"npm"
}
]
\ 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