Wrap common downloader fields into a record
All checks were successful
Build / audit (push) Successful in 7s
Build / test (push) Successful in 15m2s

This commit is contained in:
2024-10-01 19:54:32 +02:00
parent f395d57b33
commit 6290be859d
2 changed files with 41 additions and 28 deletions

View File

@ -4,7 +4,8 @@
-- | Configuration file.
module SlackBuilder.Config
( Settings(..)
( DownloaderSettings(..)
, Settings(..)
, MaintainerSettings(..)
, PackageSettings(..)
, settingsCodec
@ -14,6 +15,7 @@ import Data.List.NonEmpty (NonEmpty(..))
import Data.Text (Text)
import Toml ((.=))
import qualified Toml
import GHC.Records (HasField(..))
data Settings = Settings
{ ghToken :: !Text
@ -29,7 +31,7 @@ newtype MaintainerSettings = MaintainerSettings
{ signature :: Bool
} deriving (Eq, Show)
data PackageSettings = PackageSettings
data DownloaderSettings = DownloaderSettings
{ name :: Text
, template :: Text
, is64 :: Bool
@ -40,6 +42,10 @@ data PackageSettings = PackageSettings
, repackage :: Maybe [String]
} deriving (Eq, Show)
newtype PackageSettings = PackageSettings
{ downloader :: DownloaderSettings
} deriving (Eq, Show)
settingsCodec :: Toml.TomlCodec Settings
settingsCodec = Settings
<$> Toml.text "gh_token" .= ghToken
@ -54,8 +60,8 @@ maintainerSettingsCodec :: Toml.TomlCodec MaintainerSettings
maintainerSettingsCodec = MaintainerSettings
<$> Toml.bool "signature" .= signature
packageSettingsCodec :: Toml.TomlCodec PackageSettings
packageSettingsCodec = PackageSettings
downloaderSettingsCodec :: Toml.TomlCodec DownloaderSettings
downloaderSettingsCodec = DownloaderSettings
<$> Toml.text "name" .= name
<*> Toml.text "template" .= template
<*> Toml.bool "is64" .= is64
@ -68,3 +74,6 @@ packageSettingsCodec = PackageSettings
githubCodec = Toml.pair (Toml.text "owner") (Toml.text "name")
packagistCodec = Toml.pair (Toml.text "owner") (Toml.text "name")
textCodec = Toml.pair (Toml.text "url") (Toml.arrayOf Toml._String "picker")
packageSettingsCodec :: Toml.TomlCodec PackageSettings
packageSettingsCodec = Toml.dimap (getField @"downloader") PackageSettings downloaderSettingsCodec