mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-11 05:36:07 +10:00
Merge branch 'ci-commit-as-pipeline' into with-pipeline-view
# Conflicts: # app/models/ci/commit.rb
This commit is contained in:
+11
-61
@@ -29,16 +29,8 @@ module Ci
|
||||
validates_presence_of :sha
|
||||
validate :valid_commit_sha
|
||||
|
||||
# Make sure that status is saved
|
||||
before_save :status
|
||||
before_save :started_at
|
||||
before_save :finished_at
|
||||
before_save :duration
|
||||
|
||||
# Invalidate object and save if when touched
|
||||
after_touch :reload
|
||||
after_touch :invalidate
|
||||
after_touch :save
|
||||
after_touch :update_state
|
||||
|
||||
def self.truncate_sha(sha)
|
||||
sha[0...8]
|
||||
@@ -105,13 +97,6 @@ module Ci
|
||||
trigger_requests.any?
|
||||
end
|
||||
|
||||
def invalidate
|
||||
write_attribute(:status, nil)
|
||||
write_attribute(:started_at, nil)
|
||||
write_attribute(:finished_at, nil)
|
||||
write_attribute(:duration, nil)
|
||||
end
|
||||
|
||||
def create_builds(user, trigger_request = nil)
|
||||
return unless config_processor
|
||||
config_processor.stages.any? do |stage|
|
||||
@@ -148,22 +133,6 @@ module Ci
|
||||
@retried ||= (statuses.order(id: :desc) - statuses.latest)
|
||||
end
|
||||
|
||||
def status
|
||||
read_attribute(:status) || update_status
|
||||
end
|
||||
|
||||
def duration
|
||||
read_attribute(:duration) || update_duration
|
||||
end
|
||||
|
||||
def started_at
|
||||
read_attribute(:started_at) || update_started_at
|
||||
end
|
||||
|
||||
def finished_at
|
||||
read_attribute(:finished_at) || update_finished_at
|
||||
end
|
||||
|
||||
def coverage
|
||||
coverage_array = latest.map(&:coverage).compact
|
||||
if coverage_array.size >= 1
|
||||
@@ -199,45 +168,26 @@ module Ci
|
||||
|
||||
private
|
||||
|
||||
def update_status
|
||||
self.status =
|
||||
if yaml_errors.present?
|
||||
'failed'
|
||||
else
|
||||
latest.status || 'skipped'
|
||||
end
|
||||
end
|
||||
|
||||
def update_started_at
|
||||
self.started_at =
|
||||
statuses.minimum(:started_at)
|
||||
end
|
||||
|
||||
def update_finished_at
|
||||
self.finished_at =
|
||||
statuses.maximum(:finished_at)
|
||||
end
|
||||
|
||||
def update_duration
|
||||
def update_state
|
||||
reload
|
||||
self.status = if yaml_errors.present?
|
||||
'failed'
|
||||
else
|
||||
latest.status
|
||||
end
|
||||
self.started_at = statuses.minimum(:started_at)
|
||||
self.finished_at = statuses.maximum(:finished_at)
|
||||
self.duration = begin
|
||||
duration_array = latest.map(&:duration).compact
|
||||
duration_array.reduce(:+).to_i
|
||||
end
|
||||
end
|
||||
|
||||
def update_statuses
|
||||
update_status
|
||||
update_started_at
|
||||
update_finished_at
|
||||
update_duration
|
||||
save
|
||||
end
|
||||
|
||||
def save_yaml_error(error)
|
||||
return if self.yaml_errors?
|
||||
self.yaml_errors = error
|
||||
update_status
|
||||
save
|
||||
update_state
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,12 +12,14 @@ module CiStatus
|
||||
pending = all.pending.select('count(*)').to_sql
|
||||
running = all.running.select('count(*)').to_sql
|
||||
canceled = all.canceled.select('count(*)').to_sql
|
||||
skipped = all.skipped.select('count(*)').to_sql
|
||||
|
||||
deduce_status = "(CASE
|
||||
WHEN (#{builds})=0 THEN 'skipped'
|
||||
WHEN (#{builds})=(#{success})+(#{ignored}) THEN 'success'
|
||||
WHEN (#{builds})=(#{pending}) THEN 'pending'
|
||||
WHEN (#{builds})=(#{canceled}) THEN 'canceled'
|
||||
WHEN (#{builds})=(#{skipped}) THEN 'skipped'
|
||||
WHEN (#{running})+(#{pending})>0 THEN 'running'
|
||||
ELSE 'failed'
|
||||
END)"
|
||||
@@ -52,6 +54,7 @@ module CiStatus
|
||||
scope :success, -> { where(status: 'success') }
|
||||
scope :failed, -> { where(status: 'failed') }
|
||||
scope :canceled, -> { where(status: 'canceled') }
|
||||
scope :skipped, -> { where(status: 'skipped') }
|
||||
scope :running_or_pending, -> { where(status: [:running, :pending]) }
|
||||
scope :finished, -> { where(status: [:success, :failed, :canceled]) }
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ class Spinach::Features::Dashboard < Spinach::FeatureSteps
|
||||
end
|
||||
|
||||
step 'I should see "Shop" project CI status' do
|
||||
expect(page).to have_link "Build skipped"
|
||||
expect(page).to have_link "Build: skipped"
|
||||
end
|
||||
|
||||
step 'I should see last push widget' do
|
||||
|
||||
Reference in New Issue
Block a user