Wrap common downloader fields into a record
This commit is contained in:
parent
f395d57b33
commit
6290be859d
@ -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
|
||||
|
52
src/Main.hs
52
src/Main.hs
@ -33,12 +33,16 @@ import System.Console.ANSI
|
||||
)
|
||||
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
|
||||
{ latest =
|
||||
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||
setting = fromJust $ find ((== "universal-ctags") . getField @"name") packageSettings
|
||||
let setting = findUpdatable "universal-ctags" packageSettings
|
||||
ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||
template = Package.DownloadTemplate $ getField @"template" setting
|
||||
in Package.Updater
|
||||
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
||||
@ -50,8 +54,8 @@ autoUpdatable packageSettings =
|
||||
}
|
||||
, PackageDescription
|
||||
{ latest =
|
||||
let packagistArguments = uncurry PackageOwner $ fromJust $ getField @"packagist" setting
|
||||
setting = fromJust $ find ((== "composer") . getField @"name") packageSettings
|
||||
let setting = findUpdatable "composer" packageSettings
|
||||
packagistArguments = uncurry PackageOwner $ fromJust $ getField @"packagist" setting
|
||||
template = Package.DownloadTemplate $ getField @"template" setting
|
||||
in Package.Updater
|
||||
{ detectLatest = latestPackagist packagistArguments
|
||||
@ -63,8 +67,8 @@ autoUpdatable packageSettings =
|
||||
}
|
||||
, PackageDescription
|
||||
{ latest =
|
||||
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||
setting = fromJust $ find ((== "jitsi-meet-desktop") . getField @"name") packageSettings
|
||||
let setting = findUpdatable "jitsi-meet-desktop" packageSettings
|
||||
ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||
template = Package.DownloadTemplate $ getField @"template" setting
|
||||
in Package.Updater
|
||||
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
||||
@ -76,8 +80,8 @@ autoUpdatable packageSettings =
|
||||
}
|
||||
, PackageDescription
|
||||
{ latest =
|
||||
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||
setting = fromJust $ find ((== "php82") . getField @"name") packageSettings
|
||||
let setting = findUpdatable "php82" packageSettings
|
||||
ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||
template = Package.DownloadTemplate $ getField @"template" setting
|
||||
in Package.Updater
|
||||
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
||||
@ -89,8 +93,8 @@ autoUpdatable packageSettings =
|
||||
}
|
||||
, PackageDescription
|
||||
{ latest =
|
||||
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||
setting = fromJust $ find ((== "kitty") . getField @"name") packageSettings
|
||||
let setting = findUpdatable "kitty" packageSettings
|
||||
ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||
template = Package.DownloadTemplate $ getField @"template" setting
|
||||
in Package.Updater
|
||||
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
||||
@ -102,8 +106,8 @@ autoUpdatable packageSettings =
|
||||
}
|
||||
, PackageDescription
|
||||
{ latest =
|
||||
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||
setting = fromJust $ find ((== "rdiff-backup") . getField @"name") packageSettings
|
||||
let setting = findUpdatable "rdiff-backup" packageSettings
|
||||
ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||
template = Package.DownloadTemplate $ getField @"template" setting
|
||||
in Package.Updater
|
||||
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
||||
@ -115,8 +119,8 @@ autoUpdatable packageSettings =
|
||||
}
|
||||
, PackageDescription
|
||||
{ latest =
|
||||
let textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
|
||||
setting = fromJust $ find ((== "webex") . getField @"name") packageSettings
|
||||
let setting = findUpdatable "webex" packageSettings
|
||||
textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
|
||||
template = Package.DownloadTemplate $ getField @"template" setting
|
||||
in Package.Updater
|
||||
{ detectLatest = latestText textArguments (getField @"version" setting)
|
||||
@ -128,8 +132,8 @@ autoUpdatable packageSettings =
|
||||
}
|
||||
, PackageDescription
|
||||
{ latest =
|
||||
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||
setting = fromJust $ find ((== "librsync") . getField @"name") packageSettings
|
||||
let setting = findUpdatable "librsync" packageSettings
|
||||
ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||
template = Package.DownloadTemplate $ getField @"template" setting
|
||||
in Package.Updater
|
||||
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
||||
@ -141,8 +145,8 @@ autoUpdatable packageSettings =
|
||||
}
|
||||
, PackageDescription
|
||||
{ latest =
|
||||
let textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
|
||||
setting = fromJust $ find ((== "dmd") . getField @"name") packageSettings
|
||||
let setting = findUpdatable "dmd" packageSettings
|
||||
textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
|
||||
template = Package.DownloadTemplate $ getField @"template" setting
|
||||
in Package.Updater
|
||||
{ detectLatest = latestText textArguments (getField @"version" setting)
|
||||
@ -154,8 +158,8 @@ autoUpdatable packageSettings =
|
||||
}
|
||||
, PackageDescription
|
||||
{ latest =
|
||||
let textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
|
||||
setting = fromJust $ find ((== "d-tools") . getField @"name") packageSettings
|
||||
let setting = findUpdatable "d-tools" packageSettings
|
||||
textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
|
||||
template = Package.DownloadTemplate $ getField @"template" setting
|
||||
in Package.Updater
|
||||
{ detectLatest = latestText textArguments (getField @"version" setting)
|
||||
@ -193,8 +197,8 @@ autoUpdatable packageSettings =
|
||||
}
|
||||
, PackageDescription
|
||||
{ latest =
|
||||
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||
setting = fromJust $ find ((== "simde") . getField @"name") packageSettings
|
||||
let setting = findUpdatable "simde" packageSettings
|
||||
ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||
template = Package.DownloadTemplate $ getField @"template" setting
|
||||
in Package.Updater
|
||||
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
||||
@ -206,8 +210,8 @@ autoUpdatable packageSettings =
|
||||
}
|
||||
, PackageDescription
|
||||
{ latest =
|
||||
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||
setting = fromJust $ find ((== "nginx") . getField @"name") packageSettings
|
||||
let setting = findUpdatable "nginx" packageSettings
|
||||
ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||
template = Package.DownloadTemplate $ getField @"template" setting
|
||||
in Package.Updater
|
||||
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
||||
|
Loading…
Reference in New Issue
Block a user