Commit 3759246c authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'enable-pipeline-source-filter' into 'master'

[RUN AS-IF-FOSS] [RUN ALL RSPEC] Allow pipelines to be filtered by source

See merge request gitlab-org/gitlab!68918
parents afa96a9e d63a3173
......@@ -39,7 +39,7 @@ export default {
return this.value.map((i) => i.type);
},
tokens() {
const tokens = [
return [
{
type: this.$options.userType,
icon: 'user',
......@@ -77,20 +77,15 @@ export default {
token: PipelineStatusToken,
operators: OPERATOR_IS_ONLY,
},
];
if (gon.features.pipelineSourceFilter) {
tokens.push({
{
type: this.$options.sourceType,
icon: 'trigger-source',
title: s__('Pipeline|Source'),
unique: true,
token: PipelineSourceToken,
operators: OPERATOR_IS_ONLY,
});
}
return tokens;
},
];
},
parsedParams() {
return map(this.params, (val, key) => ({
......
......@@ -14,10 +14,6 @@ class Projects::PipelinesController < Projects::ApplicationController
before_action :authorize_update_pipeline!, only: [:retry, :cancel]
before_action :ensure_pipeline, only: [:show, :downloadable_artifacts]
before_action do
push_frontend_feature_flag(:pipeline_source_filter, project, type: :development, default_enabled: :yaml)
end
# Will be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/225596
before_action :redirect_for_legacy_scope_filter, only: [:index], if: -> { request.format.html? }
......@@ -297,10 +293,7 @@ class Projects::PipelinesController < Projects::ApplicationController
end
def index_params
permitted_params = [:scope, :username, :ref, :status]
permitted_params << :source if Feature.enabled?(:pipeline_source_filter, project, default_enabled: :yaml)
params.permit(*permitted_params)
params.permit(:scope, :username, :ref, :status, :source)
end
def enable_code_quality_walkthrough_experiment
......
......@@ -29,8 +29,7 @@ module Ci
items = by_username(items)
items = by_yaml_errors(items)
items = by_updated_at(items)
items = by_source(items) if Feature.enabled?(:pipeline_source_filter, project, default_enabled: :yaml)
items = by_source(items)
sort_items(items)
end
......
---
name: pipeline_source_filter
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67846
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/338347
milestone: '14.2'
type: development
group: group::pipeline execution
default_enabled: false
......@@ -32,6 +32,7 @@ GET /projects/:id/pipelines
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](index.md#namespaced-path-encoding) owned by the authenticated user |
| `scope` | string | no | The scope of pipelines, one of: `running`, `pending`, `finished`, `branches`, `tags` |
| `status` | string | no | The status of pipelines, one of: `created`, `waiting_for_resource`, `preparing`, `pending`, `running`, `success`, `failed`, `canceled`, `skipped`, `manual`, `scheduled` |
| `source` | string | no | In [GitLab 14.3 and later](https://gitlab.com/gitlab-org/gitlab/-/issues/325439), how the pipeline was triggered, one of: `push`, `web`, `trigger`, `schedule`, `api`, `external`, `pipeline`, `chat`, `webide`, `merge_request_event`, `external_pull_request_event`, `parent_pipeline`, `ondemand_dast_scan`, or `ondemand_dast_validation`. |
| `ref` | string | no | The ref of pipelines |
| `sha` | string | no | The SHA of pipelines |
| `yaml_errors`| boolean | no | Returns pipelines with invalid configurations |
......@@ -55,6 +56,7 @@ Example of response
"iid": 12,
"project_id": 1,
"status": "pending",
"soure": "push",
"ref": "new-pipeline",
"sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
"web_url": "https://example.com/foo/bar/pipelines/47",
......@@ -66,6 +68,7 @@ Example of response
"iid": 13,
"project_id": 1,
"status": "pending",
"soure": "web",
"ref": "new-pipeline",
"sha": "eb94b618fb5865b26e80fdd8ae531b7a63ad851a",
"web_url": "https://example.com/foo/bar/pipelines/48",
......
......@@ -122,6 +122,7 @@ you can filter the pipeline list by:
- Branch name
- Status ([GitLab 13.1 and later](https://gitlab.com/gitlab-org/gitlab/-/issues/217617))
- Tag ([GitLab 13.1 and later](https://gitlab.com/gitlab-org/gitlab/-/issues/217617))
- Source ([GitLab 14.3 and later](https://gitlab.com/gitlab-org/gitlab/-/issues/338347))
[Starting in GitLab 14.2](https://gitlab.com/gitlab-org/gitlab/-/issues/26621), you can change the
pipeline column to display the pipeline ID or the pipeline IID.
......
......@@ -4,11 +4,9 @@ module API
module Entities
module Ci
class PipelineBasic < Grape::Entity
expose :id, :project_id, :sha, :ref, :status
expose :id, :project_id, :sha, :ref, :status, :source
expose :created_at, :updated_at
expose :source, if: ->(pipeline, options) { ::Feature.enabled?(:pipeline_source_filter, options[:project], default_enabled: :yaml) }
expose :web_url do |pipeline, _options|
Gitlab::Routing.url_helpers.project_pipeline_url(pipeline.project, pipeline)
end
......
......@@ -258,20 +258,8 @@ RSpec.describe Ci::PipelinesFinder do
let!(:push_pipeline) { create(:ci_pipeline, project: project, source: 'push') }
let!(:api_pipeline) { create(:ci_pipeline, project: project, source: 'api') }
context 'when `pipeline_source_filter` feature flag is disabled' do
before do
stub_feature_flags(pipeline_source_filter: false)
end
it 'returns all the pipelines' do
is_expected.to contain_exactly(web_pipeline, push_pipeline, api_pipeline)
end
end
context 'when `pipeline_source_filter` feature flag is enabled' do
it 'returns only the matched pipeline' do
is_expected.to eq([web_pipeline])
end
it 'returns only the matched pipeline' do
is_expected.to eq([web_pipeline])
end
end
......
......@@ -33,8 +33,6 @@ describe('Pipelines filtered search', () => {
};
beforeEach(() => {
window.gon = { features: { pipelineSourceFilter: true } };
mock = new MockAdapter(axios);
jest.spyOn(Api, 'projectUsers').mockResolvedValue(users);
......
......@@ -105,8 +105,6 @@ describe('Pipelines', () => {
});
beforeEach(() => {
window.gon = { features: { pipelineSourceFilter: true } };
mock = new MockAdapter(axios);
jest.spyOn(window.history, 'pushState');
......
......@@ -37,24 +37,10 @@ RSpec.describe API::Ci::Pipelines do
end
describe 'keys in the response' do
context 'when `pipeline_source_filter` feature flag is disabled' do
before do
stub_feature_flags(pipeline_source_filter: false)
end
it 'does not includes pipeline source' do
get api("/projects/#{project.id}/pipelines", user)
expect(json_response.first.keys).to contain_exactly(*%w[id project_id sha ref status web_url created_at updated_at])
end
end
it 'includes pipeline source' do
get api("/projects/#{project.id}/pipelines", user)
context 'when `pipeline_source_filter` feature flag is disabled' do
it 'includes pipeline source' do
get api("/projects/#{project.id}/pipelines", user)
expect(json_response.first.keys).to contain_exactly(*%w[id project_id sha ref status web_url created_at updated_at source])
end
expect(json_response.first.keys).to contain_exactly(*%w[id project_id sha ref status web_url created_at updated_at source])
end
end
......@@ -323,37 +309,20 @@ RSpec.describe API::Ci::Pipelines do
create(:ci_pipeline, project: project, source: :api)
end
context 'when `pipeline_source_filter` feature flag is disabled' do
before do
stub_feature_flags(pipeline_source_filter: false)
end
it 'returns all pipelines' do
get api("/projects/#{project.id}/pipelines", user), params: { source: 'web' }
it 'returns matched pipelines' do
get api("/projects/#{project.id}/pipelines", user), params: { source: 'web' }
expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers
expect(json_response).not_to be_empty
expect(json_response.length).to be >= 3
end
expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers
expect(json_response).not_to be_empty
json_response.each { |r| expect(r['source']).to eq('web') }
end
context 'when `pipeline_source_filter` feature flag is enabled' do
it 'returns matched pipelines' do
get api("/projects/#{project.id}/pipelines", user), params: { source: 'web' }
expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers
expect(json_response).not_to be_empty
json_response.each { |r| expect(r['source']).to eq('web') }
end
context 'when source is invalid' do
it 'returns bad_request' do
get api("/projects/#{project.id}/pipelines", user), params: { source: 'invalid-source' }
context 'when source is invalid' do
it 'returns bad_request' do
get api("/projects/#{project.id}/pipelines", user), params: { source: 'invalid-source' }
expect(response).to have_gitlab_http_status(:bad_request)
end
expect(response).to have_gitlab_http_status(:bad_request)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment