Skip to content

Commit 5b4addd

Browse files
JacobHennernejch
authored andcommitted
feat(api): add ProjectPackagePipeline
Add ProjectPackagePipeline, which is scheduled to be included in GitLab 16.0
1 parent 1e7f257 commit 5b4addd

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

docs/gl_objects/packages.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,31 @@ Delete a package file in a project::
9595
file = package.package_files.list()[0]
9696
file.delete()
9797

98+
Project Package Pipelines
99+
=========================
100+
101+
Reference
102+
---------
103+
104+
* v4 API:
105+
106+
+ :class:`gitlab.v4.objects.ProjectPackagePipeline`
107+
+ :class:`gitlab.v4.objects.ProjectPackagePipelineManager`
108+
+ :attr:`gitlab.v4.objects.ProjectPackage.pipelines`
109+
110+
..
111+
TODO: Not yet published (see https://gitlab.com/gitlab-org/gitlab/-/merge_requests/117539).
112+
Add anchor/fragment once available.
113+
114+
* GitLab API: https://docs.gitlab.com/ee/api/packages.html
115+
116+
Examples
117+
--------
118+
119+
List package pipelines for package in project::
120+
121+
package = project.packages.get(1)
122+
package_pipelines = package.pipelines.list()
98123

99124
Generic Packages
100125
================

gitlab/v4/objects/packages.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
"ProjectPackageManager",
3434
"ProjectPackageFile",
3535
"ProjectPackageFileManager",
36+
"ProjectPackagePipeline",
37+
"ProjectPackagePipelineManager",
3638
]
3739

3840

@@ -188,6 +190,7 @@ class GroupPackageManager(ListMixin, RESTManager):
188190

189191
class ProjectPackage(ObjectDeleteMixin, RESTObject):
190192
package_files: "ProjectPackageFileManager"
193+
pipelines: "ProjectPackagePipelineManager"
191194

192195

193196
class ProjectPackageManager(ListMixin, GetMixin, DeleteMixin, RESTManager):
@@ -215,3 +218,13 @@ class ProjectPackageFileManager(DeleteMixin, ListMixin, RESTManager):
215218
_path = "/projects/{project_id}/packages/{package_id}/package_files"
216219
_obj_cls = ProjectPackageFile
217220
_from_parent_attrs = {"project_id": "project_id", "package_id": "id"}
221+
222+
223+
class ProjectPackagePipeline(RESTObject):
224+
pass
225+
226+
227+
class ProjectPackagePipelineManager(ListMixin, RESTManager):
228+
_path = "/projects/{project_id}/packages/{package_id}/pipelines"
229+
_obj_cls = ProjectPackagePipeline
230+
_from_parent_attrs = {"project_id": "project_id", "package_id": "id"}

tests/unit/objects/test_packages.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
GroupPackage,
1313
ProjectPackage,
1414
ProjectPackageFile,
15+
ProjectPackagePipeline,
1516
)
1617

1718
package_content = {
@@ -104,6 +105,50 @@
104105
},
105106
]
106107

108+
package_pipeline_content = [
109+
{
110+
"id": 123,
111+
"iid": 1,
112+
"project_id": 1,
113+
"sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
114+
"ref": "new-pipeline",
115+
"status": "failed",
116+
"source": "push",
117+
"created_at": "2016-08-11T11:28:34.085Z",
118+
"updated_at": "2016-08-11T11:32:35.169Z",
119+
"web_url": "https://example.com/foo/bar/pipelines/47",
120+
"user": {
121+
"id": 1,
122+
"username": "root",
123+
"name": "Administrator",
124+
"state": "active",
125+
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon",
126+
"web_url": "http://gdk.test:3001/root",
127+
},
128+
},
129+
{
130+
"id": 234,
131+
"iid": 2,
132+
"project_id": 1,
133+
"sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
134+
"ref": "new-pipeline",
135+
"status": "failed",
136+
"source": "push",
137+
"created_at": "2016-08-11T11:28:34.085Z",
138+
"updated_at": "2016-08-11T11:32:35.169Z",
139+
"web_url": "https://example.com/foo/bar/pipelines/58",
140+
"user": {
141+
"id": 1,
142+
"username": "root",
143+
"name": "Administrator",
144+
"state": "active",
145+
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon",
146+
"web_url": "http://gdk.test:3001/root",
147+
},
148+
},
149+
]
150+
151+
107152
package_name = "hello-world"
108153
package_version = "v1.0.0"
109154
file_name = "hello.tar.gz"
@@ -195,6 +240,19 @@ def resp_list_package_files():
195240
yield rsps
196241

197242

243+
@pytest.fixture
244+
def resp_list_package_pipelines():
245+
with responses.RequestsMock() as rsps:
246+
rsps.add(
247+
method=responses.GET,
248+
url=re.compile(r"http://localhost/api/v4/projects/1/packages/1/pipelines"),
249+
json=package_pipeline_content,
250+
content_type="application/json",
251+
status=200,
252+
)
253+
yield rsps
254+
255+
198256
@pytest.fixture
199257
def resp_upload_generic_package(created_content):
200258
with responses.RequestsMock() as rsps:
@@ -269,6 +327,14 @@ def test_delete_project_package_file_from_package_file_object(
269327
package_file.delete()
270328

271329

330+
def test_list_project_package_pipelines(project, resp_list_package_pipelines):
331+
package = project.packages.get(1, lazy=True)
332+
pipelines = package.pipelines.list()
333+
assert isinstance(pipelines, list)
334+
assert isinstance(pipelines[0], ProjectPackagePipeline)
335+
assert pipelines[0].id == 123
336+
337+
272338
def test_upload_generic_package(tmp_path, project, resp_upload_generic_package):
273339
path = tmp_path / file_name
274340
path.write_text(file_content, encoding="utf-8")

0 commit comments

Comments
 (0)