Commit 69493001 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'lm-clean-up-jobs-refactor-ff' into 'master'

Cleans up ci_jobs_finder_refactor ff code

See merge request gitlab-org/gitlab!45558
parents c58b6d1a 7e957445
...@@ -25,11 +25,7 @@ module Ci ...@@ -25,11 +25,7 @@ module Ci
attr_reader :current_user, :pipeline, :project, :params, :type attr_reader :current_user, :pipeline, :project, :params, :type
def init_collection def init_collection
if Feature.enabled?(:ci_jobs_finder_refactor, default_enabled: true) pipeline_jobs || project_jobs || all_jobs
pipeline_jobs || project_jobs || all_jobs
else
project ? project_builds : all_jobs
end
end end
def all_jobs def all_jobs
...@@ -38,12 +34,6 @@ module Ci ...@@ -38,12 +34,6 @@ module Ci
type.all type.all
end end
def project_builds
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :read_build, project)
project.builds.relevant
end
def project_jobs def project_jobs
return unless project return unless project
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :read_build, project) raise Gitlab::Access::AccessDeniedError unless can?(current_user, :read_build, project)
...@@ -59,9 +49,7 @@ module Ci ...@@ -59,9 +49,7 @@ module Ci
end end
def filter_by_scope(builds) def filter_by_scope(builds)
if Feature.enabled?(:ci_jobs_finder_refactor, default_enabled: true) return filter_by_statuses!(params[:scope], builds) if params[:scope].is_a?(Array)
return filter_by_statuses!(params[:scope], builds) if params[:scope].is_a?(Array)
end
case params[:scope] case params[:scope]
when 'pending' when 'pending'
......
---
name: ci_jobs_finder_refactor
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/36622
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/245183
group: group::continuous integration
type: development
default_enabled: true
...@@ -128,15 +128,9 @@ module API ...@@ -128,15 +128,9 @@ module API
pipeline = user_project.all_pipelines.find(params[:pipeline_id]) pipeline = user_project.all_pipelines.find(params[:pipeline_id])
if Feature.enabled?(:ci_jobs_finder_refactor, default_enabled: true) builds = ::Ci::JobsFinder
builds = ::Ci::JobsFinder .new(current_user: current_user, pipeline: pipeline, params: params)
.new(current_user: current_user, pipeline: pipeline, params: params) .execute
.execute
else
authorize!(:read_build, pipeline)
builds = pipeline.builds
builds = filter_builds(builds, params[:scope])
end
builds = builds.with_preloads builds = builds.with_preloads
...@@ -157,16 +151,9 @@ module API ...@@ -157,16 +151,9 @@ module API
pipeline = user_project.all_pipelines.find(params[:pipeline_id]) pipeline = user_project.all_pipelines.find(params[:pipeline_id])
if Feature.enabled?(:ci_jobs_finder_refactor, default_enabled: true) bridges = ::Ci::JobsFinder
bridges = ::Ci::JobsFinder .new(current_user: current_user, pipeline: pipeline, params: params, type: ::Ci::Bridge)
.new(current_user: current_user, pipeline: pipeline, params: params, type: ::Ci::Bridge) .execute
.execute
else
authorize!(:read_pipeline, pipeline)
bridges = pipeline.bridges
bridges = filter_builds(bridges, params[:scope])
end
bridges = bridges.with_preloads bridges = bridges.with_preloads
present paginate(bridges), with: Entities::Ci::Bridge present paginate(bridges), with: Entities::Ci::Bridge
...@@ -246,21 +233,6 @@ module API ...@@ -246,21 +233,6 @@ module API
end end
helpers do helpers do
# NOTE: This method should be removed once the ci_jobs_finder_refactor FF is
# removed. https://gitlab.com/gitlab-org/gitlab/-/issues/245183
# rubocop: disable CodeReuse/ActiveRecord
def filter_builds(builds, scope)
return builds if scope.nil? || scope.empty?
available_statuses = ::CommitStatus::AVAILABLE_STATUSES
unknown = scope - available_statuses
render_api_error!('Scope contains invalid value(s)', 400) unless unknown.empty?
builds.where(status: scope)
end
# rubocop: enable CodeReuse/ActiveRecord
def pipeline def pipeline
strong_memoize(:pipeline) do strong_memoize(:pipeline) do
user_project.all_pipelines.find(params[:pipeline_id]) user_project.all_pipelines.find(params[:pipeline_id])
......
...@@ -36,135 +36,62 @@ RSpec.describe Ci::JobsFinder, '#execute' do ...@@ -36,135 +36,62 @@ RSpec.describe Ci::JobsFinder, '#execute' do
end end
end end
context 'with ci_jobs_finder_refactor ff enabled' do context 'scope is present' do
before do let(:jobs) { [job_1, job_2, job_3] }
stub_feature_flags(ci_jobs_finder_refactor: true)
end where(:scope, :index) do
[
context 'scope is present' do ['pending', 0],
let(:jobs) { [job_1, job_2, job_3] } ['running', 1],
['finished', 2]
where(:scope, :index) do ]
[
['pending', 0],
['running', 1],
['finished', 2]
]
end
with_them do
let(:params) { { scope: scope } }
it { expect(subject).to match_array([jobs[index]]) }
end
end end
context 'scope is an array' do with_them do
let(:jobs) { [job_1, job_2, job_3] } let(:params) { { scope: scope } }
let(:params) {{ scope: ['running'] }}
it 'filters by the job statuses in the scope' do it { expect(subject).to match_array([jobs[index]]) }
expect(subject).to match_array([job_2])
end
end end
end end
context 'with ci_jobs_finder_refactor ff disabled' do context 'scope is an array' do
before do let(:jobs) { [job_1, job_2, job_3] }
stub_feature_flags(ci_jobs_finder_refactor: false) let(:params) {{ scope: ['running'] }}
end
context 'scope is present' do
let(:jobs) { [job_1, job_2, job_3] }
where(:scope, :index) do
[
['pending', 0],
['running', 1],
['finished', 2]
]
end
with_them do it 'filters by the job statuses in the scope' do
let(:params) { { scope: scope } } expect(subject).to match_array([job_2])
it { expect(subject).to match_array([jobs[index]]) }
end
end end
end end
end end
context 'with ci_jobs_finder_refactor ff enabled' do context 'a project is present' do
before do subject { described_class.new(current_user: user, project: project, params: params).execute }
stub_feature_flags(ci_jobs_finder_refactor: true)
end
context 'a project is present' do
subject { described_class.new(current_user: user, project: project, params: params).execute }
context 'user has access to the project' do
before do
project.add_maintainer(user)
end
it 'returns jobs for the specified project' do
expect(subject).to match_array([job_3])
end
end
context 'user has no access to project builds' do context 'user has access to the project' do
before do before do
project.add_guest(user) project.add_maintainer(user)
end
it 'returns no jobs' do
expect(subject).to be_empty
end
end end
context 'without user' do it 'returns jobs for the specified project' do
let(:user) { nil } expect(subject).to match_array([job_3])
it 'returns no jobs' do
expect(subject).to be_empty
end
end end
end end
end
context 'with ci_jobs_finder_refactor ff disabled' do
before do
stub_feature_flags(ci_jobs_finder_refactor: false)
end
context 'a project is present' do
subject { described_class.new(current_user: user, project: project, params: params).execute }
context 'user has access to the project' do context 'user has no access to project builds' do
before do before do
project.add_maintainer(user) project.add_guest(user)
end
it 'returns jobs for the specified project' do
expect(subject).to match_array([job_3])
end
end end
context 'user has no access to project builds' do it 'returns no jobs' do
before do expect(subject).to be_empty
project.add_guest(user)
end
it 'returns no jobs' do
expect(subject).to be_empty
end
end end
end
context 'without user' do context 'without user' do
let(:user) { nil } let(:user) { nil }
it 'returns no jobs' do it 'returns no jobs' do
expect(subject).to be_empty expect(subject).to be_empty
end
end end
end end
end end
......
This diff is collapsed.
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