Commit 5ee1bd04 authored by Matija Čupić's avatar Matija Čupić

Handle running statuses when mirroring status

Handles 'running' status when mirror pipeline status to bridged job.
parent 2f418b77
...@@ -328,6 +328,10 @@ module Ci ...@@ -328,6 +328,10 @@ module Ci
config_sources.values_at(:repository_source, :auto_devops_source, :unknown_source) config_sources.values_at(:repository_source, :auto_devops_source, :unknown_source)
end end
def self.bridgeable_statuses
::Ci::Pipeline.all_statuses - [:created, :preparing, :pending]
end
def stages_count def stages_count
statuses.select(:stage).distinct.count statuses.select(:stage).distinct.count
end end
......
...@@ -73,8 +73,8 @@ module HasStatus ...@@ -73,8 +73,8 @@ module HasStatus
COMPLETED_STATUSES.map(&:to_sym) COMPLETED_STATUSES.map(&:to_sym)
end end
def blocked_statuses def all_statuses
BLOCKED_STATUS.map(&:to_sym) AVAILABLE_STATUSES.map(&:to_sym)
end end
end end
......
...@@ -4,6 +4,7 @@ module EE ...@@ -4,6 +4,7 @@ module EE
module Ci module Ci
module Bridge module Bridge
extend ActiveSupport::Concern extend ActiveSupport::Concern
include ::Gitlab::Utils::StrongMemoize
InvalidBridgeTypeError = Class.new(StandardError) InvalidBridgeTypeError = Class.new(StandardError)
...@@ -57,12 +58,16 @@ module EE ...@@ -57,12 +58,16 @@ module EE
end end
def downstream_project def downstream_project
strong_memoize(:downstream_project) do
options&.dig(:trigger, :project) options&.dig(:trigger, :project)
end end
end
def upstream_project def upstream_project
strong_memoize(:upstream_project) do
options&.dig(:needs, :pipeline) options&.dig(:needs, :pipeline)
end end
end
def target_ref def target_ref
options&.dig(:trigger, :branch) options&.dig(:trigger, :branch)
......
...@@ -97,7 +97,7 @@ module EE ...@@ -97,7 +97,7 @@ module EE
end end
end end
after_transition any => ::Ci::Pipeline.completed_statuses + ::Ci::Pipeline.blocked_statuses do |pipeline| after_transition any => ::Ci::Pipeline.bridgeable_statuses do |pipeline|
next unless pipeline.downstream_bridges.any? next unless pipeline.downstream_bridges.any?
pipeline.run_after_commit do pipeline.run_after_commit do
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
module Ci module Ci
class PipelineBridgeStatusService < ::BaseService class PipelineBridgeStatusService < ::BaseService
InvalidUpstreamStatusError = Class.new(StandardError)
def execute(pipeline) def execute(pipeline)
pipeline.downstream_bridges.each do |bridge| pipeline.downstream_bridges.each do |bridge|
process_bridge(pipeline.status, bridge) process_bridge(pipeline.status, bridge)
...@@ -18,10 +20,14 @@ module Ci ...@@ -18,10 +20,14 @@ module Ci
bridge.cancel! bridge.cancel!
when 'skipped' when 'skipped'
bridge.skip! bridge.skip!
when 'running'
bridge.run!
when 'manual' when 'manual'
bridge.update(status: 'manual') bridge.update(status: 'manual')
when 'scheduled' when 'scheduled'
bridge.schedule! bridge.update(status: 'scheduled')
else
raise InvalidUpstreamStatusError
end end
end end
end end
......
...@@ -21,7 +21,7 @@ module Ci ...@@ -21,7 +21,7 @@ module Ci
bridge_updates = { upstream_pipeline: upstream_pipeline } bridge_updates = { upstream_pipeline: upstream_pipeline }
if upstream_pipeline.complete? || upstream_pipeline.blocked? if ::Ci::Pipeline.bridgeable_statuses.include?(upstream_pipeline.status.to_sym)
bridge_updates[:status] = upstream_pipeline.status bridge_updates[:status] = upstream_pipeline.status
end end
......
...@@ -17,6 +17,14 @@ describe Ci::PipelineBridgeStatusService do ...@@ -17,6 +17,14 @@ describe Ci::PipelineBridgeStatusService do
pipeline.downstream_bridges << bridge pipeline.downstream_bridges << bridge
end end
context 'when pipeline starts running' do
let(:status) { :running }
it 'updates the bridge status with the pipeline status' do
expect { subject }.to change { bridge.status }.from('pending').to('running')
end
end
context 'when pipeline succeeds' do context 'when pipeline succeeds' do
let(:status) { :success } let(:status) { :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