summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Wittig <max.wittig@siemens.com>2020-10-08 18:16:49 +0200
committerGitHub <noreply@github.com>2020-10-08 18:16:49 +0200
commitc303dabc720a2f840e7a45644647de59c7e0e7bf (patch)
tree916ec7414a283a25edfd95074bd78c1402dc2e2e
parentbe0afdd3e0a7d94327fc075fcc0786b95731279d (diff)
parentf37ebf5fd792c8e8a973443a1df386fa77d1248f (diff)
downloadgitlab-c303dabc720a2f840e7a45644647de59c7e0e7bf.tar.gz
Merge pull request #1203 from intostern/feat/bridge
Added support for pipeline bridges
-rw-r--r--docs/gl_objects/pipelines_and_jobs.rst24
-rw-r--r--gitlab/tests/objects/test_bridges.py111
-rw-r--r--gitlab/v4/objects/__init__.py12
3 files changed, 147 insertions, 0 deletions
diff --git a/docs/gl_objects/pipelines_and_jobs.rst b/docs/gl_objects/pipelines_and_jobs.rst
index cc4db53..0a3ddb1 100644
--- a/docs/gl_objects/pipelines_and_jobs.rst
+++ b/docs/gl_objects/pipelines_and_jobs.rst
@@ -302,3 +302,27 @@ Play (trigger) a job::
Erase a job (artifacts and trace)::
build_or_job.erase()
+
+
+Pipeline bridges
+=====================
+
+Get a list of bridge jobs (including child pipelines) for a pipeline.
+
+Reference
+---------
+
+* v4 API
+
+ + :class:`gitlab.v4.objects.ProjectPipelineBridge`
+ + :class:`gitlab.v4.objects.ProjectPipelineBridgeManager`
+ + :attr:`gitlab.v4.objects.ProjectPipeline.bridges`
+
+* GitLab API: https://docs.gitlab.com/ee/api/jobs.html#list-pipeline-bridges
+
+Examples
+--------
+
+List bridges for the pipeline::
+
+ bridges = pipeline.bridges.list()
diff --git a/gitlab/tests/objects/test_bridges.py b/gitlab/tests/objects/test_bridges.py
new file mode 100644
index 0000000..ea8c634
--- /dev/null
+++ b/gitlab/tests/objects/test_bridges.py
@@ -0,0 +1,111 @@
+"""
+GitLab API: https://docs.gitlab.com/ee/api/jobs.html#list-pipeline-bridges
+"""
+import re
+
+import pytest
+import responses
+
+from gitlab.v4.objects import Project, ProjectPipelineBridge
+
+
+@pytest.fixture
+def resp_list_bridges():
+ export_bridges_content = {
+ "commit": {
+ "author_email": "admin@example.com",
+ "author_name": "Administrator",
+ "created_at": "2015-12-24T16:51:14.000+01:00",
+ "id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
+ "message": "Test the CI integration.",
+ "short_id": "0ff3ae19",
+ "title": "Test the CI integration.",
+ },
+ "allow_failure": False,
+ "created_at": "2015-12-24T15:51:21.802Z",
+ "started_at": "2015-12-24T17:54:27.722Z",
+ "finished_at": "2015-12-24T17:58:27.895Z",
+ "duration": 240,
+ "id": 7,
+ "name": "teaspoon",
+ "pipeline": {
+ "id": 6,
+ "ref": "master",
+ "sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
+ "status": "pending",
+ "created_at": "2015-12-24T15:50:16.123Z",
+ "updated_at": "2015-12-24T18:00:44.432Z",
+ "web_url": "https://example.com/foo/bar/pipelines/6",
+ },
+ "ref": "master",
+ "stage": "test",
+ "status": "pending",
+ "tag": False,
+ "web_url": "https://example.com/foo/bar/-/jobs/7",
+ "user": {
+ "id": 1,
+ "name": "Administrator",
+ "username": "root",
+ "state": "active",
+ "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
+ "web_url": "http://gitlab.dev/root",
+ "created_at": "2015-12-21T13:14:24.077Z",
+ "public_email": "",
+ "skype": "",
+ "linkedin": "",
+ "twitter": "",
+ "website_url": "",
+ "organization": "",
+ },
+ "downstream_pipeline": {
+ "id": 5,
+ "sha": "f62a4b2fb89754372a346f24659212eb8da13601",
+ "ref": "master",
+ "status": "pending",
+ "created_at": "2015-12-24T17:54:27.722Z",
+ "updated_at": "2015-12-24T17:58:27.896Z",
+ "web_url": "https://example.com/diaspora/diaspora-client/pipelines/5",
+ },
+ }
+
+ export_pipelines_content = [
+ {
+ "id": 6,
+ "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",
+ },
+ ]
+
+ with responses.RequestsMock() as rsps:
+ rsps.add(
+ method=responses.GET,
+ url="http://localhost/api/v4/projects/1/pipelines/6/bridges",
+ json=[export_bridges_content],
+ content_type="application/json",
+ status=200,
+ )
+ rsps.add(
+ method=responses.GET,
+ url="http://localhost/api/v4/projects/1/pipelines",
+ json=export_pipelines_content,
+ content_type="application/json",
+ status=200,
+ )
+ yield rsps
+
+
+def test_list_projects_pipelines_bridges(project, resp_list_bridges):
+ pipeline = project.pipelines.list()[0]
+ bridges = pipeline.bridges.list()
+
+ assert isinstance(bridges, list)
+ assert isinstance(bridges[0], ProjectPipelineBridge)
+ assert bridges[0].downstream_pipeline["id"] == 5
+ assert (
+ bridges[0].downstream_pipeline["sha"]
+ == "f62a4b2fb89754372a346f24659212eb8da13601"
+ )
diff --git a/gitlab/v4/objects/__init__.py b/gitlab/v4/objects/__init__.py
index 317e67a..ca1f583 100644
--- a/gitlab/v4/objects/__init__.py
+++ b/gitlab/v4/objects/__init__.py
@@ -3778,6 +3778,17 @@ class ProjectPipelineJobManager(ListMixin, RESTManager):
_list_filters = ("scope",)
+class ProjectPipelineBridge(RESTObject):
+ pass
+
+
+class ProjectPipelineBridgeManager(ListMixin, RESTManager):
+ _path = "/projects/%(project_id)s/pipelines/%(pipeline_id)s/bridges"
+ _obj_cls = ProjectPipelineBridge
+ _from_parent_attrs = {"project_id": "project_id", "pipeline_id": "id"}
+ _list_filters = ("scope",)
+
+
class ProjectPipelineVariable(RESTObject):
_id_attr = "key"
@@ -3791,6 +3802,7 @@ class ProjectPipelineVariableManager(ListMixin, RESTManager):
class ProjectPipeline(RESTObject, RefreshMixin, ObjectDeleteMixin):
_managers = (
("jobs", "ProjectPipelineJobManager"),
+ ("bridges", "ProjectPipelineBridgeManager"),
("variables", "ProjectPipelineVariableManager"),
)