diff options
| author | Eugen Wissner <belka@caraus.de> | 2023-08-04 21:33:21 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2023-08-04 21:33:21 +0200 |
| commit | 028f64d25a93e0430f22240024e255eec12bfb09 (patch) | |
| tree | 8782148d6eedf7558b3af2c75ba8410207340ea6 /app/Main.hs | |
| parent | 1bc410d86d0dcdb1fcb2eab74b0ace2b6781b0ff (diff) | |
| download | slackbuilder-028f64d25a93e0430f22240024e255eec12bfb09.tar.gz | |
Move packagist check to a Haskell binary
Diffstat (limited to 'app/Main.hs')
| -rw-r--r-- | app/Main.hs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/app/Main.hs b/app/Main.hs new file mode 100644 index 0000000..75a4396 --- /dev/null +++ b/app/Main.hs @@ -0,0 +1,46 @@ +module Main + ( main + ) where + +import Data.Aeson.TH (defaultOptions, deriveJSON) +import Data.HashMap.Strict (HashMap) +import qualified Data.HashMap.Strict as HashMap +import Data.Text (Text) +import qualified Data.Text.IO as Text.IO +import Data.Vector (Vector) +import qualified Data.Vector as Vector +import Network.HTTP.Req + ( runReq + , defaultHttpConfig + , req + , GET(..) + , https + , jsonResponse + , NoReqBody(..) + , (/:) + , responseBody + ) +import Data.Maybe (fromMaybe) + +newtype PackagistPackage = PackagistPackage + { version :: Text + } deriving (Eq, Show) + +$(deriveJSON defaultOptions ''PackagistPackage) + +newtype PackagistResponse = PackagistResponse + { packages :: HashMap Text (Vector PackagistPackage) + } deriving (Eq, Show) + +$(deriveJSON defaultOptions ''PackagistResponse) + +main :: IO () +main = do + packagistResponse <- runReq defaultHttpConfig $ + let uri = https "repo.packagist.org" /: "p2" /: "composer" /: "composer.json" + in req GET uri NoReqBody jsonResponse mempty + let packagistPackages = packages $ responseBody packagistResponse + + Text.IO.putStrLn $ fromMaybe "" + $ HashMap.lookup "composer/composer" packagistPackages + >>= fmap (version . fst) . Vector.uncons |
