Refactor CI interpolation input classes
What does this MR do and why?
- Related to issue Backend: Input type validation - type (1/2) (#390458 - closed)
- Related to MR Add type validation to inputs (!122667 - closed)
This MR refactors how we build input objects from both spec:inputs
specifications and user-provided values.
Before this refactoring we had different types of inputs based on various characteristics of input specification:
-
Default
ifdefault
was defined -
Required
ifdefault
was not defined -
Options
ifoptions
was defined -
Unknown
for catch all scenarios
The main problem with this object classification is the fact that options
can be specified together with default
and the 2 characteristics are not mutually exclusive. Currently options
does not work and it's not even enabled as syntax but the design would need to be changed anyway when we enable options
attribute of the input spec.
Also the Unknown
type was there just as a catch all type but it wasn't necessary.
After this refactoring we consolidate the characteristics (required, with default, options) under a single Interpolation::Inputs::BaseInput
class so that all types of inputs always behave the same under this aspect. The new class also has a smaller interface (less public methods).
We also introduce a type StringInput
class which is the default type today. Adding new types is now very easy and it requires to add a new class with only 2 class methods:
class Gitlab::Ci::Interpolation::Inputs::BooleanInput < Inputs::BaseInput
def self.matches?(spec)
spec[:type] == 'boolean'
end
def self.valid_value?(value)
[true, false].include?(value)
end
end
All validations are equivalent to StringInput
(and other future types):
- check that the selected input type is supported
- check that the value is provided, if there is no default specified
- check that the provided value matches the given type
- check that any default value matches the given type
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
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.