Skip to content

feat: add ProjectPackageFile #1373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/gl_objects/packages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,25 @@ Filter the results by ``package_type`` or ``package_name`` ::

packages = group.packages.list(package_type='pypi')


Project Package Files
=====================

Reference
---------

* v4 API:

+ :class:`gitlab.v4.objects.ProjectPackageFile`
+ :class:`gitlab.v4.objects.ProjectPackageFileManager`
+ :attr:`gitlab.v4.objects.ProjectPackage.package_files`

* GitLab API: https://docs.gitlab.com/ee/api/packages.html#list-package-files

Examples
--------

List package files for package in project::

package = project.packages.get(1)
package_files = package.package_files.list()
70 changes: 69 additions & 1 deletion gitlab/tests/objects/test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest
import responses

from gitlab.v4.objects import GroupPackage, ProjectPackage
from gitlab.v4.objects import GroupPackage, ProjectPackage, ProjectPackageFile


package_content = {
Expand Down Expand Up @@ -54,6 +54,51 @@
],
}

package_file_content = [
{
"id": 25,
"package_id": 1,
"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",
"pipelines": [
{
"id": 123,
"status": "pending",
"ref": "new-pipeline",
"sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
"web_url": "https://example.com/foo/bar/pipelines/47",
"created_at": "2016-08-11T11:28:34.085Z",
"updated_at": "2016-08-11T11:32:35.169Z",
"user": {
"name": "Administrator",
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
},
}
],
},
{
"id": 26,
"package_id": 1,
"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": 1,
"created_at": "2018-11-07T15:26:00.556Z",
"file_name": "maven-metadata.xml",
"size": 767,
"file_md5": "6dfd0cce1203145a927fef5e3a1c650c",
"file_sha1": "d25932de56052d320a8ac156f745ece73f6a8cd2",
},
]


@pytest.fixture
def resp_list_packages():
Expand Down Expand Up @@ -94,6 +139,21 @@ def resp_delete_package(no_content):
yield rsps


@pytest.fixture
def resp_list_package_files():
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.GET,
url=re.compile(
r"http://localhost/api/v4/projects/1/packages/1/package_files"
),
json=package_file_content,
content_type="application/json",
status=200,
)
yield rsps


def test_list_project_packages(project, resp_list_packages):
packages = project.packages.list()
assert isinstance(packages, list)
Expand All @@ -117,3 +177,11 @@ def test_get_project_package(project, resp_get_package):
def test_delete_project_package(project, resp_delete_package):
package = project.packages.get(1, lazy=True)
package.delete()


def test_list_project_package_files(project, resp_list_package_files):
package = project.packages.get(1, lazy=True)
package_files = package.package_files.list()
assert isinstance(package_files, list)
assert isinstance(package_files[0], ProjectPackageFile)
assert package_files[0].id == 25
15 changes: 13 additions & 2 deletions gitlab/v4/objects/packages.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from gitlab.base import RESTManager, RESTObject
from gitlab.mixins import DeleteMixin, GetMixin, ListMixin, ObjectDeleteMixin


__all__ = [
"GroupPackage",
"GroupPackageManager",
"ProjectPackage",
"ProjectPackageManager",
"ProjectPackageFile",
"ProjectPackageFileManager",
]


Expand All @@ -28,7 +29,7 @@ class GroupPackageManager(ListMixin, RESTManager):


class ProjectPackage(ObjectDeleteMixin, RESTObject):
pass
_managers = (("package_files", "ProjectPackageFileManager"),)


class ProjectPackageManager(ListMixin, GetMixin, DeleteMixin, RESTManager):
Expand All @@ -41,3 +42,13 @@ class ProjectPackageManager(ListMixin, GetMixin, DeleteMixin, RESTManager):
"package_type",
"package_name",
)


class ProjectPackageFile(RESTObject):
pass


class ProjectPackageFileManager(ListMixin, RESTManager):
_path = "/projects/%(project_id)s/packages/%(package_id)s/package_files"
_obj_cls = ProjectPackageFile
_from_parent_attrs = {"project_id": "project_id", "package_id": "id"}