From 77c9a2ab54b697f37e21b76c1fd82fc42dc4792e Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 3 Sep 2023 10:26:43 +0200 Subject: Add a test module --- app/SlackBuilder/Package.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'app/SlackBuilder/Package.hs') diff --git a/app/SlackBuilder/Package.hs b/app/SlackBuilder/Package.hs index cc07cc5..cc3ea42 100644 --- a/app/SlackBuilder/Package.hs +++ b/app/SlackBuilder/Package.hs @@ -1,13 +1,15 @@ module SlackBuilder.Package ( DownloadPlaceholder(..) , Download(..) + , DownloadTemplate(..) , PackageInfo(..) , Maintainer(..) , Updater(..) , infoTemplate + , renderDownloadWithVersion ) where -import Data.List.NonEmpty (NonEmpty) +import Data.List.NonEmpty (NonEmpty(..)) import Data.Text (Text) import qualified Data.Text as Text import Text.URI (URI(..)) @@ -17,6 +19,7 @@ import GHC.Records (HasField(..)) import System.FilePath (takeBaseName) import Data.List (partition) import SlackBuilder.Trans +import Control.Monad.Catch (MonadThrow) -- | Download URI with the MD5 checksum of the target. data Download = Download @@ -60,8 +63,15 @@ instance Show DownloadTemplate where show (DownloadTemplate components) = concatMap show components +renderDownloadWithVersion :: MonadThrow m => DownloadTemplate -> Text -> m URI +renderDownloadWithVersion (DownloadTemplate components) version = + URI.mkURI $ foldr f "" components + where + f (StaticPlaceholder staticPlaceholder) accumulator = accumulator <> staticPlaceholder + f VersionPlaceholder accumulator = accumulator <> version + -- | Function used to get the latest version of a source. -newtype Updater = Updater (SlackBuilderT (Maybe Text)) +data Updater = Updater (SlackBuilderT (Maybe Text)) DownloadTemplate packageName :: PackageInfo -> Text packageName PackageInfo{ path } = Text.pack $ takeBaseName path -- cgit v1.2.3