/bootstrap-your-zuul/BootstrapYourZuul/JsonConfig/toConfig.dhall

Copy path to clipboard

Source

--| An helper function to convert weakly type JsonConfig to Config
-- The Connection.Type variant are too similar and json-to-dhall picks the first one that match
-- To workaround this limitation, the JsonConfig schema defines the connection type as a key,
-- and this function converts the JsonConfig into a Config:
--
-- From:
-- ```yaml
-- connections:
-- gerrit: ["local", "opendev.org"]
-- ```
--
-- To:
-- ```dhall
-- { connections = [Connection.gerrit "local", Connection.gerrit "opendev.org"] }
-- ```
let Prelude = (../../imports.dhall).Prelude

./Type.dhallJsonConfig = { Type = ./Type.dhall }

../Config/package.dhalllet Config = ../Config/package.dhall

../Connection/package.dhallection = ../Connection/package.dhall

let cmap =
\(f : Text -> Connection.Type) ->
\(xs : Optional (List Text)) ->
merge
{ None = [] : List Connection.Type
, Some =
\(xs : List Text) -> Prelude.List.map Text Connection.Type f xs
}
xs

let toConfig
: JsonConfig.Type -> Config.Type
= \(jsonConfig : JsonConfig.Type) ->
Config::{
, name = jsonConfig.name
, label = jsonConfig.label
, zuul-jobs = jsonConfig.zuul_jobs
, connections =
cmap Connection.gerrit jsonConfig.connections.gerrit
# cmap Connection.pagure jsonConfig.connections.pagure
# cmap Connection.github jsonConfig.connections.github
}

in toConfig