summaryrefslogtreecommitdiff
path: root/app/SlackBuilder/Package.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2023-09-03 10:26:43 +0200
committerEugen Wissner <belka@caraus.de>2023-09-03 10:26:43 +0200
commit77c9a2ab54b697f37e21b76c1fd82fc42dc4792e (patch)
tree882f48c34d14a9ae58642ea41ba102136d7bf8c4 /app/SlackBuilder/Package.hs
parentc2b98ba395aa486c18fa002175d93aa789b231d6 (diff)
downloadslackbuilder-77c9a2ab54b697f37e21b76c1fd82fc42dc4792e.tar.gz
Add a test module
Diffstat (limited to 'app/SlackBuilder/Package.hs')
-rw-r--r--app/SlackBuilder/Package.hs14
1 files changed, 12 insertions, 2 deletions
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