Commit 39704e39 authored by Kamil Trzciński's avatar Kamil Trzciński

Add feature flag

parent c6a7e95a
...@@ -23,7 +23,13 @@ module Ci ...@@ -23,7 +23,13 @@ module Ci
def status def status
strong_memoize(:status) do strong_memoize(:status) do
@jobs.slow_composite_status if Feature.enabled?(:ci_composite_status, default_enabled: true)
Gitlab::Ci::Status::GroupedStatuses
.new(@jobs)
.one[:status]
else
CommitStatus.where(id: @jobs).legacy_status
end
end end
end end
......
...@@ -31,7 +31,6 @@ module Ci ...@@ -31,7 +31,6 @@ module Ci
def status def status
@status ||= statuses.latest.slow_composite_status @status ||= statuses.latest.slow_composite_status
end end
def detailed_status(current_user) def detailed_status(current_user)
......
...@@ -387,9 +387,24 @@ module Ci ...@@ -387,9 +387,24 @@ module Ci
end end
end end
def legacy_stages def legacy_stages_using_sql
# TODO, this needs refactoring, see gitlab-foss#26481. # TODO, this needs refactoring, see gitlab-foss#26481.
stages_query = statuses
.group('stage').select(:stage).order('max(stage_idx)')
status_sql = statuses.latest.where('stage=sg.stage').legacy_status_sql
warnings_sql = statuses.latest.select('COUNT(*)')
.where('stage=sg.stage').failed_but_allowed.to_sql
stages_with_statuses = CommitStatus.from(stages_query, :sg)
.pluck('sg.stage', status_sql, "(#{warnings_sql})")
stages_with_statuses.map do |stage|
Ci::LegacyStage.new(self, Hash[%i[name status warnings].zip(stage)])
end
def legacy_stages_using_composite_status
stages = Gitlab::Ci::Status::GroupedStatuses stages = Gitlab::Ci::Status::GroupedStatuses
.new(statuses.latest, :stage, :stage_idx) .new(statuses.latest, :stage, :stage_idx)
.group(:stage, :stage_idx) .group(:stage, :stage_idx)
...@@ -401,6 +416,13 @@ module Ci ...@@ -401,6 +416,13 @@ module Ci
status: stage[:status], status: stage[:status],
warnings: stage[:warnings]) warnings: stage[:warnings])
end end
def legacy_stages
if Feature.enabled?(:ci_composite_status, default_enabled: true)
legacy_stages_using_composite_status
else
legacy_status_using_sql
end
end end
def valid_commit_sha def valid_commit_sha
...@@ -633,7 +655,8 @@ module Ci ...@@ -633,7 +655,8 @@ module Ci
def update_status def update_status
retry_optimistic_lock(self) do retry_optimistic_lock(self) do
case latest_builds_status.to_s new_status = latest_builds_status.to_s
case new_status
when 'created' then nil when 'created' then nil
when 'preparing' then prepare when 'preparing' then prepare
when 'pending' then enqueue when 'pending' then enqueue
...@@ -646,7 +669,7 @@ module Ci ...@@ -646,7 +669,7 @@ module Ci
when 'scheduled' then delay when 'scheduled' then delay
else else
raise HasStatus::UnknownStatusError, raise HasStatus::UnknownStatusError,
"Unknown status `#{latest_builds_status}`" "Unknown status `#{new_status}`"
end end
end end
end end
......
...@@ -78,7 +78,8 @@ module Ci ...@@ -78,7 +78,8 @@ module Ci
def update_status def update_status
retry_optimistic_lock(self) do retry_optimistic_lock(self) do
case latest_stage_status new_status = latest_stage_status.to_s
case new_status
when 'created' then nil when 'created' then nil
when 'preparing' then prepare when 'preparing' then prepare
when 'pending' then enqueue when 'pending' then enqueue
...@@ -91,7 +92,7 @@ module Ci ...@@ -91,7 +92,7 @@ module Ci
when 'skipped', nil then skip when 'skipped', nil then skip
else else
raise HasStatus::UnknownStatusError, raise HasStatus::UnknownStatusError,
"Unknown status `#{statuses.latest.status}`" "Unknown status `#{new_status}`"
end end
end end
end end
......
...@@ -59,9 +59,13 @@ module HasStatus ...@@ -59,9 +59,13 @@ module HasStatus
end end
def slow_composite_status def slow_composite_status
if Feature.enabled?(:ci_composite_status, default_enabled: true)
Gitlab::Ci::Status::GroupedStatuses Gitlab::Ci::Status::GroupedStatuses
.new(all) .new(all)
.one[:status] .one[:status]
else
legacy_status
end
end end
def started_at def started_at
......
...@@ -15,7 +15,9 @@ module Gitlab ...@@ -15,7 +15,9 @@ module Gitlab
def status def status
case case
when none? || only_of?(:skipped) when none?
:skipped
when only_of?(:skipped)
warnings? ? :success : :skipped warnings? ? :success : :skipped
when only_of?(:success, :skipped) when only_of?(:success, :skipped)
:success :success
......
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