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
config_sources.values_at(:repository_source, :auto_devops_source, :unknown_source)
end
def self.bridgeable_statuses
::Ci::Pipeline.all_statuses - [:created, :preparing, :pending]
end
def stages_count
statuses.select(:stage).distinct.count
end
......
......@@ -73,8 +73,8 @@ module HasStatus
COMPLETED_STATUSES.map(&:to_sym)
end
def blocked_statuses
BLOCKED_STATUS.map(&:to_sym)
def all_statuses
AVAILABLE_STATUSES.map(&:to_sym)
end
end
......
......@@ -4,6 +4,7 @@ module EE
module Ci
module Bridge
extend ActiveSupport::Concern
include ::Gitlab::Utils::StrongMemoize
InvalidBridgeTypeError = Class.new(StandardError)
......@@ -57,11 +58,15 @@ module EE
end
def downstream_project
options&.dig(:trigger, :project)
strong_memoize(:downstream_project) do
options&.dig(:trigger, :project)
end
end
def upstream_project
options&.dig(:needs, :pipeline)
strong_memoize(:upstream_project) do
options&.dig(:needs, :pipeline)
end
end
def target_ref
......
......@@ -97,7 +97,7 @@ module EE
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?
pipeline.run_after_commit do
......
......@@ -2,6 +2,8 @@
module Ci
class PipelineBridgeStatusService < ::BaseService
InvalidUpstreamStatusError = Class.new(StandardError)
def execute(pipeline)
pipeline.downstream_bridges.each do |bridge|
process_bridge(pipeline.status, bridge)
......@@ -18,10 +20,14 @@ module Ci
bridge.cancel!
when 'skipped'
bridge.skip!
when 'running'
bridge.run!
when 'manual'
bridge.update(status: 'manual')
when 'scheduled'
bridge.schedule!
bridge.update(status: 'scheduled')
else
raise InvalidUpstreamStatusError
end
end
end
......
......@@ -21,7 +21,7 @@ module Ci
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
end
......
......@@ -17,6 +17,14 @@ describe Ci::PipelineBridgeStatusService do
pipeline.downstream_bridges << bridge
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
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