Wrap common downloader fields into a record
This commit is contained in:
parent
f395d57b33
commit
6290be859d
@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
-- | Configuration file.
|
-- | Configuration file.
|
||||||
module SlackBuilder.Config
|
module SlackBuilder.Config
|
||||||
( Settings(..)
|
( DownloaderSettings(..)
|
||||||
|
, Settings(..)
|
||||||
, MaintainerSettings(..)
|
, MaintainerSettings(..)
|
||||||
, PackageSettings(..)
|
, PackageSettings(..)
|
||||||
, settingsCodec
|
, settingsCodec
|
||||||
@ -14,6 +15,7 @@ import Data.List.NonEmpty (NonEmpty(..))
|
|||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import Toml ((.=))
|
import Toml ((.=))
|
||||||
import qualified Toml
|
import qualified Toml
|
||||||
|
import GHC.Records (HasField(..))
|
||||||
|
|
||||||
data Settings = Settings
|
data Settings = Settings
|
||||||
{ ghToken :: !Text
|
{ ghToken :: !Text
|
||||||
@ -29,7 +31,7 @@ newtype MaintainerSettings = MaintainerSettings
|
|||||||
{ signature :: Bool
|
{ signature :: Bool
|
||||||
} deriving (Eq, Show)
|
} deriving (Eq, Show)
|
||||||
|
|
||||||
data PackageSettings = PackageSettings
|
data DownloaderSettings = DownloaderSettings
|
||||||
{ name :: Text
|
{ name :: Text
|
||||||
, template :: Text
|
, template :: Text
|
||||||
, is64 :: Bool
|
, is64 :: Bool
|
||||||
@ -40,6 +42,10 @@ data PackageSettings = PackageSettings
|
|||||||
, repackage :: Maybe [String]
|
, repackage :: Maybe [String]
|
||||||
} deriving (Eq, Show)
|
} deriving (Eq, Show)
|
||||||
|
|
||||||
|
newtype PackageSettings = PackageSettings
|
||||||
|
{ downloader :: DownloaderSettings
|
||||||
|
} deriving (Eq, Show)
|
||||||
|
|
||||||
settingsCodec :: Toml.TomlCodec Settings
|
settingsCodec :: Toml.TomlCodec Settings
|
||||||
settingsCodec = Settings
|
settingsCodec = Settings
|
||||||
<$> Toml.text "gh_token" .= ghToken
|
<$> Toml.text "gh_token" .= ghToken
|
||||||
@ -54,8 +60,8 @@ maintainerSettingsCodec :: Toml.TomlCodec MaintainerSettings
|
|||||||
maintainerSettingsCodec = MaintainerSettings
|
maintainerSettingsCodec = MaintainerSettings
|
||||||
<$> Toml.bool "signature" .= signature
|
<$> Toml.bool "signature" .= signature
|
||||||
|
|
||||||
packageSettingsCodec :: Toml.TomlCodec PackageSettings
|
downloaderSettingsCodec :: Toml.TomlCodec DownloaderSettings
|
||||||
packageSettingsCodec = PackageSettings
|
downloaderSettingsCodec = DownloaderSettings
|
||||||
<$> Toml.text "name" .= name
|
<$> Toml.text "name" .= name
|
||||||
<*> Toml.text "template" .= template
|
<*> Toml.text "template" .= template
|
||||||
<*> Toml.bool "is64" .= is64
|
<*> Toml.bool "is64" .= is64
|
||||||
@ -68,3 +74,6 @@ packageSettingsCodec = PackageSettings
|
|||||||
githubCodec = Toml.pair (Toml.text "owner") (Toml.text "name")
|
githubCodec = Toml.pair (Toml.text "owner") (Toml.text "name")
|
||||||
packagistCodec = 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")
|
textCodec = Toml.pair (Toml.text "url") (Toml.arrayOf Toml._String "picker")
|
||||||
|
|
||||||
|
packageSettingsCodec :: Toml.TomlCodec PackageSettings
|
||||||
|
packageSettingsCodec = Toml.dimap (getField @"downloader") PackageSettings downloaderSettingsCodec
|
||||||
|
52
src/Main.hs
52
src/Main.hs
@ -33,12 +33,16 @@ import System.Console.ANSI
|
|||||||
)
|
)
|
||||||
import Data.Maybe (fromJust)
|
import Data.Maybe (fromJust)
|
||||||
|
|
||||||
|
findUpdatable :: Text -> [PackageSettings] -> DownloaderSettings
|
||||||
|
findUpdatable packageName = getField @"downloader" . fromJust
|
||||||
|
. find ((== packageName) . getField @"name" . getField @"downloader")
|
||||||
|
|
||||||
autoUpdatable :: [PackageSettings] -> [PackageDescription]
|
autoUpdatable :: [PackageSettings] -> [PackageDescription]
|
||||||
autoUpdatable packageSettings =
|
autoUpdatable packageSettings =
|
||||||
[ PackageDescription
|
[ PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
let setting = findUpdatable "universal-ctags" packageSettings
|
||||||
setting = fromJust $ find ((== "universal-ctags") . getField @"name") packageSettings
|
ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||||
template = Package.DownloadTemplate $ getField @"template" setting
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
||||||
@ -50,8 +54,8 @@ autoUpdatable packageSettings =
|
|||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let packagistArguments = uncurry PackageOwner $ fromJust $ getField @"packagist" setting
|
let setting = findUpdatable "composer" packageSettings
|
||||||
setting = fromJust $ find ((== "composer") . getField @"name") packageSettings
|
packagistArguments = uncurry PackageOwner $ fromJust $ getField @"packagist" setting
|
||||||
template = Package.DownloadTemplate $ getField @"template" setting
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestPackagist packagistArguments
|
{ detectLatest = latestPackagist packagistArguments
|
||||||
@ -63,8 +67,8 @@ autoUpdatable packageSettings =
|
|||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
let setting = findUpdatable "jitsi-meet-desktop" packageSettings
|
||||||
setting = fromJust $ find ((== "jitsi-meet-desktop") . getField @"name") packageSettings
|
ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||||
template = Package.DownloadTemplate $ getField @"template" setting
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
||||||
@ -76,8 +80,8 @@ autoUpdatable packageSettings =
|
|||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
let setting = findUpdatable "php82" packageSettings
|
||||||
setting = fromJust $ find ((== "php82") . getField @"name") packageSettings
|
ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||||
template = Package.DownloadTemplate $ getField @"template" setting
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
||||||
@ -89,8 +93,8 @@ autoUpdatable packageSettings =
|
|||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
let setting = findUpdatable "kitty" packageSettings
|
||||||
setting = fromJust $ find ((== "kitty") . getField @"name") packageSettings
|
ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||||
template = Package.DownloadTemplate $ getField @"template" setting
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
||||||
@ -102,8 +106,8 @@ autoUpdatable packageSettings =
|
|||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
let setting = findUpdatable "rdiff-backup" packageSettings
|
||||||
setting = fromJust $ find ((== "rdiff-backup") . getField @"name") packageSettings
|
ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||||
template = Package.DownloadTemplate $ getField @"template" setting
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
||||||
@ -115,8 +119,8 @@ autoUpdatable packageSettings =
|
|||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
|
let setting = findUpdatable "webex" packageSettings
|
||||||
setting = fromJust $ find ((== "webex") . getField @"name") packageSettings
|
textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
|
||||||
template = Package.DownloadTemplate $ getField @"template" setting
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestText textArguments (getField @"version" setting)
|
{ detectLatest = latestText textArguments (getField @"version" setting)
|
||||||
@ -128,8 +132,8 @@ autoUpdatable packageSettings =
|
|||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
let setting = findUpdatable "librsync" packageSettings
|
||||||
setting = fromJust $ find ((== "librsync") . getField @"name") packageSettings
|
ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||||
template = Package.DownloadTemplate $ getField @"template" setting
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
||||||
@ -141,8 +145,8 @@ autoUpdatable packageSettings =
|
|||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
|
let setting = findUpdatable "dmd" packageSettings
|
||||||
setting = fromJust $ find ((== "dmd") . getField @"name") packageSettings
|
textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
|
||||||
template = Package.DownloadTemplate $ getField @"template" setting
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestText textArguments (getField @"version" setting)
|
{ detectLatest = latestText textArguments (getField @"version" setting)
|
||||||
@ -154,8 +158,8 @@ autoUpdatable packageSettings =
|
|||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
|
let setting = findUpdatable "d-tools" packageSettings
|
||||||
setting = fromJust $ find ((== "d-tools") . getField @"name") packageSettings
|
textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
|
||||||
template = Package.DownloadTemplate $ getField @"template" setting
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestText textArguments (getField @"version" setting)
|
{ detectLatest = latestText textArguments (getField @"version" setting)
|
||||||
@ -193,8 +197,8 @@ autoUpdatable packageSettings =
|
|||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
let setting = findUpdatable "simde" packageSettings
|
||||||
setting = fromJust $ find ((== "simde") . getField @"name") packageSettings
|
ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||||
template = Package.DownloadTemplate $ getField @"template" setting
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
||||||
@ -206,8 +210,8 @@ autoUpdatable packageSettings =
|
|||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
let setting = findUpdatable "nginx" packageSettings
|
||||||
setting = fromJust $ find ((== "nginx") . getField @"name") packageSettings
|
ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||||
template = Package.DownloadTemplate $ getField @"template" setting
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
||||||
|
Loading…
Reference in New Issue
Block a user