Fix wrong behavior when CI keyword "when" is an array
What does this MR do and why?
Related to #347356 (closed)
We have the "inclusion" validation for the when
keyword but no validation for its type. So, the attribute also accepts an array as the value. The "inclusion" validation of ActiveModel::Validations
also accepts array values and compares each element.
class MyTestClass
include ActiveModel::Validations
attr_accessor :title
validates_inclusion_of :title, in: %w[abc def]
end
t = MyTestClass.new
t.title = 'abc'
t.valid? # => true
t.title = 'ghi'
t.valid? # => false
t.title = ['abc']
t.valid? # => true
In this MR, we are adding the type: String
validation for the when
keyword for Entry::Job
and Entry::Bridge
entries.
Notes:
- In the issue, we discussed if this change can be a breaking change for some users but this behavior is already broken so it should be okay to fix this without considering breaking changes.
- This MR does not aim to fix the duplication between
Entry::Job
andEntry::Bridge
. Maybe in another issue or maybe we should leave them as they are to keep them clear. - Maybe we should have a model validation for
Ci::Processable#when
but it requires additional work. - We have other
when
attributes for other CI entries (Entry::Change
andEntry::Artifacts
). Maybe we should also fix them in a follow-up. (#378368 (closed)) - We may need to check every
inclusion
validation in every CI entry. (#378368 (closed))
Screenshots or screen recordings
build:
when: [always]
script: exit 0
Before:
The job is skipped because in Ci::ProcessBuildService
, the job falls into the "else" case.
After:
Correct message
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Furkan Ayhan