summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/ci/pipeline.rb3
-rw-r--r--app/models/commit_status.rb6
-rw-r--r--spec/models/ci/pipeline_spec.rb45
3 files changed, 53 insertions, 1 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 718fe3290c1..8de799d6088 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -185,6 +185,7 @@ module Ci
def process!
Ci::ProcessPipelineService.new(project, user).execute(self)
+
reload_status!
end
@@ -195,7 +196,7 @@ module Ci
end
def reload_status!
- statuses.reload
+ reload
self.status =
if yaml_errors.blank?
statuses.latest.status || 'skipped'
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb
index 20713314a25..3ab44461179 100644
--- a/app/models/commit_status.rb
+++ b/app/models/commit_status.rb
@@ -76,6 +76,12 @@ class CommitStatus < ActiveRecord::Base
commit_status.pipeline.process! if commit_status.pipeline
end
+
+ around_transition any => [:pending, :running] do |commit_status, block|
+ block.call
+
+ commit_status.pipeline.reload_status! if commit_status.pipeline
+ end
end
delegate :sha, :short_sha, to: :pipeline
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index fdb579ab45c..9a9720cfbfc 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -254,4 +254,49 @@ describe Ci::Pipeline, models: true do
end
end
end
+
+ describe '#status' do
+ let!(:build) { create(:ci_build, :created, pipeline: pipeline, name: 'test') }
+
+ subject { pipeline.reload.status }
+
+ context 'on queuing' do
+ before { build.queue }
+
+ it { is_expected.to eq('pending') }
+ end
+
+ context 'on run' do
+ before do
+ build.queue
+ build.run
+ end
+
+ it { is_expected.to eq('running') }
+ end
+
+ context 'on drop' do
+ before do
+ build.drop
+ end
+
+ it { is_expected.to eq('failed') }
+ end
+
+ context 'on success' do
+ before do
+ build.success
+ end
+
+ it { is_expected.to eq('success') }
+ end
+
+ context 'on cancel' do
+ before do
+ build.cancel
+ end
+
+ it { is_expected.to eq('canceled') }
+ end
+ end
end