diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-06-04 12:29:39 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-06-04 12:29:39 +0300 |
commit | 114c26ccf0f10788271c6108774e72809a7f93e1 (patch) | |
tree | 1476e038b966c2b31d4d4a838fd245bc7ccab3dd /app/models | |
parent | 93241149e646f546e9a4406e85ced66c8d54099f (diff) |
Raise error if pipeline / stage hits unknown status
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/ci/pipeline.rb | 6 | ||||
-rw-r--r-- | app/models/ci/stage.rb | 4 | ||||
-rw-r--r-- | app/models/concerns/has_status.rb | 2 |
3 files changed, 11 insertions, 1 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 94a548181d9..1274d2a5f16 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -517,7 +517,8 @@ module Ci def update_status retry_optimistic_lock(self) do - case latest_builds_status + case latest_builds_status.to_s + when 'created' then nil when 'pending' then enqueue when 'running' then run when 'success' then succeed @@ -525,6 +526,9 @@ module Ci when 'canceled' then cancel when 'skipped' then skip when 'manual' then block + else + raise HasStatus::UnknownStatusError, + "Unknown status `#{latest_builds_status}`" end end end diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb index abf73c00539..ea07f37e6c1 100644 --- a/app/models/ci/stage.rb +++ b/app/models/ci/stage.rb @@ -68,6 +68,7 @@ module Ci def update_status retry_optimistic_lock(self) do case statuses.latest.status + when 'created' then nil when 'pending' then enqueue when 'running' then run when 'success' then succeed @@ -75,6 +76,9 @@ module Ci when 'canceled' then cancel when 'manual' then block when 'skipped', nil then skip + else + raise HasStatus::UnknownStatusError, + "Unknown status `#{statuses.latest.status}`" end end end diff --git a/app/models/concerns/has_status.rb b/app/models/concerns/has_status.rb index 7c3ed96bc28..72c236a0fc7 100644 --- a/app/models/concerns/has_status.rb +++ b/app/models/concerns/has_status.rb @@ -11,6 +11,8 @@ module HasStatus STATUSES_ENUM = { created: 0, pending: 1, running: 2, success: 3, failed: 4, canceled: 5, skipped: 6, manual: 7 }.freeze + UnknownStatusError = Class.new(StandardError) + class_methods do def status_sql scope_relevant = respond_to?(:exclude_ignored) ? exclude_ignored : all |