From ca5e68835acab2f398ef97329ab61268c381acbe Mon Sep 17 00:00:00 2001 From: Lukas Eipert Date: Wed, 17 Apr 2024 13:26:58 +0200 Subject: [PATCH 1/3] Add support to list child pipelines in project Currently we do not support retrieving child pipelines of a project via the API or GraphQL. This can lead to an odd situation, that if the parent pipeline was deleted, one cannot iterate through the child pipelines. We already return child pipelines if the (undocumented) `iids` parameter is set. By following similar logic, we can just show child pipelines if the user explicitly filters `source=parent_pipeline` which used to always return an empty list. Changelog: added --- app/finders/ci/pipelines_finder.rb | 9 ++++++++- doc/api/pipelines.md | 5 +++-- spec/finders/ci/pipelines_finder_spec.rb | 8 ++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/finders/ci/pipelines_finder.rb b/app/finders/ci/pipelines_finder.rb index b3aefe6fa448b4..03f2b4b163f261 100644 --- a/app/finders/ci/pipelines_finder.rb +++ b/app/finders/ci/pipelines_finder.rb @@ -26,7 +26,7 @@ def execute return Ci::Pipeline.none unless Ability.allowed?(current_user, :read_pipeline, project) items = pipelines - items = items.no_child unless params[:iids].present? + items = drop_child_pipelines(items) items = by_iids(items) items = by_scope(items) items = by_status(items) @@ -63,6 +63,13 @@ def tags project.repository.tag_names end + def drop_child_pipelines(items) + return items if params[:iids].present? + return items if params[:source] == 'parent_pipeline' + + items.no_child + end + def by_iids(items) if params[:iids].present? items.for_iid(params[:iids]) diff --git a/doc/api/pipelines.md b/doc/api/pipelines.md index b4766aa7b9fa5b..04d5d30677de70 100644 --- a/doc/api/pipelines.md +++ b/doc/api/pipelines.md @@ -19,14 +19,15 @@ Read more on [pagination](rest/index.md#pagination). ## List project pipelines +> - Support for child pipelines if `source` is set to `parent_pipeline` in GitLab 17.0. > - `iid` in response [introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/342223) in GitLab 14.6. > - `name` in response [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/115310) in GitLab 15.11 [with a flag](../administration/feature_flags.md) named `pipeline_name_in_api`. Disabled by default. > - `name` in request [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/115310) in 15.11 [with a flag](../administration/feature_flags.md) named `pipeline_name_search`. Disabled by default. > - `name` in response [generally available](https://gitlab.com/gitlab-org/gitlab/-/issues/398131) in GitLab 16.3. Feature flag `pipeline_name_in_api` removed. > - `name` in request [generally available](https://gitlab.com/gitlab-org/gitlab/-/issues/385864) in GitLab 16.9. Feature flag `pipeline_name_search` removed. -List pipelines in a project. Child pipelines are not included in the results, -but you can [get child pipeline](pipelines.md#get-a-single-pipeline) individually. +List pipelines in a project. Child pipelines are not included in the results per default, +but you can get child pipelines of a project if you set `source` to `parent_pipeline`. ```plaintext GET /projects/:id/pipelines diff --git a/spec/finders/ci/pipelines_finder_spec.rb b/spec/finders/ci/pipelines_finder_spec.rb index 7a94c8191f5547..bb3b603976b9a7 100644 --- a/spec/finders/ci/pipelines_finder_spec.rb +++ b/spec/finders/ci/pipelines_finder_spec.rb @@ -75,6 +75,14 @@ it 'filters out child pipelines and shows only the parents by default' do is_expected.to eq([parent_pipeline]) end + + context 'when source is parent_pipeline' do + let(:params) { { source: 'parent_pipeline' } } + + it 'does not filter out child pipelines' do + is_expected.to eq([child_pipeline]) + end + end end Ci::HasStatus::AVAILABLE_STATUSES.each do |target| -- GitLab From 987a81d1179b84e9f27ffb6fe4f29bf1379cf887 Mon Sep 17 00:00:00 2001 From: Lukas 'ai-pi' Eipert Date: Thu, 18 Apr 2024 12:37:28 +0000 Subject: [PATCH 2/3] Update docs --- doc/api/pipelines.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/api/pipelines.md b/doc/api/pipelines.md index 04d5d30677de70..93b4a07773db89 100644 --- a/doc/api/pipelines.md +++ b/doc/api/pipelines.md @@ -19,15 +19,17 @@ Read more on [pagination](rest/index.md#pagination). ## List project pipelines -> - Support for child pipelines if `source` is set to `parent_pipeline` in GitLab 17.0. > - `iid` in response [introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/342223) in GitLab 14.6. > - `name` in response [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/115310) in GitLab 15.11 [with a flag](../administration/feature_flags.md) named `pipeline_name_in_api`. Disabled by default. > - `name` in request [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/115310) in 15.11 [with a flag](../administration/feature_flags.md) named `pipeline_name_search`. Disabled by default. > - `name` in response [generally available](https://gitlab.com/gitlab-org/gitlab/-/issues/398131) in GitLab 16.3. Feature flag `pipeline_name_in_api` removed. > - `name` in request [generally available](https://gitlab.com/gitlab-org/gitlab/-/issues/385864) in GitLab 16.9. Feature flag `pipeline_name_search` removed. +> - Support for returning child pipelines with `source` set to `parent_pipeline` [introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/39503) in GitLab 17.0. -List pipelines in a project. Child pipelines are not included in the results per default, -but you can get child pipelines of a project if you set `source` to `parent_pipeline`. +List pipelines in a project. + +By default, [child pipelines](../ci/pipelines/downstream_pipelines.md#parent-child-pipelines) +are not included in the results. To return child pipelines, set `source` to `parent_pipeline`. ```plaintext GET /projects/:id/pipelines -- GitLab From cd60b04d6e1f9a2f967c28157ab0253151156330 Mon Sep 17 00:00:00 2001 From: Lukas Eipert Date: Thu, 18 Apr 2024 14:39:56 +0200 Subject: [PATCH 3/3] Rename pipeline prefilter --- app/finders/ci/pipelines_finder.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/finders/ci/pipelines_finder.rb b/app/finders/ci/pipelines_finder.rb index 03f2b4b163f261..a17103cd48a281 100644 --- a/app/finders/ci/pipelines_finder.rb +++ b/app/finders/ci/pipelines_finder.rb @@ -25,8 +25,7 @@ def initialize(project, current_user, params = {}) def execute return Ci::Pipeline.none unless Ability.allowed?(current_user, :read_pipeline, project) - items = pipelines - items = drop_child_pipelines(items) + items = prefiltered_pipelines items = by_iids(items) items = by_scope(items) items = by_status(items) @@ -63,11 +62,11 @@ def tags project.repository.tag_names end - def drop_child_pipelines(items) - return items if params[:iids].present? - return items if params[:source] == 'parent_pipeline' + def prefiltered_pipelines + return pipelines if params[:iids].present? + return pipelines if params[:source] == 'parent_pipeline' - items.no_child + pipelines.no_child end def by_iids(items) -- GitLab